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 /* size must be multiple of bw by bh or equal to whole texture size */
1598 if ((subWidth
% bw
!= 0) && subWidth
!= (GLint
) destImage
->Width
) {
1599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1600 "%s%dD(width = %d)", function
, dims
, subWidth
);
1604 if ((subHeight
% bh
!= 0) && subHeight
!= (GLint
) destImage
->Height
) {
1605 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1606 "%s%dD(height = %d)", function
, dims
, subHeight
);
1618 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1619 * specific texture image size checks.
1621 * A hardware driver might override this function if, for example, the
1622 * max 3D texture size is 512x512x64 (i.e. not a cube).
1624 * Note that width, height, depth == 0 is not an error. However, a
1625 * texture with zero width/height/depth will be considered "incomplete"
1626 * and texturing will effectively be disabled.
1628 * \param target any texture target/type
1629 * \param level as passed to glTexImage
1630 * \param format the MESA_FORMAT_x for the tex image
1631 * \param width as passed to glTexImage
1632 * \param height as passed to glTexImage
1633 * \param depth as passed to glTexImage
1634 * \param border as passed to glTexImage
1635 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1638 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1640 GLint width
, GLint height
, GLint depth
, GLint border
)
1642 /* We just check if the image size is less than MaxTextureMbytes.
1643 * Some drivers may do more specific checks.
1645 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1646 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1647 mbytes
*= _mesa_num_tex_faces(target
);
1648 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1653 * Return true if the format is only valid for glCompressedTexImage.
1656 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1659 case GL_ETC1_RGB8_OES
:
1660 case GL_PALETTE4_RGB8_OES
:
1661 case GL_PALETTE4_RGBA8_OES
:
1662 case GL_PALETTE4_R5_G6_B5_OES
:
1663 case GL_PALETTE4_RGBA4_OES
:
1664 case GL_PALETTE4_RGB5_A1_OES
:
1665 case GL_PALETTE8_RGB8_OES
:
1666 case GL_PALETTE8_RGBA8_OES
:
1667 case GL_PALETTE8_R5_G6_B5_OES
:
1668 case GL_PALETTE8_RGBA4_OES
:
1669 case GL_PALETTE8_RGB5_A1_OES
:
1678 * Helper function to determine whether a target and specific compression
1679 * format are supported.
1682 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1685 (void) intFormat
; /* not used yet */
1689 case GL_PROXY_TEXTURE_2D
:
1690 return GL_TRUE
; /* true for any compressed format so far */
1691 case GL_PROXY_TEXTURE_CUBE_MAP
:
1692 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1694 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1696 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1698 return ctx
->Extensions
.ARB_texture_cube_map
;
1699 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1700 case GL_TEXTURE_2D_ARRAY_EXT
:
1701 return (ctx
->Extensions
.MESA_texture_array
||
1702 ctx
->Extensions
.EXT_texture_array
);
1703 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1704 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1705 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1713 * Check if the given texture target value is legal for a
1714 * glTexImage1/2/3D call.
1717 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1723 case GL_PROXY_TEXTURE_1D
:
1724 return _mesa_is_desktop_gl(ctx
);
1732 case GL_PROXY_TEXTURE_2D
:
1733 return _mesa_is_desktop_gl(ctx
);
1734 case GL_PROXY_TEXTURE_CUBE_MAP
:
1735 return _mesa_is_desktop_gl(ctx
)
1736 && ctx
->Extensions
.ARB_texture_cube_map
;
1737 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1739 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1740 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1741 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1742 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1743 return ctx
->Extensions
.ARB_texture_cube_map
;
1744 case GL_TEXTURE_RECTANGLE_NV
:
1745 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1746 return _mesa_is_desktop_gl(ctx
)
1747 && ctx
->Extensions
.NV_texture_rectangle
;
1748 case GL_TEXTURE_1D_ARRAY_EXT
:
1749 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1750 return _mesa_is_desktop_gl(ctx
)
1751 && (ctx
->Extensions
.MESA_texture_array
||
1752 ctx
->Extensions
.EXT_texture_array
);
1760 case GL_PROXY_TEXTURE_3D
:
1761 return _mesa_is_desktop_gl(ctx
);
1762 case GL_TEXTURE_2D_ARRAY_EXT
:
1763 return (_mesa_is_desktop_gl(ctx
)
1764 && (ctx
->Extensions
.MESA_texture_array
||
1765 ctx
->Extensions
.EXT_texture_array
))
1766 || _mesa_is_gles3(ctx
);
1767 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1768 return _mesa_is_desktop_gl(ctx
)
1769 && (ctx
->Extensions
.MESA_texture_array
||
1770 ctx
->Extensions
.EXT_texture_array
);
1771 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1772 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1773 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1778 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1785 * Check if the given texture target value is legal for a
1786 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1787 * The difference compared to legal_teximage_target() above is that
1788 * proxy targets are not supported.
1791 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1795 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1800 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1801 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1802 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1803 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1804 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1805 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1806 return ctx
->Extensions
.ARB_texture_cube_map
;
1807 case GL_TEXTURE_RECTANGLE_NV
:
1808 return _mesa_is_desktop_gl(ctx
)
1809 && ctx
->Extensions
.NV_texture_rectangle
;
1810 case GL_TEXTURE_1D_ARRAY_EXT
:
1811 return _mesa_is_desktop_gl(ctx
)
1812 && (ctx
->Extensions
.MESA_texture_array
||
1813 ctx
->Extensions
.EXT_texture_array
);
1821 case GL_TEXTURE_2D_ARRAY_EXT
:
1822 return (_mesa_is_desktop_gl(ctx
)
1823 && (ctx
->Extensions
.MESA_texture_array
||
1824 ctx
->Extensions
.EXT_texture_array
))
1825 || _mesa_is_gles3(ctx
);
1826 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1827 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1828 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1833 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1841 * Helper function to determine if a texture object is mutable (in terms
1842 * of GL_ARB_texture_storage).
1845 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1847 if (ctx
->Extensions
.ARB_texture_storage
) {
1848 struct gl_texture_object
*texObj
=
1849 _mesa_get_current_tex_object(ctx
, target
);
1850 return !texObj
->Immutable
;
1857 * Return expected size of a compressed texture.
1860 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1863 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1864 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1869 * Test the glTexImage[123]D() parameters for errors.
1871 * \param ctx GL context.
1872 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1873 * \param target texture target given by the user (already validated).
1874 * \param level image level given by the user.
1875 * \param internalFormat internal format given by the user.
1876 * \param format pixel data format given by the user.
1877 * \param type pixel data type given by the user.
1878 * \param width image width given by the user.
1879 * \param height image height given by the user.
1880 * \param depth image depth given by the user.
1881 * \param border image border given by the user.
1883 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1885 * Verifies each of the parameters against the constants specified in
1886 * __struct gl_contextRec::Const and the supported extensions, and according
1887 * to the OpenGL specification.
1888 * Note that we don't fully error-check the width, height, depth values
1889 * here. That's done in _mesa_legal_texture_dimensions() which is used
1890 * by several other GL entrypoints. Plus, texture dims have a special
1891 * interaction with proxy textures.
1894 texture_error_check( struct gl_context
*ctx
,
1895 GLuint dimensions
, GLenum target
,
1896 GLint level
, GLint internalFormat
,
1897 GLenum format
, GLenum type
,
1898 GLint width
, GLint height
,
1899 GLint depth
, GLint border
)
1901 GLboolean colorFormat
;
1904 /* Even though there are no color-index textures, we still have to support
1905 * uploading color-index data and remapping it to RGB via the
1906 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1908 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1910 /* Note: for proxy textures, some error conditions immediately generate
1911 * a GL error in the usual way. But others do not generate a GL error.
1912 * Instead, they cause the width, height, depth, format fields of the
1913 * texture image to be zeroed-out. The GL spec seems to indicate that the
1914 * zero-out behaviour is only used in cases related to memory allocation.
1918 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1919 _mesa_error(ctx
, GL_INVALID_VALUE
,
1920 "glTexImage%dD(level=%d)", dimensions
, level
);
1925 if (border
< 0 || border
> 1 ||
1926 ((ctx
->API
!= API_OPENGL_COMPAT
||
1927 target
== GL_TEXTURE_RECTANGLE_NV
||
1928 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1929 _mesa_error(ctx
, GL_INVALID_VALUE
,
1930 "glTexImage%dD(border=%d)", dimensions
, border
);
1934 if (width
< 0 || height
< 0 || depth
< 0) {
1935 _mesa_error(ctx
, GL_INVALID_VALUE
,
1936 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1940 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1941 * combinations of format, internalFormat, and type that can be used.
1942 * Formats and types that require additional extensions (e.g., GL_FLOAT
1943 * requires GL_OES_texture_float) are filtered elsewhere.
1946 if (_mesa_is_gles(ctx
)) {
1947 if (_mesa_is_gles3(ctx
)) {
1948 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1951 if (format
!= internalFormat
) {
1952 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1953 "glTexImage%dD(format = %s, internalFormat = %s)",
1955 _mesa_lookup_enum_by_nr(format
),
1956 _mesa_lookup_enum_by_nr(internalFormat
));
1960 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1962 if (err
!= GL_NO_ERROR
) {
1963 _mesa_error(ctx
, err
,
1964 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1966 _mesa_lookup_enum_by_nr(format
),
1967 _mesa_lookup_enum_by_nr(type
),
1968 _mesa_lookup_enum_by_nr(internalFormat
));
1973 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1974 _mesa_is_cube_face(target
)) && width
!= height
) {
1975 _mesa_error(ctx
, GL_INVALID_VALUE
,
1976 "glTexImage2D(cube width != height)");
1980 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1981 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1982 _mesa_error(ctx
, GL_INVALID_VALUE
,
1983 "glTexImage3D(cube array width != height)");
1987 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1988 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "glTexImage3D(cube array depth not multiple of 6)");
1994 /* Check internalFormat */
1995 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glTexImage%dD(internalFormat=%s)",
1998 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2002 /* Check incoming image format and type */
2003 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2004 if (err
!= GL_NO_ERROR
) {
2005 _mesa_error(ctx
, err
,
2006 "glTexImage%dD(incompatible format = %s, type = %s)",
2007 dimensions
, _mesa_lookup_enum_by_nr(format
),
2008 _mesa_lookup_enum_by_nr(type
));
2012 /* make sure internal format and format basically agree */
2013 colorFormat
= _mesa_is_color_format(format
);
2014 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2015 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2016 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2017 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2018 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2019 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2020 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2021 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2022 _mesa_lookup_enum_by_nr(format
));
2026 /* additional checks for ycbcr textures */
2027 if (internalFormat
== GL_YCBCR_MESA
) {
2028 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2029 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2030 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2032 _mesa_snprintf(message
, sizeof(message
),
2033 "glTexImage%dD(format/type YCBCR mismatch)",
2035 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2036 return GL_TRUE
; /* error */
2038 if (target
!= GL_TEXTURE_2D
&&
2039 target
!= GL_PROXY_TEXTURE_2D
&&
2040 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2041 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2042 _mesa_error(ctx
, GL_INVALID_ENUM
,
2043 "glTexImage%dD(bad target for YCbCr texture)",
2049 _mesa_snprintf(message
, sizeof(message
),
2050 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2051 dimensions
, border
);
2052 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2057 /* additional checks for depth textures */
2058 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2059 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2060 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2061 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2062 if (target
!= GL_TEXTURE_1D
&&
2063 target
!= GL_PROXY_TEXTURE_1D
&&
2064 target
!= GL_TEXTURE_2D
&&
2065 target
!= GL_PROXY_TEXTURE_2D
&&
2066 target
!= GL_TEXTURE_1D_ARRAY
&&
2067 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2068 target
!= GL_TEXTURE_2D_ARRAY
&&
2069 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2070 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2071 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2072 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2073 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2074 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2075 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2076 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2077 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2078 _mesa_error(ctx
, GL_INVALID_ENUM
,
2079 "glTexImage%dD(bad target for depth texture)",
2085 /* additional checks for compressed textures */
2086 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2087 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2088 _mesa_error(ctx
, GL_INVALID_ENUM
,
2089 "glTexImage%dD(target can't be compressed)", dimensions
);
2092 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2093 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2094 "glTexImage%dD(no compression for format)", dimensions
);
2098 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2099 "glTexImage%dD(border!=0)", dimensions
);
2104 /* additional checks for integer textures */
2105 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2106 (_mesa_is_enum_format_integer(format
) !=
2107 _mesa_is_enum_format_integer(internalFormat
))) {
2108 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2109 "glTexImage%dD(integer/non-integer format mismatch)",
2114 if (!mutable_tex_object(ctx
, target
)) {
2115 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2116 "glTexImage%dD(immutable texture)", dimensions
);
2120 /* if we get here, the parameters are OK */
2126 * Error checking for glCompressedTexImage[123]D().
2127 * Note that the width, height and depth values are not fully error checked
2129 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2132 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2133 GLenum target
, GLint level
,
2134 GLenum internalFormat
, GLsizei width
,
2135 GLsizei height
, GLsizei depth
, GLint border
,
2138 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2140 GLenum error
= GL_NO_ERROR
;
2141 char *reason
= ""; /* no error */
2143 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2145 error
= GL_INVALID_ENUM
;
2149 /* This will detect any invalid internalFormat value */
2150 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2151 reason
= "internalFormat";
2152 error
= GL_INVALID_ENUM
;
2156 switch (internalFormat
) {
2157 case GL_PALETTE4_RGB8_OES
:
2158 case GL_PALETTE4_RGBA8_OES
:
2159 case GL_PALETTE4_R5_G6_B5_OES
:
2160 case GL_PALETTE4_RGBA4_OES
:
2161 case GL_PALETTE4_RGB5_A1_OES
:
2162 case GL_PALETTE8_RGB8_OES
:
2163 case GL_PALETTE8_RGBA8_OES
:
2164 case GL_PALETTE8_R5_G6_B5_OES
:
2165 case GL_PALETTE8_RGBA4_OES
:
2166 case GL_PALETTE8_RGB5_A1_OES
:
2167 /* check level (note that level should be zero or less!) */
2168 if (level
> 0 || level
< -maxLevels
) {
2170 error
= GL_INVALID_VALUE
;
2174 if (dimensions
!= 2) {
2175 reason
= "compressed paletted textures must be 2D";
2176 error
= GL_INVALID_OPERATION
;
2180 /* Figure out the expected texture size (in bytes). This will be
2181 * checked against the actual size later.
2183 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2186 /* This is for the benefit of the TestProxyTexImage below. It expects
2187 * level to be non-negative. OES_compressed_paletted_texture uses a
2188 * weird mechanism where the level specified to glCompressedTexImage2D
2189 * is -(n-1) number of levels in the texture, and the data specifies the
2190 * complete mipmap stack. This is done to ensure the palette is the
2191 * same for all levels.
2198 if (level
< 0 || level
>= maxLevels
) {
2200 error
= GL_INVALID_VALUE
;
2204 /* Figure out the expected texture size (in bytes). This will be
2205 * checked against the actual size later.
2207 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2211 /* This should really never fail */
2212 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2213 reason
= "internalFormat";
2214 error
= GL_INVALID_ENUM
;
2218 /* No compressed formats support borders at this time */
2220 reason
= "border != 0";
2221 error
= GL_INVALID_VALUE
;
2225 /* For cube map, width must equal height */
2226 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2227 _mesa_is_cube_face(target
)) && width
!= height
) {
2228 reason
= "width != height";
2229 error
= GL_INVALID_VALUE
;
2233 /* check image size in bytes */
2234 if (expectedSize
!= imageSize
) {
2235 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2236 * if <imageSize> is not consistent with the format, dimensions, and
2237 * contents of the specified image.
2239 reason
= "imageSize inconsistant with width/height/format";
2240 error
= GL_INVALID_VALUE
;
2244 if (!mutable_tex_object(ctx
, target
)) {
2245 reason
= "immutable texture";
2246 error
= GL_INVALID_OPERATION
;
2253 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2260 * Test glTexSubImage[123]D() parameters for errors.
2262 * \param ctx GL context.
2263 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2264 * \param target texture target given by the user (already validated)
2265 * \param level image level given by the user.
2266 * \param xoffset sub-image x offset given by the user.
2267 * \param yoffset sub-image y offset given by the user.
2268 * \param zoffset sub-image z offset given by the user.
2269 * \param format pixel data format given by the user.
2270 * \param type pixel data type given by the user.
2271 * \param width image width given by the user.
2272 * \param height image height given by the user.
2273 * \param depth image depth given by the user.
2275 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2277 * Verifies each of the parameters against the constants specified in
2278 * __struct gl_contextRec::Const and the supported extensions, and according
2279 * to the OpenGL specification.
2282 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2283 GLenum target
, GLint level
,
2284 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2285 GLint width
, GLint height
, GLint depth
,
2286 GLenum format
, GLenum type
)
2288 struct gl_texture_object
*texObj
;
2289 struct gl_texture_image
*texImage
;
2292 /* check target (proxies not allowed) */
2293 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2294 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2295 dimensions
, _mesa_lookup_enum_by_nr(target
));
2300 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2301 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2306 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2307 * combinations of format and type that can be used. Formats and types
2308 * that require additional extensions (e.g., GL_FLOAT requires
2309 * GL_OES_texture_float) are filtered elsewhere.
2311 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2312 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2313 if (err
!= GL_NO_ERROR
) {
2314 _mesa_error(ctx
, err
,
2315 "glTexSubImage%dD(format = %s, type = %s)",
2317 _mesa_lookup_enum_by_nr(format
),
2318 _mesa_lookup_enum_by_nr(type
));
2323 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2324 if (err
!= GL_NO_ERROR
) {
2325 _mesa_error(ctx
, err
,
2326 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2327 dimensions
, _mesa_lookup_enum_by_nr(format
),
2328 _mesa_lookup_enum_by_nr(type
));
2332 /* Get dest texture object / image pointers */
2333 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2335 /* must be out of memory */
2336 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2340 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2342 /* non-existant texture level */
2343 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2344 "glTexSubImage%dD(invalid texture image)", dimensions
);
2348 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2349 texImage
, xoffset
, yoffset
, 0,
2350 width
, height
, 1)) {
2354 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2355 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2357 "glTexSubImage%dD(no compression for format)", dimensions
);
2362 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2363 /* both source and dest must be integer-valued, or neither */
2364 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2365 _mesa_is_enum_format_integer(format
)) {
2366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2367 "glTexSubImage%dD(integer/non-integer format mismatch)",
2378 * Test glCopyTexImage[12]D() parameters for errors.
2380 * \param ctx GL context.
2381 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2382 * \param target texture target given by the user.
2383 * \param level image level given by the user.
2384 * \param internalFormat internal format given by the user.
2385 * \param width image width given by the user.
2386 * \param height image height given by the user.
2387 * \param border texture border.
2389 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2391 * Verifies each of the parameters against the constants specified in
2392 * __struct gl_contextRec::Const and the supported extensions, and according
2393 * to the OpenGL specification.
2396 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2397 GLenum target
, GLint level
, GLint internalFormat
,
2398 GLint width
, GLint height
, GLint border
)
2401 GLint rb_base_format
;
2402 struct gl_renderbuffer
*rb
;
2403 GLenum rb_internal_format
;
2406 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2408 dimensions
, _mesa_lookup_enum_by_nr(target
));
2413 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2414 _mesa_error(ctx
, GL_INVALID_VALUE
,
2415 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2419 /* Check that the source buffer is complete */
2420 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2421 if (ctx
->ReadBuffer
->_Status
== 0) {
2422 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2424 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2425 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2426 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2430 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2431 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2432 "glCopyTexImage%dD(multisample FBO)",
2439 if (border
< 0 || border
> 1 ||
2440 ((ctx
->API
!= API_OPENGL_COMPAT
||
2441 target
== GL_TEXTURE_RECTANGLE_NV
||
2442 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2443 _mesa_error(ctx
, GL_INVALID_VALUE
,
2444 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2448 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2451 "glCopyTexImage%dD(read buffer)", dimensions
);
2455 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2458 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2459 switch (internalFormat
) {
2464 case GL_LUMINANCE_ALPHA
:
2467 _mesa_error(ctx
, GL_INVALID_VALUE
,
2468 "glCopyTexImage%dD(internalFormat)", dimensions
);
2473 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2474 if (baseFormat
< 0) {
2475 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2476 "glCopyTexImage%dD(internalFormat)", dimensions
);
2480 rb_internal_format
= rb
->InternalFormat
;
2481 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2482 if (_mesa_is_color_format(internalFormat
)) {
2483 if (rb_base_format
< 0) {
2484 _mesa_error(ctx
, GL_INVALID_VALUE
,
2485 "glCopyTexImage%dD(internalFormat)", dimensions
);
2490 if (_mesa_is_gles(ctx
)) {
2492 if (_mesa_base_format_component_count(baseFormat
) >
2493 _mesa_base_format_component_count(rb_base_format
)) {
2496 if (baseFormat
== GL_DEPTH_COMPONENT
||
2497 baseFormat
== GL_DEPTH_STENCIL
||
2498 rb_base_format
== GL_DEPTH_COMPONENT
||
2499 rb_base_format
== GL_DEPTH_STENCIL
||
2500 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2501 baseFormat
== GL_ALPHA
) &&
2502 rb_base_format
!= GL_RGBA
) ||
2503 internalFormat
== GL_RGB9_E5
) {
2506 if (internalFormat
== GL_RGB9_E5
) {
2510 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2511 "glCopyTexImage%dD(internalFormat)", dimensions
);
2516 if (_mesa_is_gles3(ctx
)) {
2517 bool rb_is_srgb
= false;
2518 bool dst_is_srgb
= false;
2520 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2521 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2525 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2529 if (rb_is_srgb
!= dst_is_srgb
) {
2530 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2531 * OpenGLES 3.0.0 spec says:
2533 * "The error INVALID_OPERATION is also generated if the
2534 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2535 * framebuffer attachment corresponding to the read buffer
2536 * is LINEAR (see section 6.1.13) and internalformat is
2537 * one of the sRGB formats described in section 3.8.16, or
2538 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2539 * SRGB and internalformat is not one of the sRGB formats."
2541 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2542 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2547 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2549 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2553 /* From the EXT_texture_integer spec:
2555 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2556 * if the texture internalformat is an integer format and the read color
2557 * buffer is not an integer format, or if the internalformat is not an
2558 * integer format and the read color buffer is an integer format."
2560 if (_mesa_is_color_format(internalFormat
)) {
2561 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2562 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2563 if (is_int
|| is_rbint
) {
2564 if (is_int
!= is_rbint
) {
2565 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2566 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2568 } else if (_mesa_is_gles(ctx
) &&
2569 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2570 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2572 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2578 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2579 _mesa_is_cube_face(target
)) && width
!= height
) {
2580 _mesa_error(ctx
, GL_INVALID_VALUE
,
2581 "glTexImage2D(cube width != height)");
2585 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2586 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2587 _mesa_error(ctx
, GL_INVALID_ENUM
,
2588 "glCopyTexImage%dD(target)", dimensions
);
2591 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2592 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2593 "glCopyTexImage%dD(no compression for format)", dimensions
);
2597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2598 "glCopyTexImage%dD(border!=0)", dimensions
);
2603 if (!mutable_tex_object(ctx
, target
)) {
2604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2605 "glCopyTexImage%dD(immutable texture)", dimensions
);
2609 /* if we get here, the parameters are OK */
2615 * Test glCopyTexSubImage[12]D() parameters for errors.
2616 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2619 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2620 GLenum target
, GLint level
,
2621 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2622 GLint width
, GLint height
)
2624 struct gl_texture_object
*texObj
;
2625 struct gl_texture_image
*texImage
;
2627 /* Check that the source buffer is complete */
2628 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2629 if (ctx
->ReadBuffer
->_Status
== 0) {
2630 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2632 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2633 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2634 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2638 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2640 "glCopyTexSubImage%dD(multisample FBO)",
2646 /* check target (proxies not allowed) */
2647 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2648 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2649 dimensions
, _mesa_lookup_enum_by_nr(target
));
2654 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2655 _mesa_error(ctx
, GL_INVALID_VALUE
,
2656 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2660 /* Get dest texture object / image pointers */
2661 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2663 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2667 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2669 /* destination image does not exist */
2670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2671 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2675 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2676 dimensions
, texImage
,
2677 xoffset
, yoffset
, zoffset
,
2678 width
, height
, 1)) {
2682 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2683 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2684 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2685 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2690 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2691 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2695 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2697 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2698 dimensions
, texImage
->_BaseFormat
);
2702 /* From the EXT_texture_integer spec:
2704 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2705 * if the texture internalformat is an integer format and the read color
2706 * buffer is not an integer format, or if the internalformat is not an
2707 * integer format and the read color buffer is an integer format."
2709 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2710 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2712 if (_mesa_is_format_integer_color(rb
->Format
) !=
2713 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2715 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2720 /* if we get here, the parameters are OK */
2725 /** Callback info for walking over FBO hash table */
2728 struct gl_context
*ctx
;
2729 struct gl_texture_object
*texObj
;
2735 * Check render to texture callback. Called from _mesa_HashWalk().
2738 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2740 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2741 const struct cb_info
*info
= (struct cb_info
*) userData
;
2742 struct gl_context
*ctx
= info
->ctx
;
2743 const struct gl_texture_object
*texObj
= info
->texObj
;
2744 const GLuint level
= info
->level
, face
= info
->face
;
2746 /* If this is a user-created FBO */
2747 if (_mesa_is_user_fbo(fb
)) {
2749 /* check if any of the FBO's attachments point to 'texObj' */
2750 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2751 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2752 if (att
->Type
== GL_TEXTURE
&&
2753 att
->Texture
== texObj
&&
2754 att
->TextureLevel
== level
&&
2755 att
->CubeMapFace
== face
) {
2756 ASSERT(_mesa_get_attachment_teximage(att
));
2757 /* Tell driver about the new renderbuffer texture */
2758 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2759 /* Mark fb status as indeterminate to force re-validation */
2768 * When a texture image is specified we have to check if it's bound to
2769 * any framebuffer objects (render to texture) in order to detect changes
2770 * in size or format since that effects FBO completeness.
2771 * Any FBOs rendering into the texture must be re-validated.
2774 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2775 struct gl_texture_object
*texObj
,
2776 GLuint face
, GLuint level
)
2778 /* Only check this texture if it's been marked as RenderToTexture */
2779 if (texObj
->_RenderToTexture
) {
2780 struct cb_info info
;
2782 info
.texObj
= texObj
;
2785 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2791 * If the texture object's GenerateMipmap flag is set and we've
2792 * changed the texture base level image, regenerate the rest of the
2793 * mipmap levels now.
2796 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2797 struct gl_texture_object
*texObj
, GLint level
)
2799 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2800 if (texObj
->GenerateMipmap
&&
2801 level
== texObj
->BaseLevel
&&
2802 level
< texObj
->MaxLevel
) {
2803 ASSERT(ctx
->Driver
.GenerateMipmap
);
2804 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2809 /** Debug helper: override the user-requested internal format */
2811 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2814 if (internalFormat
== GL_RGBA16F_ARB
||
2815 internalFormat
== GL_RGBA32F_ARB
) {
2816 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2819 else if (internalFormat
== GL_RGB16F_ARB
||
2820 internalFormat
== GL_RGB32F_ARB
) {
2821 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2824 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2825 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2826 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2827 return GL_LUMINANCE_ALPHA
;
2829 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2830 internalFormat
== GL_LUMINANCE32F_ARB
) {
2831 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2832 return GL_LUMINANCE
;
2834 else if (internalFormat
== GL_ALPHA16F_ARB
||
2835 internalFormat
== GL_ALPHA32F_ARB
) {
2836 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2840 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2841 internalFormat = GL_RGBA;
2845 return internalFormat
;
2848 return internalFormat
;
2854 * Choose the actual hardware format for a texture image.
2855 * Try to use the same format as the previous image level when possible.
2856 * Otherwise, ask the driver for the best format.
2857 * It's important to try to choose a consistant format for all levels
2858 * for efficient texture memory layout/allocation. In particular, this
2859 * comes up during automatic mipmap generation.
2862 _mesa_choose_texture_format(struct gl_context
*ctx
,
2863 struct gl_texture_object
*texObj
,
2864 GLenum target
, GLint level
,
2865 GLenum internalFormat
, GLenum format
, GLenum type
)
2869 /* see if we've already chosen a format for the previous level */
2871 struct gl_texture_image
*prevImage
=
2872 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2873 /* See if the prev level is defined and has an internal format which
2874 * matches the new internal format.
2877 prevImage
->Width
> 0 &&
2878 prevImage
->InternalFormat
== internalFormat
) {
2879 /* use the same format */
2880 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2881 return prevImage
->TexFormat
;
2885 /* If the application requested compression to an S3TC format but we don't
2886 * have the DTXn library, force a generic compressed format instead.
2888 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2889 const GLenum before
= internalFormat
;
2891 switch (internalFormat
) {
2892 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2893 if (!ctx
->Mesa_DXTn
)
2894 internalFormat
= GL_COMPRESSED_RGB
;
2896 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2897 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2898 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2899 if (!ctx
->Mesa_DXTn
)
2900 internalFormat
= GL_COMPRESSED_RGBA
;
2906 if (before
!= internalFormat
) {
2908 "DXT compression requested (%s), "
2909 "but libtxc_dxtn library not installed. Using %s "
2911 _mesa_lookup_enum_by_nr(before
),
2912 _mesa_lookup_enum_by_nr(internalFormat
));
2916 /* choose format from scratch */
2917 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2919 ASSERT(f
!= MESA_FORMAT_NONE
);
2924 * Adjust pixel unpack params and image dimensions to strip off the
2925 * one-pixel texture border.
2927 * Gallium and intel don't support texture borders. They've seldem been used
2928 * and seldom been implemented correctly anyway.
2930 * \param unpackNew returns the new pixel unpack parameters
2933 strip_texture_border(GLenum target
,
2934 GLint
*width
, GLint
*height
, GLint
*depth
,
2935 const struct gl_pixelstore_attrib
*unpack
,
2936 struct gl_pixelstore_attrib
*unpackNew
)
2942 *unpackNew
= *unpack
;
2944 if (unpackNew
->RowLength
== 0)
2945 unpackNew
->RowLength
= *width
;
2947 if (unpackNew
->ImageHeight
== 0)
2948 unpackNew
->ImageHeight
= *height
;
2950 assert(*width
>= 3);
2951 unpackNew
->SkipPixels
++; /* skip the border */
2952 *width
= *width
- 2; /* reduce the width by two border pixels */
2954 /* The min height of a texture with a border is 3 */
2955 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2956 unpackNew
->SkipRows
++; /* skip the border */
2957 *height
= *height
- 2; /* reduce the height by two border pixels */
2960 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2961 unpackNew
->SkipImages
++; /* skip the border */
2962 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2968 * Common code to implement all the glTexImage1D/2D/3D functions
2969 * as well as glCompressedTexImage1D/2D/3D.
2970 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2971 * \param format the user's image format (only used if !compressed)
2972 * \param type the user's image type (only used if !compressed)
2973 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2976 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2977 GLenum target
, GLint level
, GLint internalFormat
,
2978 GLsizei width
, GLsizei height
, GLsizei depth
,
2979 GLint border
, GLenum format
, GLenum type
,
2980 GLsizei imageSize
, const GLvoid
*pixels
)
2982 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2983 struct gl_pixelstore_attrib unpack_no_border
;
2984 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2985 struct gl_texture_object
*texObj
;
2986 gl_format texFormat
;
2987 GLboolean dimensionsOK
, sizeOK
;
2989 FLUSH_VERTICES(ctx
, 0);
2991 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2994 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2996 _mesa_lookup_enum_by_nr(target
), level
,
2997 _mesa_lookup_enum_by_nr(internalFormat
),
2998 width
, height
, depth
, border
, pixels
);
3001 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3003 _mesa_lookup_enum_by_nr(target
), level
,
3004 _mesa_lookup_enum_by_nr(internalFormat
),
3005 width
, height
, depth
, border
,
3006 _mesa_lookup_enum_by_nr(format
),
3007 _mesa_lookup_enum_by_nr(type
), pixels
);
3010 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3012 /* target error checking */
3013 if (!legal_teximage_target(ctx
, dims
, target
)) {
3014 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3015 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3019 /* general error checking */
3021 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3023 width
, height
, depth
,
3028 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3029 format
, type
, width
, height
, depth
, border
))
3033 /* Here we convert a cpal compressed image into a regular glTexImage2D
3034 * call by decompressing the texture. If we really want to support cpal
3035 * textures in any driver this would have to be changed.
3037 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3038 switch (internalFormat
) {
3039 case GL_PALETTE4_RGB8_OES
:
3040 case GL_PALETTE4_RGBA8_OES
:
3041 case GL_PALETTE4_R5_G6_B5_OES
:
3042 case GL_PALETTE4_RGBA4_OES
:
3043 case GL_PALETTE4_RGB5_A1_OES
:
3044 case GL_PALETTE8_RGB8_OES
:
3045 case GL_PALETTE8_RGBA8_OES
:
3046 case GL_PALETTE8_R5_G6_B5_OES
:
3047 case GL_PALETTE8_RGBA4_OES
:
3048 case GL_PALETTE8_RGB5_A1_OES
:
3049 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3050 width
, height
, imageSize
, pixels
);
3055 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3059 /* For glCompressedTexImage() the driver has no choice about the
3060 * texture format since we'll never transcode the user's compressed
3061 * image data. The internalFormat was error checked earlier.
3063 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3066 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3067 internalFormat
, format
, type
);
3070 assert(texFormat
!= MESA_FORMAT_NONE
);
3072 /* check that width, height, depth are legal for the mipmap level */
3073 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3074 height
, depth
, border
);
3076 /* check that the texture won't take too much memory, etc */
3077 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3079 width
, height
, depth
, border
);
3081 if (_mesa_is_proxy_texture(target
)) {
3082 /* Proxy texture: just clear or set state depending on error checking */
3083 struct gl_texture_image
*texImage
=
3084 get_proxy_tex_image(ctx
, target
, level
);
3087 return; /* GL_OUT_OF_MEMORY already recorded */
3089 if (dimensionsOK
&& sizeOK
) {
3090 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3091 border
, internalFormat
, texFormat
);
3094 clear_teximage_fields(texImage
);
3098 /* non-proxy target */
3099 const GLuint face
= _mesa_tex_target_to_face(target
);
3100 struct gl_texture_image
*texImage
;
3102 if (!dimensionsOK
) {
3103 _mesa_error(ctx
, GL_INVALID_VALUE
,
3104 "glTexImage%uD(invalid width or height or depth)",
3110 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3111 "glTexImage%uD(image too large)", dims
);
3115 /* Allow a hardware driver to just strip out the border, to provide
3116 * reliable but slightly incorrect hardware rendering instead of
3117 * rarely-tested software fallback rendering.
3119 if (border
&& ctx
->Const
.StripTextureBorder
) {
3120 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3123 unpack
= &unpack_no_border
;
3126 if (ctx
->NewState
& _NEW_PIXEL
)
3127 _mesa_update_state(ctx
);
3129 _mesa_lock_texture(ctx
, texObj
);
3131 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3134 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3137 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3139 _mesa_init_teximage_fields(ctx
, texImage
,
3140 width
, height
, depth
,
3141 border
, internalFormat
, texFormat
);
3143 /* Give the texture to the driver. <pixels> may be null. */
3144 if (width
> 0 && height
> 0 && depth
> 0) {
3146 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3150 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3151 type
, pixels
, unpack
);
3155 check_gen_mipmap(ctx
, target
, texObj
, level
);
3157 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3159 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3162 _mesa_unlock_texture(ctx
, texObj
);
3169 * Called from the API. Note that width includes the border.
3172 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3173 GLsizei width
, GLint border
, GLenum format
,
3174 GLenum type
, const GLvoid
*pixels
)
3176 GET_CURRENT_CONTEXT(ctx
);
3177 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3178 border
, format
, type
, 0, pixels
);
3183 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3184 GLsizei width
, GLsizei height
, GLint border
,
3185 GLenum format
, GLenum type
,
3186 const GLvoid
*pixels
)
3188 GET_CURRENT_CONTEXT(ctx
);
3189 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3190 border
, format
, type
, 0, pixels
);
3195 * Called by the API or display list executor.
3196 * Note that width and height include the border.
3199 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3200 GLsizei width
, GLsizei height
, GLsizei depth
,
3201 GLint border
, GLenum format
, GLenum type
,
3202 const GLvoid
*pixels
)
3204 GET_CURRENT_CONTEXT(ctx
);
3205 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3206 width
, height
, depth
,
3207 border
, format
, type
, 0, pixels
);
3212 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3213 GLsizei width
, GLsizei height
, GLsizei depth
,
3214 GLint border
, GLenum format
, GLenum type
,
3215 const GLvoid
*pixels
)
3217 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3218 depth
, border
, format
, type
, pixels
);
3223 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3225 struct gl_texture_object
*texObj
;
3226 struct gl_texture_image
*texImage
;
3228 GET_CURRENT_CONTEXT(ctx
);
3229 FLUSH_VERTICES(ctx
, 0);
3233 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3235 case GL_TEXTURE_EXTERNAL_OES
:
3236 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3239 valid_target
= false;
3243 if (!valid_target
) {
3244 _mesa_error(ctx
, GL_INVALID_ENUM
,
3245 "glEGLImageTargetTexture2D(target=%d)", target
);
3250 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3251 "glEGLImageTargetTexture2D(image=%p)", image
);
3255 if (ctx
->NewState
& _NEW_PIXEL
)
3256 _mesa_update_state(ctx
);
3258 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3259 _mesa_lock_texture(ctx
, texObj
);
3261 if (texObj
->Immutable
) {
3262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3263 "glEGLImageTargetTexture2D(texture is immutable)");
3264 _mesa_unlock_texture(ctx
, texObj
);
3268 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3270 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3272 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3274 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3275 texObj
, texImage
, image
);
3277 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3279 _mesa_unlock_texture(ctx
, texObj
);
3286 * Implement all the glTexSubImage1/2/3D() functions.
3289 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3290 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3291 GLsizei width
, GLsizei height
, GLsizei depth
,
3292 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3294 struct gl_texture_object
*texObj
;
3295 struct gl_texture_image
*texImage
;
3297 FLUSH_VERTICES(ctx
, 0);
3299 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3300 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3302 _mesa_lookup_enum_by_nr(target
), level
,
3303 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3304 _mesa_lookup_enum_by_nr(format
),
3305 _mesa_lookup_enum_by_nr(type
), pixels
);
3307 /* check target (proxies not allowed) */
3308 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3309 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3310 dims
, _mesa_lookup_enum_by_nr(target
));
3314 if (ctx
->NewState
& _NEW_PIXEL
)
3315 _mesa_update_state(ctx
);
3317 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3318 xoffset
, yoffset
, zoffset
,
3319 width
, height
, depth
, format
, type
)) {
3320 return; /* error was detected */
3323 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3325 _mesa_lock_texture(ctx
, texObj
);
3327 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3329 if (width
> 0 && height
> 0 && depth
> 0) {
3330 /* If we have a border, offset=-1 is legal. Bias by border width. */
3333 if (target
!= GL_TEXTURE_2D_ARRAY
)
3334 zoffset
+= texImage
->Border
;
3337 if (target
!= GL_TEXTURE_1D_ARRAY
)
3338 yoffset
+= texImage
->Border
;
3341 xoffset
+= texImage
->Border
;
3344 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3345 xoffset
, yoffset
, zoffset
,
3346 width
, height
, depth
,
3347 format
, type
, pixels
, &ctx
->Unpack
);
3349 check_gen_mipmap(ctx
, target
, texObj
, level
);
3351 ctx
->NewState
|= _NEW_TEXTURE
;
3354 _mesa_unlock_texture(ctx
, texObj
);
3359 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3360 GLint xoffset
, GLsizei width
,
3361 GLenum format
, GLenum type
,
3362 const GLvoid
*pixels
)
3364 GET_CURRENT_CONTEXT(ctx
);
3365 texsubimage(ctx
, 1, target
, level
,
3368 format
, type
, pixels
);
3373 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3374 GLint xoffset
, GLint yoffset
,
3375 GLsizei width
, GLsizei height
,
3376 GLenum format
, GLenum type
,
3377 const GLvoid
*pixels
)
3379 GET_CURRENT_CONTEXT(ctx
);
3380 texsubimage(ctx
, 2, target
, level
,
3381 xoffset
, yoffset
, 0,
3383 format
, type
, pixels
);
3389 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3390 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3391 GLsizei width
, GLsizei height
, GLsizei depth
,
3392 GLenum format
, GLenum type
,
3393 const GLvoid
*pixels
)
3395 GET_CURRENT_CONTEXT(ctx
);
3396 texsubimage(ctx
, 3, target
, level
,
3397 xoffset
, yoffset
, zoffset
,
3398 width
, height
, depth
,
3399 format
, type
, pixels
);
3405 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3406 * from. This depends on whether the texture contains color or depth values.
3408 static struct gl_renderbuffer
*
3409 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3411 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3412 /* reading from depth/stencil buffer */
3413 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3416 /* copying from color buffer */
3417 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3424 * Implement the glCopyTexImage1/2D() functions.
3427 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3428 GLenum target
, GLint level
, GLenum internalFormat
,
3429 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3431 struct gl_texture_object
*texObj
;
3432 struct gl_texture_image
*texImage
;
3433 const GLuint face
= _mesa_tex_target_to_face(target
);
3434 gl_format texFormat
;
3436 FLUSH_VERTICES(ctx
, 0);
3438 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3439 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3441 _mesa_lookup_enum_by_nr(target
), level
,
3442 _mesa_lookup_enum_by_nr(internalFormat
),
3443 x
, y
, width
, height
, border
);
3445 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3446 _mesa_update_state(ctx
);
3448 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3449 width
, height
, border
))
3452 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3454 _mesa_error(ctx
, GL_INVALID_VALUE
,
3455 "glCopyTexImage%uD(invalid width or height)", dims
);
3459 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3462 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3463 internalFormat
, GL_NONE
, GL_NONE
);
3464 assert(texFormat
!= MESA_FORMAT_NONE
);
3466 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3468 width
, height
, 1, border
)) {
3469 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3470 "glCopyTexImage%uD(image too large)", dims
);
3474 if (border
&& ctx
->Const
.StripTextureBorder
) {
3476 width
-= border
* 2;
3479 height
-= border
* 2;
3484 _mesa_lock_texture(ctx
, texObj
);
3486 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3489 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3492 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3494 /* Free old texture image */
3495 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3497 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3498 border
, internalFormat
, texFormat
);
3500 if (width
&& height
) {
3501 /* Allocate texture memory (no pixel data yet) */
3502 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3504 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3506 struct gl_renderbuffer
*srcRb
=
3507 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3509 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3510 srcRb
, srcX
, srcY
, width
, height
);
3513 check_gen_mipmap(ctx
, target
, texObj
, level
);
3516 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3518 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3521 _mesa_unlock_texture(ctx
, texObj
);
3527 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3528 GLenum internalFormat
,
3530 GLsizei width
, GLint border
)
3532 GET_CURRENT_CONTEXT(ctx
);
3533 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3539 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3540 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3543 GET_CURRENT_CONTEXT(ctx
);
3544 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3545 x
, y
, width
, height
, border
);
3551 * Implementation for glCopyTexSubImage1/2/3D() functions.
3554 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3555 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3556 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3558 struct gl_texture_object
*texObj
;
3559 struct gl_texture_image
*texImage
;
3561 FLUSH_VERTICES(ctx
, 0);
3563 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3564 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3566 _mesa_lookup_enum_by_nr(target
),
3567 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3569 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3570 _mesa_update_state(ctx
);
3572 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3573 xoffset
, yoffset
, zoffset
, width
, height
)) {
3577 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3579 _mesa_lock_texture(ctx
, texObj
);
3581 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3583 /* If we have a border, offset=-1 is legal. Bias by border width. */
3586 if (target
!= GL_TEXTURE_2D_ARRAY
)
3587 zoffset
+= texImage
->Border
;
3590 if (target
!= GL_TEXTURE_1D_ARRAY
)
3591 yoffset
+= texImage
->Border
;
3594 xoffset
+= texImage
->Border
;
3597 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3599 struct gl_renderbuffer
*srcRb
=
3600 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3602 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3603 xoffset
, yoffset
, zoffset
,
3604 srcRb
, x
, y
, width
, height
);
3606 check_gen_mipmap(ctx
, target
, texObj
, level
);
3608 ctx
->NewState
|= _NEW_TEXTURE
;
3611 _mesa_unlock_texture(ctx
, texObj
);
3616 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3617 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3619 GET_CURRENT_CONTEXT(ctx
);
3620 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3626 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3627 GLint xoffset
, GLint yoffset
,
3628 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3630 GET_CURRENT_CONTEXT(ctx
);
3631 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3638 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3639 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3640 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3642 GET_CURRENT_CONTEXT(ctx
);
3643 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3644 x
, y
, width
, height
);
3650 /**********************************************************************/
3651 /****** Compressed Textures ******/
3652 /**********************************************************************/
3656 * Error checking for glCompressedTexSubImage[123]D().
3657 * \return error code or GL_NO_ERROR.
3660 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3661 GLenum target
, GLint level
,
3662 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3663 GLsizei width
, GLsizei height
, GLsizei depth
,
3664 GLenum format
, GLsizei imageSize
)
3666 struct gl_texture_object
*texObj
;
3667 struct gl_texture_image
*texImage
;
3675 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3676 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3677 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3678 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3679 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3680 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3684 targetOK
= GL_FALSE
;
3689 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3693 /* no 1D compressed textures at this time */
3694 targetOK
= GL_FALSE
;
3699 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3704 /* this will catch any invalid compressed format token */
3705 if (!_mesa_is_compressed_format(ctx
, format
)) {
3706 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3711 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3712 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3717 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3718 if (expectedSize
!= imageSize
) {
3719 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3724 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3726 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3727 "glCompressedTexSubImage%uD()", dims
);
3731 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3734 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3738 if ((GLint
) format
!= texImage
->InternalFormat
) {
3739 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3740 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3744 if (compressedteximage_only_format(ctx
, format
)) {
3745 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3746 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3751 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3752 texImage
, xoffset
, yoffset
, zoffset
,
3753 width
, height
, depth
)) {
3762 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3763 GLenum internalFormat
, GLsizei width
,
3764 GLint border
, GLsizei imageSize
,
3767 GET_CURRENT_CONTEXT(ctx
);
3768 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3769 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3774 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3775 GLenum internalFormat
, GLsizei width
,
3776 GLsizei height
, GLint border
, GLsizei imageSize
,
3779 GET_CURRENT_CONTEXT(ctx
);
3780 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3781 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3786 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3787 GLenum internalFormat
, GLsizei width
,
3788 GLsizei height
, GLsizei depth
, GLint border
,
3789 GLsizei imageSize
, const GLvoid
*data
)
3791 GET_CURRENT_CONTEXT(ctx
);
3792 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3793 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3798 * Common helper for glCompressedTexSubImage1/2/3D().
3801 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3802 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3803 GLsizei width
, GLsizei height
, GLsizei depth
,
3804 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3806 struct gl_texture_object
*texObj
;
3807 struct gl_texture_image
*texImage
;
3808 GET_CURRENT_CONTEXT(ctx
);
3809 FLUSH_VERTICES(ctx
, 0);
3811 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3812 xoffset
, yoffset
, zoffset
,
3813 width
, height
, depth
,
3814 format
, imageSize
)) {
3818 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3820 _mesa_lock_texture(ctx
, texObj
);
3822 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3825 if (width
> 0 && height
> 0 && depth
> 0) {
3826 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3827 xoffset
, yoffset
, zoffset
,
3828 width
, height
, depth
,
3829 format
, imageSize
, data
);
3831 check_gen_mipmap(ctx
, target
, texObj
, level
);
3833 ctx
->NewState
|= _NEW_TEXTURE
;
3836 _mesa_unlock_texture(ctx
, texObj
);
3841 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3842 GLsizei width
, GLenum format
,
3843 GLsizei imageSize
, const GLvoid
*data
)
3845 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3846 format
, imageSize
, data
);
3851 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3852 GLint yoffset
, GLsizei width
, GLsizei height
,
3853 GLenum format
, GLsizei imageSize
,
3856 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3857 width
, height
, 1, format
, imageSize
, data
);
3862 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3863 GLint yoffset
, GLint zoffset
, GLsizei width
,
3864 GLsizei height
, GLsizei depth
, GLenum format
,
3865 GLsizei imageSize
, const GLvoid
*data
)
3867 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3868 width
, height
, depth
, format
, imageSize
, data
);
3872 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3874 switch (internalFormat
) {
3876 return MESA_FORMAT_A8
;
3878 return MESA_FORMAT_A16
;
3879 case GL_ALPHA16F_ARB
:
3880 return MESA_FORMAT_ALPHA_FLOAT16
;
3881 case GL_ALPHA32F_ARB
:
3882 return MESA_FORMAT_ALPHA_FLOAT32
;
3883 case GL_ALPHA8I_EXT
:
3884 return MESA_FORMAT_ALPHA_INT8
;
3885 case GL_ALPHA16I_EXT
:
3886 return MESA_FORMAT_ALPHA_INT16
;
3887 case GL_ALPHA32I_EXT
:
3888 return MESA_FORMAT_ALPHA_INT32
;
3889 case GL_ALPHA8UI_EXT
:
3890 return MESA_FORMAT_ALPHA_UINT8
;
3891 case GL_ALPHA16UI_EXT
:
3892 return MESA_FORMAT_ALPHA_UINT16
;
3893 case GL_ALPHA32UI_EXT
:
3894 return MESA_FORMAT_ALPHA_UINT32
;
3896 return MESA_FORMAT_L8
;
3897 case GL_LUMINANCE16
:
3898 return MESA_FORMAT_L16
;
3899 case GL_LUMINANCE16F_ARB
:
3900 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3901 case GL_LUMINANCE32F_ARB
:
3902 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3903 case GL_LUMINANCE8I_EXT
:
3904 return MESA_FORMAT_LUMINANCE_INT8
;
3905 case GL_LUMINANCE16I_EXT
:
3906 return MESA_FORMAT_LUMINANCE_INT16
;
3907 case GL_LUMINANCE32I_EXT
:
3908 return MESA_FORMAT_LUMINANCE_INT32
;
3909 case GL_LUMINANCE8UI_EXT
:
3910 return MESA_FORMAT_LUMINANCE_UINT8
;
3911 case GL_LUMINANCE16UI_EXT
:
3912 return MESA_FORMAT_LUMINANCE_UINT16
;
3913 case GL_LUMINANCE32UI_EXT
:
3914 return MESA_FORMAT_LUMINANCE_UINT32
;
3915 case GL_LUMINANCE8_ALPHA8
:
3916 return MESA_FORMAT_AL88
;
3917 case GL_LUMINANCE16_ALPHA16
:
3918 return MESA_FORMAT_AL1616
;
3919 case GL_LUMINANCE_ALPHA16F_ARB
:
3920 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3921 case GL_LUMINANCE_ALPHA32F_ARB
:
3922 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3923 case GL_LUMINANCE_ALPHA8I_EXT
:
3924 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3925 case GL_LUMINANCE_ALPHA16I_EXT
:
3926 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3927 case GL_LUMINANCE_ALPHA32I_EXT
:
3928 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3929 case GL_LUMINANCE_ALPHA8UI_EXT
:
3930 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3931 case GL_LUMINANCE_ALPHA16UI_EXT
:
3932 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3933 case GL_LUMINANCE_ALPHA32UI_EXT
:
3934 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3936 return MESA_FORMAT_I8
;
3937 case GL_INTENSITY16
:
3938 return MESA_FORMAT_I16
;
3939 case GL_INTENSITY16F_ARB
:
3940 return MESA_FORMAT_INTENSITY_FLOAT16
;
3941 case GL_INTENSITY32F_ARB
:
3942 return MESA_FORMAT_INTENSITY_FLOAT32
;
3943 case GL_INTENSITY8I_EXT
:
3944 return MESA_FORMAT_INTENSITY_INT8
;
3945 case GL_INTENSITY16I_EXT
:
3946 return MESA_FORMAT_INTENSITY_INT16
;
3947 case GL_INTENSITY32I_EXT
:
3948 return MESA_FORMAT_INTENSITY_INT32
;
3949 case GL_INTENSITY8UI_EXT
:
3950 return MESA_FORMAT_INTENSITY_UINT8
;
3951 case GL_INTENSITY16UI_EXT
:
3952 return MESA_FORMAT_INTENSITY_UINT16
;
3953 case GL_INTENSITY32UI_EXT
:
3954 return MESA_FORMAT_INTENSITY_UINT32
;
3956 return MESA_FORMAT_RGBA8888_REV
;
3958 return MESA_FORMAT_RGBA_16
;
3959 case GL_RGBA16F_ARB
:
3960 return MESA_FORMAT_RGBA_FLOAT16
;
3961 case GL_RGBA32F_ARB
:
3962 return MESA_FORMAT_RGBA_FLOAT32
;
3964 return MESA_FORMAT_RGBA_INT8
;
3965 case GL_RGBA16I_EXT
:
3966 return MESA_FORMAT_RGBA_INT16
;
3967 case GL_RGBA32I_EXT
:
3968 return MESA_FORMAT_RGBA_INT32
;
3969 case GL_RGBA8UI_EXT
:
3970 return MESA_FORMAT_RGBA_UINT8
;
3971 case GL_RGBA16UI_EXT
:
3972 return MESA_FORMAT_RGBA_UINT16
;
3973 case GL_RGBA32UI_EXT
:
3974 return MESA_FORMAT_RGBA_UINT32
;
3977 return MESA_FORMAT_GR88
;
3979 return MESA_FORMAT_GR1616
;
3981 return MESA_FORMAT_RG_FLOAT16
;
3983 return MESA_FORMAT_RG_FLOAT32
;
3985 return MESA_FORMAT_RG_INT8
;
3987 return MESA_FORMAT_RG_INT16
;
3989 return MESA_FORMAT_RG_INT32
;
3991 return MESA_FORMAT_RG_UINT8
;
3993 return MESA_FORMAT_RG_UINT16
;
3995 return MESA_FORMAT_RG_UINT32
;
3998 return MESA_FORMAT_R8
;
4000 return MESA_FORMAT_R16
;
4002 return MESA_FORMAT_R_FLOAT16
;
4004 return MESA_FORMAT_R_FLOAT32
;
4006 return MESA_FORMAT_R_INT8
;
4008 return MESA_FORMAT_R_INT16
;
4010 return MESA_FORMAT_R_INT32
;
4012 return MESA_FORMAT_R_UINT8
;
4014 return MESA_FORMAT_R_UINT16
;
4016 return MESA_FORMAT_R_UINT32
;
4019 return MESA_FORMAT_RGB_FLOAT32
;
4021 return MESA_FORMAT_RGB_UINT32
;
4023 return MESA_FORMAT_RGB_INT32
;
4026 return MESA_FORMAT_NONE
;
4031 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4033 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4036 if (format
== MESA_FORMAT_NONE
)
4037 return MESA_FORMAT_NONE
;
4039 datatype
= _mesa_get_format_datatype(format
);
4040 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4041 return MESA_FORMAT_NONE
;
4043 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4044 return MESA_FORMAT_NONE
;
4046 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4047 * any mention of R/RG formats, but they appear in the GL 3.1 core
4050 if (ctx
->Version
<= 30) {
4051 GLenum base_format
= _mesa_get_format_base_format(format
);
4053 if (base_format
== GL_R
|| base_format
== GL_RG
)
4054 return MESA_FORMAT_NONE
;
4057 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4058 GLenum base_format
= _mesa_get_format_base_format(format
);
4059 if (base_format
== GL_RGB
)
4060 return MESA_FORMAT_NONE
;
4067 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4068 struct gl_buffer_object
*bufObj
,
4069 GLintptr offset
, GLsizeiptr size
)
4071 struct gl_texture_object
*texObj
;
4074 FLUSH_VERTICES(ctx
, 0);
4076 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4077 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4081 format
= validate_texbuffer_format(ctx
, internalFormat
);
4082 if (format
== MESA_FORMAT_NONE
) {
4083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4088 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4090 _mesa_lock_texture(ctx
, texObj
);
4092 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4093 texObj
->BufferObjectFormat
= internalFormat
;
4094 texObj
->_BufferObjectFormat
= format
;
4095 texObj
->BufferOffset
= offset
;
4096 texObj
->BufferSize
= size
;
4098 _mesa_unlock_texture(ctx
, texObj
);
4101 /** GL_ARB_texture_buffer_object */
4103 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4105 struct gl_buffer_object
*bufObj
;
4107 GET_CURRENT_CONTEXT(ctx
);
4109 /* NOTE: ARB_texture_buffer_object has interactions with
4110 * the compatibility profile that are not implemented.
4112 if (!(ctx
->API
== API_OPENGL_CORE
&&
4113 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4114 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4118 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4119 if (!bufObj
&& buffer
) {
4120 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4124 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4127 /** GL_ARB_texture_buffer_range */
4129 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4130 GLintptr offset
, GLsizeiptr size
)
4132 struct gl_buffer_object
*bufObj
;
4134 GET_CURRENT_CONTEXT(ctx
);
4136 if (!(ctx
->API
== API_OPENGL_CORE
&&
4137 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4138 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4142 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4146 (offset
+ size
) > bufObj
->Size
) {
4147 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4150 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4151 _mesa_error(ctx
, GL_INVALID_VALUE
,
4152 "glTexBufferRange(invalid offset alignment)");
4155 } else if (buffer
) {
4156 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4164 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4168 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4170 /* Everything that is allowed for renderbuffers,
4171 * except for a base format of GL_STENCIL_INDEX.
4173 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4174 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4177 /** GL_ARB_texture_multisample */
4179 check_multisample_target(GLuint dims
, GLenum target
)
4182 case GL_TEXTURE_2D_MULTISAMPLE
:
4183 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4186 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4187 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4196 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4197 GLint internalformat
, GLsizei width
, GLsizei height
,
4198 GLsizei depth
, GLboolean fixedsamplelocations
,
4199 GLboolean immutable
, const char *func
)
4201 struct gl_texture_object
*texObj
;
4202 struct gl_texture_image
*texImage
;
4203 GLboolean sizeOK
, dimensionsOK
;
4204 gl_format texFormat
;
4205 GLenum sample_count_error
;
4207 GET_CURRENT_CONTEXT(ctx
);
4209 if (!(ctx
->Extensions
.ARB_texture_multisample
4210 && _mesa_is_desktop_gl(ctx
))) {
4211 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4215 if (!check_multisample_target(dims
, target
)) {
4216 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4220 /* check that the specified internalformat is color/depth/stencil-renderable;
4221 * refer GL3.1 spec 4.4.4
4224 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4225 _mesa_error(ctx
, GL_INVALID_ENUM
,
4226 "%s(internalformat=%s not legal for immutable-format)",
4227 func
, _mesa_lookup_enum_by_nr(internalformat
));
4231 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4232 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4233 "%s(internalformat=%s)",
4234 func
, _mesa_lookup_enum_by_nr(internalformat
));
4238 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4239 internalformat
, samples
);
4240 if (sample_count_error
!= GL_NO_ERROR
) {
4241 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4245 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4247 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4248 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4249 "%s(texture object 0)",
4254 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4256 if (texImage
== NULL
) {
4257 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4261 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4262 internalformat
, GL_NONE
, GL_NONE
);
4263 assert(texFormat
!= MESA_FORMAT_NONE
);
4265 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4266 width
, height
, depth
, 0);
4268 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4269 width
, height
, depth
, 0);
4271 if (_mesa_is_proxy_texture(target
)) {
4272 if (dimensionsOK
&& sizeOK
) {
4273 _mesa_init_teximage_fields(ctx
, texImage
,
4274 width
, height
, depth
, 0, internalformat
, texFormat
);
4275 texImage
->NumSamples
= samples
;
4276 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4279 /* clear all image fields */
4280 _mesa_init_teximage_fields(ctx
, texImage
,
4281 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4285 if (!dimensionsOK
) {
4286 _mesa_error(ctx
, GL_INVALID_VALUE
,
4287 "%s(invalid width or height)", func
);
4292 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4293 "%s(texture too large)", func
);
4297 /* Check if texObj->Immutable is set */
4298 if (texObj
->Immutable
) {
4299 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4303 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4305 _mesa_init_teximage_fields(ctx
, texImage
,
4306 width
, height
, depth
, 0, internalformat
, texFormat
);
4308 texImage
->NumSamples
= samples
;
4309 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4311 if (width
> 0 && height
> 0 && depth
> 0) {
4313 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4314 width
, height
, depth
)) {
4315 /* tidy up the texture image state. strictly speaking,
4316 * we're allowed to just leave this in whatever state we
4317 * like, but being tidy is good.
4319 _mesa_init_teximage_fields(ctx
, texImage
,
4320 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4324 texObj
->Immutable
= immutable
;
4325 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4330 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4331 GLint internalformat
, GLsizei width
,
4332 GLsizei height
, GLboolean fixedsamplelocations
)
4334 teximagemultisample(2, target
, samples
, internalformat
,
4335 width
, height
, 1, fixedsamplelocations
, GL_FALSE
, "glTexImage2DMultisample");
4339 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4340 GLint internalformat
, GLsizei width
,
4341 GLsizei height
, GLsizei depth
,
4342 GLboolean fixedsamplelocations
)
4344 teximagemultisample(3, target
, samples
, internalformat
,
4345 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
, "glTexImage3DMultisample");
4350 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4351 GLenum internalformat
, GLsizei width
,
4352 GLsizei height
, GLboolean fixedsamplelocations
)
4354 teximagemultisample(2, target
, samples
, internalformat
,
4355 width
, height
, 1, fixedsamplelocations
, GL_TRUE
, "glTexStorage2DMultisample");
4359 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4360 GLenum internalformat
, GLsizei width
,
4361 GLsizei height
, GLsizei depth
,
4362 GLboolean fixedsamplelocations
)
4364 teximagemultisample(3, target
, samples
, internalformat
,
4365 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
, "glTexStorage3DMultisample");