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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
45 #include "texcompress_cpal.h"
50 #include "glformats.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * Return the simple base format for a given internal texture format.
64 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
66 * \param ctx GL context.
67 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
69 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
70 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
72 * This is the format which is used during texture application (i.e. the
73 * texture format and env mode determine the arithmetic used.
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
84 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
91 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
106 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
119 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
133 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
135 if (_mesa_is_gles(ctx
)) {
136 switch (internalFormat
) {
144 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
145 switch (internalFormat
) {
153 if (ctx
->Extensions
.ARB_depth_texture
) {
154 switch (internalFormat
) {
155 case GL_DEPTH_COMPONENT
:
156 case GL_DEPTH_COMPONENT16
:
157 case GL_DEPTH_COMPONENT24
:
158 case GL_DEPTH_COMPONENT32
:
159 return GL_DEPTH_COMPONENT
;
165 switch (internalFormat
) {
166 case GL_COMPRESSED_ALPHA
:
168 case GL_COMPRESSED_LUMINANCE
:
170 case GL_COMPRESSED_LUMINANCE_ALPHA
:
171 return GL_LUMINANCE_ALPHA
;
172 case GL_COMPRESSED_INTENSITY
:
174 case GL_COMPRESSED_RGB
:
176 case GL_COMPRESSED_RGBA
:
182 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_FXT1_3DFX
:
186 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
193 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
195 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
196 switch (internalFormat
) {
197 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
199 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
200 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
201 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
208 if (_mesa_is_desktop_gl(ctx
)
209 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
210 switch (internalFormat
) {
222 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
223 if (internalFormat
== GL_YCBCR_MESA
)
224 return GL_YCBCR_MESA
;
227 if (ctx
->Extensions
.ARB_texture_float
) {
228 switch (internalFormat
) {
229 case GL_ALPHA16F_ARB
:
230 case GL_ALPHA32F_ARB
:
238 case GL_INTENSITY16F_ARB
:
239 case GL_INTENSITY32F_ARB
:
241 case GL_LUMINANCE16F_ARB
:
242 case GL_LUMINANCE32F_ARB
:
244 case GL_LUMINANCE_ALPHA16F_ARB
:
245 case GL_LUMINANCE_ALPHA32F_ARB
:
246 return GL_LUMINANCE_ALPHA
;
252 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
253 switch (internalFormat
) {
262 if (ctx
->Extensions
.EXT_texture_snorm
) {
263 switch (internalFormat
) {
278 case GL_RGBA16_SNORM
:
281 case GL_ALPHA8_SNORM
:
282 case GL_ALPHA16_SNORM
:
284 case GL_LUMINANCE_SNORM
:
285 case GL_LUMINANCE8_SNORM
:
286 case GL_LUMINANCE16_SNORM
:
288 case GL_LUMINANCE_ALPHA_SNORM
:
289 case GL_LUMINANCE8_ALPHA8_SNORM
:
290 case GL_LUMINANCE16_ALPHA16_SNORM
:
291 return GL_LUMINANCE_ALPHA
;
292 case GL_INTENSITY_SNORM
:
293 case GL_INTENSITY8_SNORM
:
294 case GL_INTENSITY16_SNORM
:
301 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
302 switch (internalFormat
) {
303 case GL_DEPTH_STENCIL_EXT
:
304 case GL_DEPTH24_STENCIL8_EXT
:
305 return GL_DEPTH_STENCIL_EXT
;
311 if (ctx
->Extensions
.EXT_texture_sRGB
) {
312 switch (internalFormat
) {
315 case GL_COMPRESSED_SRGB_EXT
:
316 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
318 case GL_SRGB_ALPHA_EXT
:
319 case GL_SRGB8_ALPHA8_EXT
:
320 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
321 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
325 case GL_SLUMINANCE_ALPHA_EXT
:
326 case GL_SLUMINANCE8_ALPHA8_EXT
:
327 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
328 return GL_LUMINANCE_ALPHA
;
329 case GL_SLUMINANCE_EXT
:
330 case GL_SLUMINANCE8_EXT
:
331 case GL_COMPRESSED_SLUMINANCE_EXT
:
338 if (ctx
->Version
>= 30 ||
339 ctx
->Extensions
.EXT_texture_integer
) {
340 switch (internalFormat
) {
342 case GL_RGBA16UI_EXT
:
343 case GL_RGBA32UI_EXT
:
359 if (ctx
->Extensions
.EXT_texture_integer
) {
360 switch (internalFormat
) {
361 case GL_ALPHA8UI_EXT
:
362 case GL_ALPHA16UI_EXT
:
363 case GL_ALPHA32UI_EXT
:
365 case GL_ALPHA16I_EXT
:
366 case GL_ALPHA32I_EXT
:
368 case GL_INTENSITY8UI_EXT
:
369 case GL_INTENSITY16UI_EXT
:
370 case GL_INTENSITY32UI_EXT
:
371 case GL_INTENSITY8I_EXT
:
372 case GL_INTENSITY16I_EXT
:
373 case GL_INTENSITY32I_EXT
:
375 case GL_LUMINANCE8UI_EXT
:
376 case GL_LUMINANCE16UI_EXT
:
377 case GL_LUMINANCE32UI_EXT
:
378 case GL_LUMINANCE8I_EXT
:
379 case GL_LUMINANCE16I_EXT
:
380 case GL_LUMINANCE32I_EXT
:
382 case GL_LUMINANCE_ALPHA8UI_EXT
:
383 case GL_LUMINANCE_ALPHA16UI_EXT
:
384 case GL_LUMINANCE_ALPHA32UI_EXT
:
385 case GL_LUMINANCE_ALPHA8I_EXT
:
386 case GL_LUMINANCE_ALPHA16I_EXT
:
387 case GL_LUMINANCE_ALPHA32I_EXT
:
388 return GL_LUMINANCE_ALPHA
;
394 if (ctx
->Extensions
.ARB_texture_rg
) {
395 switch (internalFormat
) {
397 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
399 if (!ctx
->Extensions
.ARB_half_float_pixel
)
403 if (!ctx
->Extensions
.ARB_texture_float
)
412 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
418 case GL_COMPRESSED_RED
:
422 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
424 if (!ctx
->Extensions
.ARB_half_float_pixel
)
428 if (!ctx
->Extensions
.ARB_texture_float
)
437 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
443 case GL_COMPRESSED_RG
:
450 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
451 switch (internalFormat
) {
459 if (ctx
->Extensions
.EXT_packed_float
) {
460 switch (internalFormat
) {
461 case GL_R11F_G11F_B10F_EXT
:
468 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
469 switch (internalFormat
) {
470 case GL_DEPTH_COMPONENT32F
:
471 return GL_DEPTH_COMPONENT
;
472 case GL_DEPTH32F_STENCIL8
:
473 return GL_DEPTH_STENCIL
;
479 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
480 switch (internalFormat
) {
481 case GL_COMPRESSED_RED_RGTC1
:
482 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
484 case GL_COMPRESSED_RG_RGTC2
:
485 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
492 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
493 switch (internalFormat
) {
494 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
495 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
498 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
499 return GL_LUMINANCE_ALPHA
;
505 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
506 switch (internalFormat
) {
507 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
508 return GL_LUMINANCE_ALPHA
;
514 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
515 switch (internalFormat
) {
516 case GL_ETC1_RGB8_OES
:
523 if (_mesa_is_gles3(ctx
)) {
524 switch (internalFormat
) {
525 case GL_COMPRESSED_RGB8_ETC2
:
526 case GL_COMPRESSED_SRGB8_ETC2
:
528 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
529 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
530 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
531 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
533 case GL_COMPRESSED_R11_EAC
:
534 case GL_COMPRESSED_SIGNED_R11_EAC
:
536 case GL_COMPRESSED_RG11_EAC
:
537 case GL_COMPRESSED_SIGNED_RG11_EAC
:
544 if (ctx
->API
== API_OPENGLES
) {
545 switch (internalFormat
) {
546 case GL_PALETTE4_RGB8_OES
:
547 case GL_PALETTE4_R5_G6_B5_OES
:
548 case GL_PALETTE8_RGB8_OES
:
549 case GL_PALETTE8_R5_G6_B5_OES
:
551 case GL_PALETTE4_RGBA8_OES
:
552 case GL_PALETTE8_RGB5_A1_OES
:
553 case GL_PALETTE4_RGBA4_OES
:
554 case GL_PALETTE4_RGB5_A1_OES
:
555 case GL_PALETTE8_RGBA8_OES
:
556 case GL_PALETTE8_RGBA4_OES
:
563 return -1; /* error */
568 * For cube map faces, return a face index in [0,5].
569 * For other targets return 0;
572 _mesa_tex_target_to_face(GLenum target
)
574 if (_mesa_is_cube_face(target
))
575 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
583 * Install gl_texture_image in a gl_texture_object according to the target
584 * and level parameters.
586 * \param tObj texture object.
587 * \param target texture target.
588 * \param level image level.
589 * \param texImage texture image.
592 set_tex_image(struct gl_texture_object
*tObj
,
593 GLenum target
, GLint level
,
594 struct gl_texture_image
*texImage
)
596 const GLuint face
= _mesa_tex_target_to_face(target
);
600 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
603 tObj
->Image
[face
][level
] = texImage
;
605 /* Set the 'back' pointer */
606 texImage
->TexObject
= tObj
;
607 texImage
->Level
= level
;
608 texImage
->Face
= face
;
613 * Allocate a texture image structure.
615 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
618 * \return a pointer to gl_texture_image struct with all fields initialized to
621 struct gl_texture_image
*
622 _mesa_new_texture_image( struct gl_context
*ctx
)
625 return CALLOC_STRUCT(gl_texture_image
);
630 * Free a gl_texture_image and associated data.
631 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
633 * \param texImage texture image.
635 * Free the texture image structure and the associated image data.
638 _mesa_delete_texture_image(struct gl_context
*ctx
,
639 struct gl_texture_image
*texImage
)
641 /* Free texImage->Data and/or any other driver-specific texture
644 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
645 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
651 * Test if a target is a proxy target.
653 * \param target texture target.
655 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
658 _mesa_is_proxy_texture(GLenum target
)
661 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
662 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
664 assert(NUM_TEXTURE_TARGETS
== 10 + 2);
666 return (target
== GL_PROXY_TEXTURE_1D
||
667 target
== GL_PROXY_TEXTURE_2D
||
668 target
== GL_PROXY_TEXTURE_3D
||
669 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
670 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
671 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
672 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
673 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
674 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE
||
675 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
);
680 * Return the proxy target which corresponds to the given texture target
683 _mesa_get_proxy_target(GLenum target
)
687 case GL_PROXY_TEXTURE_1D
:
688 return GL_PROXY_TEXTURE_1D
;
690 case GL_PROXY_TEXTURE_2D
:
691 return GL_PROXY_TEXTURE_2D
;
693 case GL_PROXY_TEXTURE_3D
:
694 return GL_PROXY_TEXTURE_3D
;
695 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
697 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
701 case GL_TEXTURE_CUBE_MAP_ARB
:
702 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
703 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
704 case GL_TEXTURE_RECTANGLE_NV
:
705 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
706 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
707 case GL_TEXTURE_1D_ARRAY_EXT
:
708 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
709 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
710 case GL_TEXTURE_2D_ARRAY_EXT
:
711 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
712 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
713 case GL_TEXTURE_CUBE_MAP_ARRAY
:
714 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
715 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
716 case GL_TEXTURE_2D_MULTISAMPLE
:
717 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
718 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
719 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
720 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
723 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
730 * Get the texture object that corresponds to the target of the given
731 * texture unit. The target should have already been checked for validity.
733 * \param ctx GL context.
734 * \param texUnit texture unit.
735 * \param target texture target.
737 * \return pointer to the texture object on success, or NULL on failure.
739 struct gl_texture_object
*
740 _mesa_select_tex_object(struct gl_context
*ctx
,
741 const struct gl_texture_unit
*texUnit
,
744 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
745 ctx
->Extensions
.EXT_texture_array
);
749 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
750 case GL_PROXY_TEXTURE_1D
:
751 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
753 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
754 case GL_PROXY_TEXTURE_2D
:
755 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
757 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
758 case GL_PROXY_TEXTURE_3D
:
759 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
760 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
761 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
762 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
763 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
764 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
765 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
766 case GL_TEXTURE_CUBE_MAP_ARB
:
767 return ctx
->Extensions
.ARB_texture_cube_map
768 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
769 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
770 return ctx
->Extensions
.ARB_texture_cube_map
771 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
772 case GL_TEXTURE_CUBE_MAP_ARRAY
:
773 return ctx
->Extensions
.ARB_texture_cube_map_array
774 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
775 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
776 return ctx
->Extensions
.ARB_texture_cube_map_array
777 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
778 case GL_TEXTURE_RECTANGLE_NV
:
779 return ctx
->Extensions
.NV_texture_rectangle
780 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
781 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
782 return ctx
->Extensions
.NV_texture_rectangle
783 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
784 case GL_TEXTURE_1D_ARRAY_EXT
:
785 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
786 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
787 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
788 case GL_TEXTURE_2D_ARRAY_EXT
:
789 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
790 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
791 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
792 case GL_TEXTURE_BUFFER
:
793 return ctx
->API
== API_OPENGL_CORE
&&
794 ctx
->Extensions
.ARB_texture_buffer_object
?
795 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
796 case GL_TEXTURE_EXTERNAL_OES
:
797 return ctx
->Extensions
.OES_EGL_image_external
798 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
799 case GL_TEXTURE_2D_MULTISAMPLE
:
800 return ctx
->Extensions
.ARB_texture_multisample
801 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
802 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
803 return ctx
->Extensions
.ARB_texture_multisample
804 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
805 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
806 return ctx
->Extensions
.ARB_texture_multisample
807 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
808 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
809 return ctx
->Extensions
.ARB_texture_multisample
810 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
812 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
819 * Return pointer to texture object for given target on current texture unit.
821 struct gl_texture_object
*
822 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
824 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
825 return _mesa_select_tex_object(ctx
, texUnit
, target
);
830 * Get a texture image pointer from a texture object, given a texture
831 * target and mipmap level. The target and level parameters should
832 * have already been error-checked.
834 * \param ctx GL context.
835 * \param texObj texture unit.
836 * \param target texture target.
837 * \param level image level.
839 * \return pointer to the texture image structure, or NULL on failure.
841 struct gl_texture_image
*
842 _mesa_select_tex_image(struct gl_context
*ctx
,
843 const struct gl_texture_object
*texObj
,
844 GLenum target
, GLint level
)
846 const GLuint face
= _mesa_tex_target_to_face(target
);
850 ASSERT(level
< MAX_TEXTURE_LEVELS
);
852 return texObj
->Image
[face
][level
];
857 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
858 * it and install it. Only return NULL if passed a bad parameter or run
861 struct gl_texture_image
*
862 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
863 GLenum target
, GLint level
)
865 struct gl_texture_image
*texImage
;
870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
872 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
878 set_tex_image(texObj
, target
, level
, texImage
);
886 * Return pointer to the specified proxy texture image.
887 * Note that proxy textures are per-context, not per-texture unit.
888 * \return pointer to texture image or NULL if invalid target, invalid
889 * level, or out of memory.
891 static struct gl_texture_image
*
892 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
894 struct gl_texture_image
*texImage
;
901 case GL_PROXY_TEXTURE_1D
:
902 if (level
>= ctx
->Const
.MaxTextureLevels
)
904 texIndex
= TEXTURE_1D_INDEX
;
906 case GL_PROXY_TEXTURE_2D
:
907 if (level
>= ctx
->Const
.MaxTextureLevels
)
909 texIndex
= TEXTURE_2D_INDEX
;
911 case GL_PROXY_TEXTURE_3D
:
912 if (level
>= ctx
->Const
.Max3DTextureLevels
)
914 texIndex
= TEXTURE_3D_INDEX
;
916 case GL_PROXY_TEXTURE_CUBE_MAP
:
917 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
919 texIndex
= TEXTURE_CUBE_INDEX
;
921 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
924 texIndex
= TEXTURE_RECT_INDEX
;
926 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
927 if (level
>= ctx
->Const
.MaxTextureLevels
)
929 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
931 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
932 if (level
>= ctx
->Const
.MaxTextureLevels
)
934 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
936 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
937 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
939 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
941 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
944 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
946 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
949 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
955 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
957 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
959 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
962 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
963 /* Set the 'back' pointer */
964 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
971 * Get the maximum number of allowed mipmap levels.
973 * \param ctx GL context.
974 * \param target texture target.
976 * \return the maximum number of allowed mipmap levels for the given
977 * texture target, or zero if passed a bad target.
982 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
986 case GL_PROXY_TEXTURE_1D
:
988 case GL_PROXY_TEXTURE_2D
:
989 return ctx
->Const
.MaxTextureLevels
;
991 case GL_PROXY_TEXTURE_3D
:
992 return ctx
->Const
.Max3DTextureLevels
;
993 case GL_TEXTURE_CUBE_MAP
:
994 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
995 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
996 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
997 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1000 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1001 return ctx
->Extensions
.ARB_texture_cube_map
1002 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1003 case GL_TEXTURE_RECTANGLE_NV
:
1004 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1005 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1006 case GL_TEXTURE_1D_ARRAY_EXT
:
1007 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1008 case GL_TEXTURE_2D_ARRAY_EXT
:
1009 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1010 return (ctx
->Extensions
.MESA_texture_array
||
1011 ctx
->Extensions
.EXT_texture_array
)
1012 ? ctx
->Const
.MaxTextureLevels
: 0;
1013 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1014 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1015 return ctx
->Extensions
.ARB_texture_cube_map_array
1016 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1017 case GL_TEXTURE_BUFFER
:
1018 return ctx
->API
== API_OPENGL_CORE
&&
1019 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1020 case GL_TEXTURE_2D_MULTISAMPLE
:
1021 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1022 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1023 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1024 return _mesa_is_desktop_gl(ctx
)
1025 && ctx
->Extensions
.ARB_texture_multisample
1027 case GL_TEXTURE_EXTERNAL_OES
:
1030 return 0; /* bad target */
1036 * Return number of dimensions per mipmap level for the given texture target.
1039 _mesa_get_texture_dimensions(GLenum target
)
1043 case GL_PROXY_TEXTURE_1D
:
1046 case GL_TEXTURE_RECTANGLE
:
1047 case GL_TEXTURE_CUBE_MAP
:
1048 case GL_PROXY_TEXTURE_2D
:
1049 case GL_PROXY_TEXTURE_RECTANGLE
:
1050 case GL_PROXY_TEXTURE_CUBE_MAP
:
1051 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1052 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1053 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1054 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1057 case GL_TEXTURE_1D_ARRAY
:
1058 case GL_PROXY_TEXTURE_1D_ARRAY
:
1059 case GL_TEXTURE_EXTERNAL_OES
:
1060 case GL_TEXTURE_2D_MULTISAMPLE
:
1061 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1064 case GL_PROXY_TEXTURE_3D
:
1065 case GL_TEXTURE_2D_ARRAY
:
1066 case GL_PROXY_TEXTURE_2D_ARRAY
:
1067 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1068 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1069 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1070 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1072 case GL_TEXTURE_BUFFER
:
1075 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1083 * Return the maximum number of mipmap levels for the given target
1084 * and the dimensions.
1085 * The dimensions are expected not to include the border.
1088 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1095 case GL_TEXTURE_1D_ARRAY
:
1098 case GL_TEXTURE_CUBE_MAP
:
1099 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1100 ASSERT(width
== height
);
1104 case GL_TEXTURE_2D_ARRAY
:
1105 size
= MAX2(width
, height
);
1108 size
= MAX3(width
, height
, depth
);
1110 case GL_TEXTURE_RECTANGLE
:
1111 case GL_TEXTURE_EXTERNAL_OES
:
1112 case GL_TEXTURE_2D_MULTISAMPLE
:
1113 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1120 return _mesa_logbase2(size
) + 1;
1124 #if 000 /* not used anymore */
1126 * glTexImage[123]D can accept a NULL image pointer. In this case we
1127 * create a texture image with unspecified image contents per the OpenGL
1131 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1133 const GLint components
= _mesa_components_in_format(format
);
1134 const GLint numPixels
= width
* height
* depth
;
1135 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1139 * Let's see if anyone finds this. If glTexImage2D() is called with
1140 * a NULL image pointer then load the texture image with something
1141 * interesting instead of leaving it indeterminate.
1144 static const char message
[8][32] = {
1145 " X X XXXXX XXX X ",
1146 " XX XX X X X X X ",
1148 " X X XXXX XXX XXXXX ",
1151 " X X XXXXX XXX X X ",
1155 GLubyte
*imgPtr
= data
;
1157 for (h
= 0; h
< depth
; h
++) {
1158 for (i
= 0; i
< height
; i
++) {
1159 GLint srcRow
= 7 - (i
% 8);
1160 for (j
= 0; j
< width
; j
++) {
1161 GLint srcCol
= j
% 32;
1162 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1163 for (k
= 0; k
< components
; k
++) {
1179 * Set the size and format-related fields of a gl_texture_image struct
1180 * to zero. This is used when a proxy texture test fails.
1183 clear_teximage_fields(struct gl_texture_image
*img
)
1186 img
->_BaseFormat
= 0;
1187 img
->InternalFormat
= 0;
1196 img
->HeightLog2
= 0;
1198 img
->TexFormat
= MESA_FORMAT_NONE
;
1199 img
->NumSamples
= 0;
1200 img
->FixedSampleLocations
= GL_TRUE
;
1205 * Initialize basic fields of the gl_texture_image struct.
1207 * \param ctx GL context.
1208 * \param img texture image structure to be initialized.
1209 * \param width image width.
1210 * \param height image height.
1211 * \param depth image depth.
1212 * \param border image border.
1213 * \param internalFormat internal format.
1214 * \param format the actual hardware format (one of MESA_FORMAT_*)
1216 * Fills in the fields of \p img with the given information.
1217 * Note: width, height and depth include the border.
1220 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1221 struct gl_texture_image
*img
,
1222 GLsizei width
, GLsizei height
, GLsizei depth
,
1223 GLint border
, GLenum internalFormat
,
1229 ASSERT(height
>= 0);
1232 target
= img
->TexObject
->Target
;
1233 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1234 ASSERT(img
->_BaseFormat
> 0);
1235 img
->InternalFormat
= internalFormat
;
1236 img
->Border
= border
;
1238 img
->Height
= height
;
1241 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1242 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1244 img
->NumSamples
= 0;
1245 img
->FixedSampleLocations
= GL_TRUE
;
1249 case GL_TEXTURE_BUFFER
:
1250 case GL_PROXY_TEXTURE_1D
:
1255 img
->HeightLog2
= 0;
1262 case GL_TEXTURE_1D_ARRAY
:
1263 case GL_PROXY_TEXTURE_1D_ARRAY
:
1264 img
->Height2
= height
; /* no border */
1265 img
->HeightLog2
= 0; /* not used */
1273 case GL_TEXTURE_RECTANGLE
:
1274 case GL_TEXTURE_CUBE_MAP
:
1275 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1276 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1277 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1278 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1279 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1281 case GL_TEXTURE_EXTERNAL_OES
:
1282 case GL_PROXY_TEXTURE_2D
:
1283 case GL_PROXY_TEXTURE_RECTANGLE
:
1284 case GL_PROXY_TEXTURE_CUBE_MAP
:
1285 case GL_TEXTURE_2D_MULTISAMPLE
:
1286 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1287 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1288 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1295 case GL_TEXTURE_2D_ARRAY
:
1296 case GL_PROXY_TEXTURE_2D_ARRAY
:
1297 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1298 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1299 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1300 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1301 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1302 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1303 img
->Depth2
= depth
; /* no border */
1304 img
->DepthLog2
= 0; /* not used */
1307 case GL_PROXY_TEXTURE_3D
:
1308 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1309 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1310 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1311 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1314 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1319 _mesa_get_tex_max_num_levels(target
,
1320 img
->Width2
, img
->Height2
, img
->Depth2
);
1321 img
->TexFormat
= format
;
1326 * Free and clear fields of the gl_texture_image struct.
1328 * \param ctx GL context.
1329 * \param texImage texture image structure to be cleared.
1331 * After the call, \p texImage will have no data associated with it. Its
1332 * fields are cleared so that its parent object will test incomplete.
1335 _mesa_clear_texture_image(struct gl_context
*ctx
,
1336 struct gl_texture_image
*texImage
)
1338 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1339 clear_teximage_fields(texImage
);
1344 * Check the width, height, depth and border of a texture image are legal.
1345 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1347 * The target and level parameters will have already been validated.
1348 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1351 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1352 GLint level
, GLint width
, GLint height
,
1353 GLint depth
, GLint border
)
1359 case GL_PROXY_TEXTURE_1D
:
1360 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1361 maxSize
>>= level
; /* level size */
1362 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1364 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1365 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1371 case GL_PROXY_TEXTURE_2D
:
1372 case GL_TEXTURE_2D_MULTISAMPLE
:
1373 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1374 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1376 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1378 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1380 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1381 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1383 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1389 case GL_PROXY_TEXTURE_3D
:
1390 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1392 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1394 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1396 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1398 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1399 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1401 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1403 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1408 case GL_TEXTURE_RECTANGLE_NV
:
1409 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1412 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1413 if (width
< 0 || width
> maxSize
)
1415 if (height
< 0 || height
> maxSize
)
1419 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1420 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1421 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1422 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1423 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1424 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1425 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1426 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1428 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1430 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1432 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1433 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1435 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1440 case GL_TEXTURE_1D_ARRAY_EXT
:
1441 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1442 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1444 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1446 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1448 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1449 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1454 case GL_TEXTURE_2D_ARRAY_EXT
:
1455 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1456 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1457 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1458 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1460 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1462 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1464 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1466 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1467 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1469 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1474 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1475 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1476 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1477 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1479 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1481 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1483 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1485 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1486 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1488 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1493 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1500 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1501 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1502 * \param destImage the destination texture image.
1503 * \return GL_TRUE if error found, GL_FALSE otherwise.
1506 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1507 const char *function
, GLuint dims
,
1508 const struct gl_texture_image
*destImage
,
1509 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1510 GLsizei subWidth
, GLsizei subHeight
,
1513 const GLenum target
= destImage
->TexObject
->Target
;
1518 _mesa_error(ctx
, GL_INVALID_VALUE
,
1519 "%s%dD(width=%d)", function
, dims
, subWidth
);
1523 if (dims
> 1 && subHeight
< 0) {
1524 _mesa_error(ctx
, GL_INVALID_VALUE
,
1525 "%s%dD(height=%d)", function
, dims
, subHeight
);
1529 if (dims
> 2 && subDepth
< 0) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
,
1531 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1535 /* check xoffset and width */
1536 if (xoffset
< -destImage
->Border
) {
1537 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1542 if (xoffset
+ subWidth
> destImage
->Width
) {
1543 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1548 /* check yoffset and height */
1550 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1551 if (yoffset
< -yBorder
) {
1552 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1556 if (yoffset
+ subHeight
> destImage
->Height
) {
1557 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1563 /* check zoffset and depth */
1565 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1566 if (zoffset
< -zBorder
) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1570 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1571 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1577 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1578 * compressed texture images can be updated. But, that restriction may be
1579 * relaxed for particular compressed formats. At this time, all the
1580 * compressed formats supported by Mesa allow sub-textures to be updated
1581 * along compressed block boundaries.
1583 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1585 if (bw
!= 1 || bh
!= 1) {
1586 /* offset must be multiple of block size */
1587 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1588 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1589 "%s%dD(xoffset = %d, yoffset = %d)",
1590 function
, dims
, xoffset
, yoffset
);
1594 /* size must be multiple of bw by bh or equal to whole texture size */
1595 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1597 "%s%dD(width = %d)", function
, dims
, subWidth
);
1601 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1603 "%s%dD(height = %d)", function
, dims
, subHeight
);
1615 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1616 * specific texture image size checks.
1618 * A hardware driver might override this function if, for example, the
1619 * max 3D texture size is 512x512x64 (i.e. not a cube).
1621 * Note that width, height, depth == 0 is not an error. However, a
1622 * texture with zero width/height/depth will be considered "incomplete"
1623 * and texturing will effectively be disabled.
1625 * \param target any texture target/type
1626 * \param level as passed to glTexImage
1627 * \param format the MESA_FORMAT_x for the tex image
1628 * \param width as passed to glTexImage
1629 * \param height as passed to glTexImage
1630 * \param depth as passed to glTexImage
1631 * \param border as passed to glTexImage
1632 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1635 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1637 GLint width
, GLint height
, GLint depth
, GLint border
)
1639 /* We just check if the image size is less than MaxTextureMbytes.
1640 * Some drivers may do more specific checks.
1642 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1643 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1644 mbytes
*= _mesa_num_tex_faces(target
);
1645 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1650 * Return true if the format is only valid for glCompressedTexImage.
1653 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1656 case GL_ETC1_RGB8_OES
:
1657 case GL_PALETTE4_RGB8_OES
:
1658 case GL_PALETTE4_RGBA8_OES
:
1659 case GL_PALETTE4_R5_G6_B5_OES
:
1660 case GL_PALETTE4_RGBA4_OES
:
1661 case GL_PALETTE4_RGB5_A1_OES
:
1662 case GL_PALETTE8_RGB8_OES
:
1663 case GL_PALETTE8_RGBA8_OES
:
1664 case GL_PALETTE8_R5_G6_B5_OES
:
1665 case GL_PALETTE8_RGBA4_OES
:
1666 case GL_PALETTE8_RGB5_A1_OES
:
1675 * Helper function to determine whether a target and specific compression
1676 * format are supported.
1679 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1682 (void) intFormat
; /* not used yet */
1686 case GL_PROXY_TEXTURE_2D
:
1687 return GL_TRUE
; /* true for any compressed format so far */
1688 case GL_PROXY_TEXTURE_CUBE_MAP
:
1689 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1690 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1691 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1692 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1693 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1694 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1695 return ctx
->Extensions
.ARB_texture_cube_map
;
1696 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1697 case GL_TEXTURE_2D_ARRAY_EXT
:
1698 return (ctx
->Extensions
.MESA_texture_array
||
1699 ctx
->Extensions
.EXT_texture_array
);
1700 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1701 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1702 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1710 * Check if the given texture target value is legal for a
1711 * glTexImage1/2/3D call.
1714 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1720 case GL_PROXY_TEXTURE_1D
:
1721 return _mesa_is_desktop_gl(ctx
);
1729 case GL_PROXY_TEXTURE_2D
:
1730 return _mesa_is_desktop_gl(ctx
);
1731 case GL_PROXY_TEXTURE_CUBE_MAP
:
1732 return _mesa_is_desktop_gl(ctx
)
1733 && ctx
->Extensions
.ARB_texture_cube_map
;
1734 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1735 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1736 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1740 return ctx
->Extensions
.ARB_texture_cube_map
;
1741 case GL_TEXTURE_RECTANGLE_NV
:
1742 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1743 return _mesa_is_desktop_gl(ctx
)
1744 && ctx
->Extensions
.NV_texture_rectangle
;
1745 case GL_TEXTURE_1D_ARRAY_EXT
:
1746 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1747 return _mesa_is_desktop_gl(ctx
)
1748 && (ctx
->Extensions
.MESA_texture_array
||
1749 ctx
->Extensions
.EXT_texture_array
);
1757 case GL_PROXY_TEXTURE_3D
:
1758 return _mesa_is_desktop_gl(ctx
);
1759 case GL_TEXTURE_2D_ARRAY_EXT
:
1760 return (_mesa_is_desktop_gl(ctx
)
1761 && (ctx
->Extensions
.MESA_texture_array
||
1762 ctx
->Extensions
.EXT_texture_array
))
1763 || _mesa_is_gles3(ctx
);
1764 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1765 return _mesa_is_desktop_gl(ctx
)
1766 && (ctx
->Extensions
.MESA_texture_array
||
1767 ctx
->Extensions
.EXT_texture_array
);
1768 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1769 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1770 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1775 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1782 * Check if the given texture target value is legal for a
1783 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1784 * The difference compared to legal_teximage_target() above is that
1785 * proxy targets are not supported.
1788 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1792 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1797 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1799 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1800 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1801 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1802 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1803 return ctx
->Extensions
.ARB_texture_cube_map
;
1804 case GL_TEXTURE_RECTANGLE_NV
:
1805 return _mesa_is_desktop_gl(ctx
)
1806 && ctx
->Extensions
.NV_texture_rectangle
;
1807 case GL_TEXTURE_1D_ARRAY_EXT
:
1808 return _mesa_is_desktop_gl(ctx
)
1809 && (ctx
->Extensions
.MESA_texture_array
||
1810 ctx
->Extensions
.EXT_texture_array
);
1818 case GL_TEXTURE_2D_ARRAY_EXT
:
1819 return (_mesa_is_desktop_gl(ctx
)
1820 && (ctx
->Extensions
.MESA_texture_array
||
1821 ctx
->Extensions
.EXT_texture_array
))
1822 || _mesa_is_gles3(ctx
);
1823 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1824 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1825 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1830 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1838 * Helper function to determine if a texture object is mutable (in terms
1839 * of GL_ARB_texture_storage).
1842 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1844 if (ctx
->Extensions
.ARB_texture_storage
) {
1845 struct gl_texture_object
*texObj
=
1846 _mesa_get_current_tex_object(ctx
, target
);
1847 return !texObj
->Immutable
;
1854 * Return expected size of a compressed texture.
1857 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1860 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1861 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1866 * Test the glTexImage[123]D() parameters for errors.
1868 * \param ctx GL context.
1869 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1870 * \param target texture target given by the user (already validated).
1871 * \param level image level given by the user.
1872 * \param internalFormat internal format given by the user.
1873 * \param format pixel data format given by the user.
1874 * \param type pixel data type given by the user.
1875 * \param width image width given by the user.
1876 * \param height image height given by the user.
1877 * \param depth image depth given by the user.
1878 * \param border image border given by the user.
1880 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1882 * Verifies each of the parameters against the constants specified in
1883 * __struct gl_contextRec::Const and the supported extensions, and according
1884 * to the OpenGL specification.
1885 * Note that we don't fully error-check the width, height, depth values
1886 * here. That's done in _mesa_legal_texture_dimensions() which is used
1887 * by several other GL entrypoints. Plus, texture dims have a special
1888 * interaction with proxy textures.
1891 texture_error_check( struct gl_context
*ctx
,
1892 GLuint dimensions
, GLenum target
,
1893 GLint level
, GLint internalFormat
,
1894 GLenum format
, GLenum type
,
1895 GLint width
, GLint height
,
1896 GLint depth
, GLint border
)
1898 GLboolean colorFormat
;
1901 /* Even though there are no color-index textures, we still have to support
1902 * uploading color-index data and remapping it to RGB via the
1903 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1905 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1907 /* Note: for proxy textures, some error conditions immediately generate
1908 * a GL error in the usual way. But others do not generate a GL error.
1909 * Instead, they cause the width, height, depth, format fields of the
1910 * texture image to be zeroed-out. The GL spec seems to indicate that the
1911 * zero-out behaviour is only used in cases related to memory allocation.
1915 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1916 _mesa_error(ctx
, GL_INVALID_VALUE
,
1917 "glTexImage%dD(level=%d)", dimensions
, level
);
1922 if (border
< 0 || border
> 1 ||
1923 ((ctx
->API
!= API_OPENGL_COMPAT
||
1924 target
== GL_TEXTURE_RECTANGLE_NV
||
1925 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1926 _mesa_error(ctx
, GL_INVALID_VALUE
,
1927 "glTexImage%dD(border=%d)", dimensions
, border
);
1931 if (width
< 0 || height
< 0 || depth
< 0) {
1932 _mesa_error(ctx
, GL_INVALID_VALUE
,
1933 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1937 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1938 * combinations of format, internalFormat, and type that can be used.
1939 * Formats and types that require additional extensions (e.g., GL_FLOAT
1940 * requires GL_OES_texture_float) are filtered elsewhere.
1943 if (_mesa_is_gles(ctx
)) {
1944 if (_mesa_is_gles3(ctx
)) {
1945 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1948 if (format
!= internalFormat
) {
1949 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1950 "glTexImage%dD(format = %s, internalFormat = %s)",
1952 _mesa_lookup_enum_by_nr(format
),
1953 _mesa_lookup_enum_by_nr(internalFormat
));
1957 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1959 if (err
!= GL_NO_ERROR
) {
1960 _mesa_error(ctx
, err
,
1961 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1963 _mesa_lookup_enum_by_nr(format
),
1964 _mesa_lookup_enum_by_nr(type
),
1965 _mesa_lookup_enum_by_nr(internalFormat
));
1970 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1971 _mesa_is_cube_face(target
)) && width
!= height
) {
1972 _mesa_error(ctx
, GL_INVALID_VALUE
,
1973 "glTexImage2D(cube width != height)");
1977 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1978 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1979 _mesa_error(ctx
, GL_INVALID_VALUE
,
1980 "glTexImage3D(cube array width != height)");
1984 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1985 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1986 _mesa_error(ctx
, GL_INVALID_VALUE
,
1987 "glTexImage3D(cube array depth not multiple of 6)");
1991 /* Check internalFormat */
1992 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1993 _mesa_error(ctx
, GL_INVALID_VALUE
,
1994 "glTexImage%dD(internalFormat=%s)",
1995 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1999 /* Check incoming image format and type */
2000 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2001 if (err
!= GL_NO_ERROR
) {
2002 _mesa_error(ctx
, err
,
2003 "glTexImage%dD(incompatible format = %s, type = %s)",
2004 dimensions
, _mesa_lookup_enum_by_nr(format
),
2005 _mesa_lookup_enum_by_nr(type
));
2009 /* make sure internal format and format basically agree */
2010 colorFormat
= _mesa_is_color_format(format
);
2011 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2012 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2013 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2014 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2015 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2016 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2017 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2018 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2019 _mesa_lookup_enum_by_nr(format
));
2023 /* additional checks for ycbcr textures */
2024 if (internalFormat
== GL_YCBCR_MESA
) {
2025 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2026 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2027 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2029 _mesa_snprintf(message
, sizeof(message
),
2030 "glTexImage%dD(format/type YCBCR mismatch)",
2032 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2033 return GL_TRUE
; /* error */
2035 if (target
!= GL_TEXTURE_2D
&&
2036 target
!= GL_PROXY_TEXTURE_2D
&&
2037 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2038 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2039 _mesa_error(ctx
, GL_INVALID_ENUM
,
2040 "glTexImage%dD(bad target for YCbCr texture)",
2046 _mesa_snprintf(message
, sizeof(message
),
2047 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2048 dimensions
, border
);
2049 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2054 /* additional checks for depth textures */
2055 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2056 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2057 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2058 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2059 if (target
!= GL_TEXTURE_1D
&&
2060 target
!= GL_PROXY_TEXTURE_1D
&&
2061 target
!= GL_TEXTURE_2D
&&
2062 target
!= GL_PROXY_TEXTURE_2D
&&
2063 target
!= GL_TEXTURE_1D_ARRAY
&&
2064 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2065 target
!= GL_TEXTURE_2D_ARRAY
&&
2066 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2067 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2068 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2069 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2070 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2071 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2072 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2073 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2074 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2075 _mesa_error(ctx
, GL_INVALID_ENUM
,
2076 "glTexImage%dD(bad target for depth texture)",
2082 /* additional checks for compressed textures */
2083 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2084 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2085 _mesa_error(ctx
, GL_INVALID_ENUM
,
2086 "glTexImage%dD(target can't be compressed)", dimensions
);
2089 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2090 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2091 "glTexImage%dD(no compression for format)", dimensions
);
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "glTexImage%dD(border!=0)", dimensions
);
2101 /* additional checks for integer textures */
2102 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2103 (_mesa_is_enum_format_integer(format
) !=
2104 _mesa_is_enum_format_integer(internalFormat
))) {
2105 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2106 "glTexImage%dD(integer/non-integer format mismatch)",
2111 if (!mutable_tex_object(ctx
, target
)) {
2112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2113 "glTexImage%dD(immutable texture)", dimensions
);
2117 /* if we get here, the parameters are OK */
2123 * Error checking for glCompressedTexImage[123]D().
2124 * Note that the width, height and depth values are not fully error checked
2126 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2129 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2130 GLenum target
, GLint level
,
2131 GLenum internalFormat
, GLsizei width
,
2132 GLsizei height
, GLsizei depth
, GLint border
,
2135 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2137 GLenum error
= GL_NO_ERROR
;
2138 char *reason
= ""; /* no error */
2140 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2142 error
= GL_INVALID_ENUM
;
2146 /* This will detect any invalid internalFormat value */
2147 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2148 reason
= "internalFormat";
2149 error
= GL_INVALID_ENUM
;
2153 switch (internalFormat
) {
2154 case GL_PALETTE4_RGB8_OES
:
2155 case GL_PALETTE4_RGBA8_OES
:
2156 case GL_PALETTE4_R5_G6_B5_OES
:
2157 case GL_PALETTE4_RGBA4_OES
:
2158 case GL_PALETTE4_RGB5_A1_OES
:
2159 case GL_PALETTE8_RGB8_OES
:
2160 case GL_PALETTE8_RGBA8_OES
:
2161 case GL_PALETTE8_R5_G6_B5_OES
:
2162 case GL_PALETTE8_RGBA4_OES
:
2163 case GL_PALETTE8_RGB5_A1_OES
:
2164 /* check level (note that level should be zero or less!) */
2165 if (level
> 0 || level
< -maxLevels
) {
2167 error
= GL_INVALID_VALUE
;
2171 if (dimensions
!= 2) {
2172 reason
= "compressed paletted textures must be 2D";
2173 error
= GL_INVALID_OPERATION
;
2177 /* Figure out the expected texture size (in bytes). This will be
2178 * checked against the actual size later.
2180 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2183 /* This is for the benefit of the TestProxyTexImage below. It expects
2184 * level to be non-negative. OES_compressed_paletted_texture uses a
2185 * weird mechanism where the level specified to glCompressedTexImage2D
2186 * is -(n-1) number of levels in the texture, and the data specifies the
2187 * complete mipmap stack. This is done to ensure the palette is the
2188 * same for all levels.
2195 if (level
< 0 || level
>= maxLevels
) {
2197 error
= GL_INVALID_VALUE
;
2201 /* Figure out the expected texture size (in bytes). This will be
2202 * checked against the actual size later.
2204 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2208 /* This should really never fail */
2209 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2210 reason
= "internalFormat";
2211 error
= GL_INVALID_ENUM
;
2215 /* No compressed formats support borders at this time */
2217 reason
= "border != 0";
2218 error
= GL_INVALID_VALUE
;
2222 /* For cube map, width must equal height */
2223 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2224 _mesa_is_cube_face(target
)) && width
!= height
) {
2225 reason
= "width != height";
2226 error
= GL_INVALID_VALUE
;
2230 /* check image size in bytes */
2231 if (expectedSize
!= imageSize
) {
2232 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2233 * if <imageSize> is not consistent with the format, dimensions, and
2234 * contents of the specified image.
2236 reason
= "imageSize inconsistant with width/height/format";
2237 error
= GL_INVALID_VALUE
;
2241 if (!mutable_tex_object(ctx
, target
)) {
2242 reason
= "immutable texture";
2243 error
= GL_INVALID_OPERATION
;
2250 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2257 * Test glTexSubImage[123]D() parameters for errors.
2259 * \param ctx GL context.
2260 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2261 * \param target texture target given by the user (already validated)
2262 * \param level image level given by the user.
2263 * \param xoffset sub-image x offset given by the user.
2264 * \param yoffset sub-image y offset given by the user.
2265 * \param zoffset sub-image z offset given by the user.
2266 * \param format pixel data format given by the user.
2267 * \param type pixel data type given by the user.
2268 * \param width image width given by the user.
2269 * \param height image height given by the user.
2270 * \param depth image depth given by the user.
2272 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2274 * Verifies each of the parameters against the constants specified in
2275 * __struct gl_contextRec::Const and the supported extensions, and according
2276 * to the OpenGL specification.
2279 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2280 GLenum target
, GLint level
,
2281 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2282 GLint width
, GLint height
, GLint depth
,
2283 GLenum format
, GLenum type
)
2285 struct gl_texture_object
*texObj
;
2286 struct gl_texture_image
*texImage
;
2289 /* check target (proxies not allowed) */
2290 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2291 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2292 dimensions
, _mesa_lookup_enum_by_nr(target
));
2297 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2298 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2303 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2304 * combinations of format and type that can be used. Formats and types
2305 * that require additional extensions (e.g., GL_FLOAT requires
2306 * GL_OES_texture_float) are filtered elsewhere.
2308 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2309 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2310 if (err
!= GL_NO_ERROR
) {
2311 _mesa_error(ctx
, err
,
2312 "glTexSubImage%dD(format = %s, type = %s)",
2314 _mesa_lookup_enum_by_nr(format
),
2315 _mesa_lookup_enum_by_nr(type
));
2320 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2321 if (err
!= GL_NO_ERROR
) {
2322 _mesa_error(ctx
, err
,
2323 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2324 dimensions
, _mesa_lookup_enum_by_nr(format
),
2325 _mesa_lookup_enum_by_nr(type
));
2329 /* Get dest texture object / image pointers */
2330 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2332 /* must be out of memory */
2333 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2337 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2339 /* non-existant texture level */
2340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2341 "glTexSubImage%dD(invalid texture image)", dimensions
);
2345 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2346 texImage
, xoffset
, yoffset
, 0,
2347 width
, height
, 1)) {
2351 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2352 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2353 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2354 "glTexSubImage%dD(no compression for format)", dimensions
);
2359 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2360 /* both source and dest must be integer-valued, or neither */
2361 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2362 _mesa_is_enum_format_integer(format
)) {
2363 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2364 "glTexSubImage%dD(integer/non-integer format mismatch)",
2375 * Test glCopyTexImage[12]D() parameters for errors.
2377 * \param ctx GL context.
2378 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2379 * \param target texture target given by the user.
2380 * \param level image level given by the user.
2381 * \param internalFormat internal format given by the user.
2382 * \param width image width given by the user.
2383 * \param height image height given by the user.
2384 * \param border texture border.
2386 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2388 * Verifies each of the parameters against the constants specified in
2389 * __struct gl_contextRec::Const and the supported extensions, and according
2390 * to the OpenGL specification.
2393 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2394 GLenum target
, GLint level
, GLint internalFormat
,
2395 GLint width
, GLint height
, GLint border
)
2398 GLint rb_base_format
;
2399 struct gl_renderbuffer
*rb
;
2400 GLenum rb_internal_format
;
2403 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2404 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2405 dimensions
, _mesa_lookup_enum_by_nr(target
));
2410 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2411 _mesa_error(ctx
, GL_INVALID_VALUE
,
2412 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2416 /* Check that the source buffer is complete */
2417 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2418 if (ctx
->ReadBuffer
->_Status
== 0) {
2419 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2421 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2422 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2423 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2427 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2429 "glCopyTexImage%dD(multisample FBO)",
2436 if (border
< 0 || border
> 1 ||
2437 ((ctx
->API
!= API_OPENGL_COMPAT
||
2438 target
== GL_TEXTURE_RECTANGLE_NV
||
2439 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2440 _mesa_error(ctx
, GL_INVALID_VALUE
,
2441 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2445 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2447 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2448 "glCopyTexImage%dD(read buffer)", dimensions
);
2452 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2455 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2456 switch (internalFormat
) {
2461 case GL_LUMINANCE_ALPHA
:
2464 _mesa_error(ctx
, GL_INVALID_VALUE
,
2465 "glCopyTexImage%dD(internalFormat)", dimensions
);
2470 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2471 if (baseFormat
< 0) {
2472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2473 "glCopyTexImage%dD(internalFormat)", dimensions
);
2477 rb_internal_format
= rb
->InternalFormat
;
2478 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2479 if (_mesa_is_color_format(internalFormat
)) {
2480 if (rb_base_format
< 0) {
2481 _mesa_error(ctx
, GL_INVALID_VALUE
,
2482 "glCopyTexImage%dD(internalFormat)", dimensions
);
2487 if (_mesa_is_gles(ctx
)) {
2489 if (_mesa_base_format_component_count(baseFormat
) >
2490 _mesa_base_format_component_count(rb_base_format
)) {
2493 if (baseFormat
== GL_DEPTH_COMPONENT
||
2494 baseFormat
== GL_DEPTH_STENCIL
||
2495 rb_base_format
== GL_DEPTH_COMPONENT
||
2496 rb_base_format
== GL_DEPTH_STENCIL
||
2497 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2498 baseFormat
== GL_ALPHA
) &&
2499 rb_base_format
!= GL_RGBA
) ||
2500 internalFormat
== GL_RGB9_E5
) {
2503 if (internalFormat
== GL_RGB9_E5
) {
2507 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2508 "glCopyTexImage%dD(internalFormat)", dimensions
);
2513 if (_mesa_is_gles3(ctx
)) {
2514 bool rb_is_srgb
= false;
2515 bool dst_is_srgb
= false;
2517 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2518 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2522 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2526 if (rb_is_srgb
!= dst_is_srgb
) {
2527 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2528 * OpenGLES 3.0.0 spec says:
2530 * "The error INVALID_OPERATION is also generated if the
2531 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2532 * framebuffer attachment corresponding to the read buffer
2533 * is LINEAR (see section 6.1.13) and internalformat is
2534 * one of the sRGB formats described in section 3.8.16, or
2535 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2536 * SRGB and internalformat is not one of the sRGB formats."
2538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2539 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2544 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2545 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2546 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2550 /* From the EXT_texture_integer spec:
2552 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2553 * if the texture internalformat is an integer format and the read color
2554 * buffer is not an integer format, or if the internalformat is not an
2555 * integer format and the read color buffer is an integer format."
2557 if (_mesa_is_color_format(internalFormat
)) {
2558 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2559 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2560 if (is_int
|| is_rbint
) {
2561 if (is_int
!= is_rbint
) {
2562 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2563 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2565 } else if (_mesa_is_gles(ctx
) &&
2566 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2567 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2568 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2569 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2575 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2576 _mesa_is_cube_face(target
)) && width
!= height
) {
2577 _mesa_error(ctx
, GL_INVALID_VALUE
,
2578 "glTexImage2D(cube width != height)");
2582 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2583 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2584 _mesa_error(ctx
, GL_INVALID_ENUM
,
2585 "glCopyTexImage%dD(target)", dimensions
);
2588 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2590 "glCopyTexImage%dD(no compression for format)", dimensions
);
2594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2595 "glCopyTexImage%dD(border!=0)", dimensions
);
2600 if (!mutable_tex_object(ctx
, target
)) {
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glCopyTexImage%dD(immutable texture)", dimensions
);
2606 /* if we get here, the parameters are OK */
2612 * Test glCopyTexSubImage[12]D() parameters for errors.
2613 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2616 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2617 GLenum target
, GLint level
,
2618 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2619 GLint width
, GLint height
)
2621 struct gl_texture_object
*texObj
;
2622 struct gl_texture_image
*texImage
;
2624 /* Check that the source buffer is complete */
2625 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2626 if (ctx
->ReadBuffer
->_Status
== 0) {
2627 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2629 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2630 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2631 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2635 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2637 "glCopyTexSubImage%dD(multisample FBO)",
2643 /* check target (proxies not allowed) */
2644 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2645 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2646 dimensions
, _mesa_lookup_enum_by_nr(target
));
2651 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2652 _mesa_error(ctx
, GL_INVALID_VALUE
,
2653 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2657 /* Get dest texture object / image pointers */
2658 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2660 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2664 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2666 /* destination image does not exist */
2667 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2668 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2672 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2673 dimensions
, texImage
,
2674 xoffset
, yoffset
, zoffset
,
2675 width
, height
, 1)) {
2679 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2680 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2682 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2687 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2688 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2692 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2693 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2694 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2695 dimensions
, texImage
->_BaseFormat
);
2699 /* From the EXT_texture_integer spec:
2701 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2702 * if the texture internalformat is an integer format and the read color
2703 * buffer is not an integer format, or if the internalformat is not an
2704 * integer format and the read color buffer is an integer format."
2706 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2707 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2709 if (_mesa_is_format_integer_color(rb
->Format
) !=
2710 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2712 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2717 /* if we get here, the parameters are OK */
2722 /** Callback info for walking over FBO hash table */
2725 struct gl_context
*ctx
;
2726 struct gl_texture_object
*texObj
;
2732 * Check render to texture callback. Called from _mesa_HashWalk().
2735 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2737 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2738 const struct cb_info
*info
= (struct cb_info
*) userData
;
2739 struct gl_context
*ctx
= info
->ctx
;
2740 const struct gl_texture_object
*texObj
= info
->texObj
;
2741 const GLuint level
= info
->level
, face
= info
->face
;
2743 /* If this is a user-created FBO */
2744 if (_mesa_is_user_fbo(fb
)) {
2746 /* check if any of the FBO's attachments point to 'texObj' */
2747 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2748 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2749 if (att
->Type
== GL_TEXTURE
&&
2750 att
->Texture
== texObj
&&
2751 att
->TextureLevel
== level
&&
2752 att
->CubeMapFace
== face
) {
2753 ASSERT(_mesa_get_attachment_teximage(att
));
2754 /* Tell driver about the new renderbuffer texture */
2755 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2756 /* Mark fb status as indeterminate to force re-validation */
2765 * When a texture image is specified we have to check if it's bound to
2766 * any framebuffer objects (render to texture) in order to detect changes
2767 * in size or format since that effects FBO completeness.
2768 * Any FBOs rendering into the texture must be re-validated.
2771 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2772 struct gl_texture_object
*texObj
,
2773 GLuint face
, GLuint level
)
2775 /* Only check this texture if it's been marked as RenderToTexture */
2776 if (texObj
->_RenderToTexture
) {
2777 struct cb_info info
;
2779 info
.texObj
= texObj
;
2782 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2788 * If the texture object's GenerateMipmap flag is set and we've
2789 * changed the texture base level image, regenerate the rest of the
2790 * mipmap levels now.
2793 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2794 struct gl_texture_object
*texObj
, GLint level
)
2796 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2797 if (texObj
->GenerateMipmap
&&
2798 level
== texObj
->BaseLevel
&&
2799 level
< texObj
->MaxLevel
) {
2800 ASSERT(ctx
->Driver
.GenerateMipmap
);
2801 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2806 /** Debug helper: override the user-requested internal format */
2808 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2811 if (internalFormat
== GL_RGBA16F_ARB
||
2812 internalFormat
== GL_RGBA32F_ARB
) {
2813 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2816 else if (internalFormat
== GL_RGB16F_ARB
||
2817 internalFormat
== GL_RGB32F_ARB
) {
2818 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2821 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2822 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2823 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2824 return GL_LUMINANCE_ALPHA
;
2826 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2827 internalFormat
== GL_LUMINANCE32F_ARB
) {
2828 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2829 return GL_LUMINANCE
;
2831 else if (internalFormat
== GL_ALPHA16F_ARB
||
2832 internalFormat
== GL_ALPHA32F_ARB
) {
2833 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2837 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2838 internalFormat = GL_RGBA;
2842 return internalFormat
;
2845 return internalFormat
;
2851 * Choose the actual hardware format for a texture image.
2852 * Try to use the same format as the previous image level when possible.
2853 * Otherwise, ask the driver for the best format.
2854 * It's important to try to choose a consistant format for all levels
2855 * for efficient texture memory layout/allocation. In particular, this
2856 * comes up during automatic mipmap generation.
2859 _mesa_choose_texture_format(struct gl_context
*ctx
,
2860 struct gl_texture_object
*texObj
,
2861 GLenum target
, GLint level
,
2862 GLenum internalFormat
, GLenum format
, GLenum type
)
2866 /* see if we've already chosen a format for the previous level */
2868 struct gl_texture_image
*prevImage
=
2869 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2870 /* See if the prev level is defined and has an internal format which
2871 * matches the new internal format.
2874 prevImage
->Width
> 0 &&
2875 prevImage
->InternalFormat
== internalFormat
) {
2876 /* use the same format */
2877 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2878 return prevImage
->TexFormat
;
2882 /* If the application requested compression to an S3TC format but we don't
2883 * have the DTXn library, force a generic compressed format instead.
2885 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2886 const GLenum before
= internalFormat
;
2888 switch (internalFormat
) {
2889 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2890 if (!ctx
->Mesa_DXTn
)
2891 internalFormat
= GL_COMPRESSED_RGB
;
2893 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2894 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2895 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2896 if (!ctx
->Mesa_DXTn
)
2897 internalFormat
= GL_COMPRESSED_RGBA
;
2903 if (before
!= internalFormat
) {
2905 "DXT compression requested (%s), "
2906 "but libtxc_dxtn library not installed. Using %s "
2908 _mesa_lookup_enum_by_nr(before
),
2909 _mesa_lookup_enum_by_nr(internalFormat
));
2913 /* choose format from scratch */
2914 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2916 ASSERT(f
!= MESA_FORMAT_NONE
);
2921 * Adjust pixel unpack params and image dimensions to strip off the
2922 * one-pixel texture border.
2924 * Gallium and intel don't support texture borders. They've seldem been used
2925 * and seldom been implemented correctly anyway.
2927 * \param unpackNew returns the new pixel unpack parameters
2930 strip_texture_border(GLenum target
,
2931 GLint
*width
, GLint
*height
, GLint
*depth
,
2932 const struct gl_pixelstore_attrib
*unpack
,
2933 struct gl_pixelstore_attrib
*unpackNew
)
2939 *unpackNew
= *unpack
;
2941 if (unpackNew
->RowLength
== 0)
2942 unpackNew
->RowLength
= *width
;
2944 if (unpackNew
->ImageHeight
== 0)
2945 unpackNew
->ImageHeight
= *height
;
2947 assert(*width
>= 3);
2948 unpackNew
->SkipPixels
++; /* skip the border */
2949 *width
= *width
- 2; /* reduce the width by two border pixels */
2951 /* The min height of a texture with a border is 3 */
2952 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2953 unpackNew
->SkipRows
++; /* skip the border */
2954 *height
= *height
- 2; /* reduce the height by two border pixels */
2957 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2958 unpackNew
->SkipImages
++; /* skip the border */
2959 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2965 * Common code to implement all the glTexImage1D/2D/3D functions
2966 * as well as glCompressedTexImage1D/2D/3D.
2967 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2968 * \param format the user's image format (only used if !compressed)
2969 * \param type the user's image type (only used if !compressed)
2970 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2973 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2974 GLenum target
, GLint level
, GLint internalFormat
,
2975 GLsizei width
, GLsizei height
, GLsizei depth
,
2976 GLint border
, GLenum format
, GLenum type
,
2977 GLsizei imageSize
, const GLvoid
*pixels
)
2979 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2980 struct gl_pixelstore_attrib unpack_no_border
;
2981 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2982 struct gl_texture_object
*texObj
;
2983 gl_format texFormat
;
2984 GLboolean dimensionsOK
, sizeOK
;
2986 FLUSH_VERTICES(ctx
, 0);
2988 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2991 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2993 _mesa_lookup_enum_by_nr(target
), level
,
2994 _mesa_lookup_enum_by_nr(internalFormat
),
2995 width
, height
, depth
, border
, pixels
);
2998 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3000 _mesa_lookup_enum_by_nr(target
), level
,
3001 _mesa_lookup_enum_by_nr(internalFormat
),
3002 width
, height
, depth
, border
,
3003 _mesa_lookup_enum_by_nr(format
),
3004 _mesa_lookup_enum_by_nr(type
), pixels
);
3007 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3009 /* target error checking */
3010 if (!legal_teximage_target(ctx
, dims
, target
)) {
3011 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3012 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3016 /* general error checking */
3018 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3020 width
, height
, depth
,
3025 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3026 format
, type
, width
, height
, depth
, border
))
3030 /* Here we convert a cpal compressed image into a regular glTexImage2D
3031 * call by decompressing the texture. If we really want to support cpal
3032 * textures in any driver this would have to be changed.
3034 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3035 switch (internalFormat
) {
3036 case GL_PALETTE4_RGB8_OES
:
3037 case GL_PALETTE4_RGBA8_OES
:
3038 case GL_PALETTE4_R5_G6_B5_OES
:
3039 case GL_PALETTE4_RGBA4_OES
:
3040 case GL_PALETTE4_RGB5_A1_OES
:
3041 case GL_PALETTE8_RGB8_OES
:
3042 case GL_PALETTE8_RGBA8_OES
:
3043 case GL_PALETTE8_R5_G6_B5_OES
:
3044 case GL_PALETTE8_RGBA4_OES
:
3045 case GL_PALETTE8_RGB5_A1_OES
:
3046 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3047 width
, height
, imageSize
, pixels
);
3052 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3056 /* For glCompressedTexImage() the driver has no choice about the
3057 * texture format since we'll never transcode the user's compressed
3058 * image data. The internalFormat was error checked earlier.
3060 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3063 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3064 internalFormat
, format
, type
);
3067 assert(texFormat
!= MESA_FORMAT_NONE
);
3069 /* check that width, height, depth are legal for the mipmap level */
3070 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3071 height
, depth
, border
);
3073 /* check that the texture won't take too much memory, etc */
3074 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3076 width
, height
, depth
, border
);
3078 if (_mesa_is_proxy_texture(target
)) {
3079 /* Proxy texture: just clear or set state depending on error checking */
3080 struct gl_texture_image
*texImage
=
3081 get_proxy_tex_image(ctx
, target
, level
);
3084 return; /* GL_OUT_OF_MEMORY already recorded */
3086 if (dimensionsOK
&& sizeOK
) {
3087 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3088 border
, internalFormat
, texFormat
);
3091 clear_teximage_fields(texImage
);
3095 /* non-proxy target */
3096 const GLuint face
= _mesa_tex_target_to_face(target
);
3097 struct gl_texture_image
*texImage
;
3099 if (!dimensionsOK
) {
3100 _mesa_error(ctx
, GL_INVALID_VALUE
,
3101 "glTexImage%uD(invalid width or height or depth)",
3107 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3108 "glTexImage%uD(image too large)", dims
);
3112 /* Allow a hardware driver to just strip out the border, to provide
3113 * reliable but slightly incorrect hardware rendering instead of
3114 * rarely-tested software fallback rendering.
3116 if (border
&& ctx
->Const
.StripTextureBorder
) {
3117 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3120 unpack
= &unpack_no_border
;
3123 if (ctx
->NewState
& _NEW_PIXEL
)
3124 _mesa_update_state(ctx
);
3126 _mesa_lock_texture(ctx
, texObj
);
3128 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3131 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3134 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3136 _mesa_init_teximage_fields(ctx
, texImage
,
3137 width
, height
, depth
,
3138 border
, internalFormat
, texFormat
);
3140 /* Give the texture to the driver. <pixels> may be null. */
3141 if (width
> 0 && height
> 0 && depth
> 0) {
3143 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3147 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3148 type
, pixels
, unpack
);
3152 check_gen_mipmap(ctx
, target
, texObj
, level
);
3154 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3156 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3159 _mesa_unlock_texture(ctx
, texObj
);
3166 * Called from the API. Note that width includes the border.
3169 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3170 GLsizei width
, GLint border
, GLenum format
,
3171 GLenum type
, const GLvoid
*pixels
)
3173 GET_CURRENT_CONTEXT(ctx
);
3174 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3175 border
, format
, type
, 0, pixels
);
3180 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3181 GLsizei width
, GLsizei height
, GLint border
,
3182 GLenum format
, GLenum type
,
3183 const GLvoid
*pixels
)
3185 GET_CURRENT_CONTEXT(ctx
);
3186 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3187 border
, format
, type
, 0, pixels
);
3192 * Called by the API or display list executor.
3193 * Note that width and height include the border.
3196 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3197 GLsizei width
, GLsizei height
, GLsizei depth
,
3198 GLint border
, GLenum format
, GLenum type
,
3199 const GLvoid
*pixels
)
3201 GET_CURRENT_CONTEXT(ctx
);
3202 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3203 width
, height
, depth
,
3204 border
, format
, type
, 0, pixels
);
3209 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3210 GLsizei width
, GLsizei height
, GLsizei depth
,
3211 GLint border
, GLenum format
, GLenum type
,
3212 const GLvoid
*pixels
)
3214 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3215 depth
, border
, format
, type
, pixels
);
3220 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3222 struct gl_texture_object
*texObj
;
3223 struct gl_texture_image
*texImage
;
3225 GET_CURRENT_CONTEXT(ctx
);
3226 FLUSH_VERTICES(ctx
, 0);
3230 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3232 case GL_TEXTURE_EXTERNAL_OES
:
3233 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3236 valid_target
= false;
3240 if (!valid_target
) {
3241 _mesa_error(ctx
, GL_INVALID_ENUM
,
3242 "glEGLImageTargetTexture2D(target=%d)", target
);
3247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3248 "glEGLImageTargetTexture2D(image=%p)", image
);
3252 if (ctx
->NewState
& _NEW_PIXEL
)
3253 _mesa_update_state(ctx
);
3255 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3256 _mesa_lock_texture(ctx
, texObj
);
3258 if (texObj
->Immutable
) {
3259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3260 "glEGLImageTargetTexture2D(texture is immutable)");
3261 _mesa_unlock_texture(ctx
, texObj
);
3265 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3267 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3269 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3271 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3272 texObj
, texImage
, image
);
3274 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3276 _mesa_unlock_texture(ctx
, texObj
);
3283 * Implement all the glTexSubImage1/2/3D() functions.
3286 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3287 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3288 GLsizei width
, GLsizei height
, GLsizei depth
,
3289 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3291 struct gl_texture_object
*texObj
;
3292 struct gl_texture_image
*texImage
;
3294 FLUSH_VERTICES(ctx
, 0);
3296 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3297 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3299 _mesa_lookup_enum_by_nr(target
), level
,
3300 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3301 _mesa_lookup_enum_by_nr(format
),
3302 _mesa_lookup_enum_by_nr(type
), pixels
);
3304 /* check target (proxies not allowed) */
3305 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3306 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3307 dims
, _mesa_lookup_enum_by_nr(target
));
3311 if (ctx
->NewState
& _NEW_PIXEL
)
3312 _mesa_update_state(ctx
);
3314 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3315 xoffset
, yoffset
, zoffset
,
3316 width
, height
, depth
, format
, type
)) {
3317 return; /* error was detected */
3320 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3322 _mesa_lock_texture(ctx
, texObj
);
3324 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3326 if (width
> 0 && height
> 0 && depth
> 0) {
3327 /* If we have a border, offset=-1 is legal. Bias by border width. */
3330 if (target
!= GL_TEXTURE_2D_ARRAY
)
3331 zoffset
+= texImage
->Border
;
3334 if (target
!= GL_TEXTURE_1D_ARRAY
)
3335 yoffset
+= texImage
->Border
;
3338 xoffset
+= texImage
->Border
;
3341 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3342 xoffset
, yoffset
, zoffset
,
3343 width
, height
, depth
,
3344 format
, type
, pixels
, &ctx
->Unpack
);
3346 check_gen_mipmap(ctx
, target
, texObj
, level
);
3348 ctx
->NewState
|= _NEW_TEXTURE
;
3351 _mesa_unlock_texture(ctx
, texObj
);
3356 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3357 GLint xoffset
, GLsizei width
,
3358 GLenum format
, GLenum type
,
3359 const GLvoid
*pixels
)
3361 GET_CURRENT_CONTEXT(ctx
);
3362 texsubimage(ctx
, 1, target
, level
,
3365 format
, type
, pixels
);
3370 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3371 GLint xoffset
, GLint yoffset
,
3372 GLsizei width
, GLsizei height
,
3373 GLenum format
, GLenum type
,
3374 const GLvoid
*pixels
)
3376 GET_CURRENT_CONTEXT(ctx
);
3377 texsubimage(ctx
, 2, target
, level
,
3378 xoffset
, yoffset
, 0,
3380 format
, type
, pixels
);
3386 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3387 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3388 GLsizei width
, GLsizei height
, GLsizei depth
,
3389 GLenum format
, GLenum type
,
3390 const GLvoid
*pixels
)
3392 GET_CURRENT_CONTEXT(ctx
);
3393 texsubimage(ctx
, 3, target
, level
,
3394 xoffset
, yoffset
, zoffset
,
3395 width
, height
, depth
,
3396 format
, type
, pixels
);
3402 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3403 * from. This depends on whether the texture contains color or depth values.
3405 static struct gl_renderbuffer
*
3406 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3408 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3409 /* reading from depth/stencil buffer */
3410 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3413 /* copying from color buffer */
3414 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3421 * Implement the glCopyTexImage1/2D() functions.
3424 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3425 GLenum target
, GLint level
, GLenum internalFormat
,
3426 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3428 struct gl_texture_object
*texObj
;
3429 struct gl_texture_image
*texImage
;
3430 const GLuint face
= _mesa_tex_target_to_face(target
);
3431 gl_format texFormat
;
3433 FLUSH_VERTICES(ctx
, 0);
3435 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3436 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3438 _mesa_lookup_enum_by_nr(target
), level
,
3439 _mesa_lookup_enum_by_nr(internalFormat
),
3440 x
, y
, width
, height
, border
);
3442 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3443 _mesa_update_state(ctx
);
3445 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3446 width
, height
, border
))
3449 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3451 _mesa_error(ctx
, GL_INVALID_VALUE
,
3452 "glCopyTexImage%uD(invalid width or height)", dims
);
3456 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3459 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3460 internalFormat
, GL_NONE
, GL_NONE
);
3461 assert(texFormat
!= MESA_FORMAT_NONE
);
3463 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3465 width
, height
, 1, border
)) {
3466 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3467 "glCopyTexImage%uD(image too large)", dims
);
3471 if (border
&& ctx
->Const
.StripTextureBorder
) {
3473 width
-= border
* 2;
3476 height
-= border
* 2;
3481 _mesa_lock_texture(ctx
, texObj
);
3483 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3486 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3489 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3491 /* Free old texture image */
3492 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3494 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3495 border
, internalFormat
, texFormat
);
3497 /* Allocate texture memory (no pixel data yet) */
3498 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3500 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3502 struct gl_renderbuffer
*srcRb
=
3503 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3505 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3506 srcRb
, srcX
, srcY
, width
, height
);
3509 check_gen_mipmap(ctx
, target
, texObj
, level
);
3511 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3513 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3516 _mesa_unlock_texture(ctx
, texObj
);
3522 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3523 GLenum internalFormat
,
3525 GLsizei width
, GLint border
)
3527 GET_CURRENT_CONTEXT(ctx
);
3528 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3534 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3535 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3538 GET_CURRENT_CONTEXT(ctx
);
3539 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3540 x
, y
, width
, height
, border
);
3546 * Implementation for glCopyTexSubImage1/2/3D() functions.
3549 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3550 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3551 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3553 struct gl_texture_object
*texObj
;
3554 struct gl_texture_image
*texImage
;
3556 FLUSH_VERTICES(ctx
, 0);
3558 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3559 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3561 _mesa_lookup_enum_by_nr(target
),
3562 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3564 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3565 _mesa_update_state(ctx
);
3567 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3568 xoffset
, yoffset
, zoffset
, width
, height
)) {
3572 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3574 _mesa_lock_texture(ctx
, texObj
);
3576 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3578 /* If we have a border, offset=-1 is legal. Bias by border width. */
3581 if (target
!= GL_TEXTURE_2D_ARRAY
)
3582 zoffset
+= texImage
->Border
;
3585 if (target
!= GL_TEXTURE_1D_ARRAY
)
3586 yoffset
+= texImage
->Border
;
3589 xoffset
+= texImage
->Border
;
3592 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3594 struct gl_renderbuffer
*srcRb
=
3595 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3597 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3598 xoffset
, yoffset
, zoffset
,
3599 srcRb
, x
, y
, width
, height
);
3601 check_gen_mipmap(ctx
, target
, texObj
, level
);
3603 ctx
->NewState
|= _NEW_TEXTURE
;
3606 _mesa_unlock_texture(ctx
, texObj
);
3611 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3612 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3614 GET_CURRENT_CONTEXT(ctx
);
3615 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3621 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3622 GLint xoffset
, GLint yoffset
,
3623 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3625 GET_CURRENT_CONTEXT(ctx
);
3626 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3633 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3634 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3635 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3637 GET_CURRENT_CONTEXT(ctx
);
3638 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3639 x
, y
, width
, height
);
3645 /**********************************************************************/
3646 /****** Compressed Textures ******/
3647 /**********************************************************************/
3651 * Error checking for glCompressedTexSubImage[123]D().
3652 * \return error code or GL_NO_ERROR.
3655 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3656 GLenum target
, GLint level
,
3657 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3658 GLsizei width
, GLsizei height
, GLsizei depth
,
3659 GLenum format
, GLsizei imageSize
)
3661 struct gl_texture_object
*texObj
;
3662 struct gl_texture_image
*texImage
;
3670 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3671 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3672 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3673 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3674 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3675 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3679 targetOK
= GL_FALSE
;
3684 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3688 /* no 1D compressed textures at this time */
3689 targetOK
= GL_FALSE
;
3694 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3699 /* this will catch any invalid compressed format token */
3700 if (!_mesa_is_compressed_format(ctx
, format
)) {
3701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3706 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3707 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3712 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3713 if (expectedSize
!= imageSize
) {
3714 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3719 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3721 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3722 "glCompressedTexSubImage%uD()", dims
);
3726 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3729 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3733 if ((GLint
) format
!= texImage
->InternalFormat
) {
3734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3735 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3739 if (compressedteximage_only_format(ctx
, format
)) {
3740 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3741 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3746 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3747 texImage
, xoffset
, yoffset
, zoffset
,
3748 width
, height
, depth
)) {
3757 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3758 GLenum internalFormat
, GLsizei width
,
3759 GLint border
, GLsizei imageSize
,
3762 GET_CURRENT_CONTEXT(ctx
);
3763 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3764 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3769 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3770 GLenum internalFormat
, GLsizei width
,
3771 GLsizei height
, GLint border
, GLsizei imageSize
,
3774 GET_CURRENT_CONTEXT(ctx
);
3775 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3776 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3781 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3782 GLenum internalFormat
, GLsizei width
,
3783 GLsizei height
, GLsizei depth
, GLint border
,
3784 GLsizei imageSize
, const GLvoid
*data
)
3786 GET_CURRENT_CONTEXT(ctx
);
3787 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3788 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3793 * Common helper for glCompressedTexSubImage1/2/3D().
3796 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3797 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3798 GLsizei width
, GLsizei height
, GLsizei depth
,
3799 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3801 struct gl_texture_object
*texObj
;
3802 struct gl_texture_image
*texImage
;
3803 GET_CURRENT_CONTEXT(ctx
);
3804 FLUSH_VERTICES(ctx
, 0);
3806 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3807 xoffset
, yoffset
, zoffset
,
3808 width
, height
, depth
,
3809 format
, imageSize
)) {
3813 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3815 _mesa_lock_texture(ctx
, texObj
);
3817 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3820 if (width
> 0 && height
> 0 && depth
> 0) {
3821 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3822 xoffset
, yoffset
, zoffset
,
3823 width
, height
, depth
,
3824 format
, imageSize
, data
);
3826 check_gen_mipmap(ctx
, target
, texObj
, level
);
3828 ctx
->NewState
|= _NEW_TEXTURE
;
3831 _mesa_unlock_texture(ctx
, texObj
);
3836 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3837 GLsizei width
, GLenum format
,
3838 GLsizei imageSize
, const GLvoid
*data
)
3840 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3841 format
, imageSize
, data
);
3846 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3847 GLint yoffset
, GLsizei width
, GLsizei height
,
3848 GLenum format
, GLsizei imageSize
,
3851 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3852 width
, height
, 1, format
, imageSize
, data
);
3857 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3858 GLint yoffset
, GLint zoffset
, GLsizei width
,
3859 GLsizei height
, GLsizei depth
, GLenum format
,
3860 GLsizei imageSize
, const GLvoid
*data
)
3862 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3863 width
, height
, depth
, format
, imageSize
, data
);
3867 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3869 switch (internalFormat
) {
3871 return MESA_FORMAT_A8
;
3873 return MESA_FORMAT_A16
;
3874 case GL_ALPHA16F_ARB
:
3875 return MESA_FORMAT_ALPHA_FLOAT16
;
3876 case GL_ALPHA32F_ARB
:
3877 return MESA_FORMAT_ALPHA_FLOAT32
;
3878 case GL_ALPHA8I_EXT
:
3879 return MESA_FORMAT_ALPHA_INT8
;
3880 case GL_ALPHA16I_EXT
:
3881 return MESA_FORMAT_ALPHA_INT16
;
3882 case GL_ALPHA32I_EXT
:
3883 return MESA_FORMAT_ALPHA_INT32
;
3884 case GL_ALPHA8UI_EXT
:
3885 return MESA_FORMAT_ALPHA_UINT8
;
3886 case GL_ALPHA16UI_EXT
:
3887 return MESA_FORMAT_ALPHA_UINT16
;
3888 case GL_ALPHA32UI_EXT
:
3889 return MESA_FORMAT_ALPHA_UINT32
;
3891 return MESA_FORMAT_L8
;
3892 case GL_LUMINANCE16
:
3893 return MESA_FORMAT_L16
;
3894 case GL_LUMINANCE16F_ARB
:
3895 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3896 case GL_LUMINANCE32F_ARB
:
3897 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3898 case GL_LUMINANCE8I_EXT
:
3899 return MESA_FORMAT_LUMINANCE_INT8
;
3900 case GL_LUMINANCE16I_EXT
:
3901 return MESA_FORMAT_LUMINANCE_INT16
;
3902 case GL_LUMINANCE32I_EXT
:
3903 return MESA_FORMAT_LUMINANCE_INT32
;
3904 case GL_LUMINANCE8UI_EXT
:
3905 return MESA_FORMAT_LUMINANCE_UINT8
;
3906 case GL_LUMINANCE16UI_EXT
:
3907 return MESA_FORMAT_LUMINANCE_UINT16
;
3908 case GL_LUMINANCE32UI_EXT
:
3909 return MESA_FORMAT_LUMINANCE_UINT32
;
3910 case GL_LUMINANCE8_ALPHA8
:
3911 return MESA_FORMAT_AL88
;
3912 case GL_LUMINANCE16_ALPHA16
:
3913 return MESA_FORMAT_AL1616
;
3914 case GL_LUMINANCE_ALPHA16F_ARB
:
3915 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3916 case GL_LUMINANCE_ALPHA32F_ARB
:
3917 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3918 case GL_LUMINANCE_ALPHA8I_EXT
:
3919 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3920 case GL_LUMINANCE_ALPHA16I_EXT
:
3921 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3922 case GL_LUMINANCE_ALPHA32I_EXT
:
3923 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3924 case GL_LUMINANCE_ALPHA8UI_EXT
:
3925 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3926 case GL_LUMINANCE_ALPHA16UI_EXT
:
3927 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3928 case GL_LUMINANCE_ALPHA32UI_EXT
:
3929 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3931 return MESA_FORMAT_I8
;
3932 case GL_INTENSITY16
:
3933 return MESA_FORMAT_I16
;
3934 case GL_INTENSITY16F_ARB
:
3935 return MESA_FORMAT_INTENSITY_FLOAT16
;
3936 case GL_INTENSITY32F_ARB
:
3937 return MESA_FORMAT_INTENSITY_FLOAT32
;
3938 case GL_INTENSITY8I_EXT
:
3939 return MESA_FORMAT_INTENSITY_INT8
;
3940 case GL_INTENSITY16I_EXT
:
3941 return MESA_FORMAT_INTENSITY_INT16
;
3942 case GL_INTENSITY32I_EXT
:
3943 return MESA_FORMAT_INTENSITY_INT32
;
3944 case GL_INTENSITY8UI_EXT
:
3945 return MESA_FORMAT_INTENSITY_UINT8
;
3946 case GL_INTENSITY16UI_EXT
:
3947 return MESA_FORMAT_INTENSITY_UINT16
;
3948 case GL_INTENSITY32UI_EXT
:
3949 return MESA_FORMAT_INTENSITY_UINT32
;
3951 return MESA_FORMAT_RGBA8888_REV
;
3953 return MESA_FORMAT_RGBA_16
;
3954 case GL_RGBA16F_ARB
:
3955 return MESA_FORMAT_RGBA_FLOAT16
;
3956 case GL_RGBA32F_ARB
:
3957 return MESA_FORMAT_RGBA_FLOAT32
;
3959 return MESA_FORMAT_RGBA_INT8
;
3960 case GL_RGBA16I_EXT
:
3961 return MESA_FORMAT_RGBA_INT16
;
3962 case GL_RGBA32I_EXT
:
3963 return MESA_FORMAT_RGBA_INT32
;
3964 case GL_RGBA8UI_EXT
:
3965 return MESA_FORMAT_RGBA_UINT8
;
3966 case GL_RGBA16UI_EXT
:
3967 return MESA_FORMAT_RGBA_UINT16
;
3968 case GL_RGBA32UI_EXT
:
3969 return MESA_FORMAT_RGBA_UINT32
;
3972 return MESA_FORMAT_GR88
;
3974 return MESA_FORMAT_GR1616
;
3976 return MESA_FORMAT_RG_FLOAT16
;
3978 return MESA_FORMAT_RG_FLOAT32
;
3980 return MESA_FORMAT_RG_INT8
;
3982 return MESA_FORMAT_RG_INT16
;
3984 return MESA_FORMAT_RG_INT32
;
3986 return MESA_FORMAT_RG_UINT8
;
3988 return MESA_FORMAT_RG_UINT16
;
3990 return MESA_FORMAT_RG_UINT32
;
3993 return MESA_FORMAT_R8
;
3995 return MESA_FORMAT_R16
;
3997 return MESA_FORMAT_R_FLOAT16
;
3999 return MESA_FORMAT_R_FLOAT32
;
4001 return MESA_FORMAT_R_INT8
;
4003 return MESA_FORMAT_R_INT16
;
4005 return MESA_FORMAT_R_INT32
;
4007 return MESA_FORMAT_R_UINT8
;
4009 return MESA_FORMAT_R_UINT16
;
4011 return MESA_FORMAT_R_UINT32
;
4014 return MESA_FORMAT_RGB_FLOAT32
;
4016 return MESA_FORMAT_RGB_UINT32
;
4018 return MESA_FORMAT_RGB_INT32
;
4021 return MESA_FORMAT_NONE
;
4026 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4028 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4031 if (format
== MESA_FORMAT_NONE
)
4032 return MESA_FORMAT_NONE
;
4034 datatype
= _mesa_get_format_datatype(format
);
4035 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4036 return MESA_FORMAT_NONE
;
4038 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4039 return MESA_FORMAT_NONE
;
4041 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4042 * any mention of R/RG formats, but they appear in the GL 3.1 core
4045 if (ctx
->Version
<= 30) {
4046 GLenum base_format
= _mesa_get_format_base_format(format
);
4048 if (base_format
== GL_R
|| base_format
== GL_RG
)
4049 return MESA_FORMAT_NONE
;
4052 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4053 GLenum base_format
= _mesa_get_format_base_format(format
);
4054 if (base_format
== GL_RGB
)
4055 return MESA_FORMAT_NONE
;
4062 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4063 struct gl_buffer_object
*bufObj
,
4064 GLintptr offset
, GLsizeiptr size
)
4066 struct gl_texture_object
*texObj
;
4069 FLUSH_VERTICES(ctx
, 0);
4071 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4072 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4076 format
= validate_texbuffer_format(ctx
, internalFormat
);
4077 if (format
== MESA_FORMAT_NONE
) {
4078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4083 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4085 _mesa_lock_texture(ctx
, texObj
);
4087 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4088 texObj
->BufferObjectFormat
= internalFormat
;
4089 texObj
->_BufferObjectFormat
= format
;
4090 texObj
->BufferOffset
= offset
;
4091 texObj
->BufferSize
= size
;
4093 _mesa_unlock_texture(ctx
, texObj
);
4096 /** GL_ARB_texture_buffer_object */
4098 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4100 struct gl_buffer_object
*bufObj
;
4102 GET_CURRENT_CONTEXT(ctx
);
4104 /* NOTE: ARB_texture_buffer_object has interactions with
4105 * the compatibility profile that are not implemented.
4107 if (!(ctx
->API
== API_OPENGL_CORE
&&
4108 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4109 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4113 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4114 if (!bufObj
&& buffer
) {
4115 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4119 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4122 /** GL_ARB_texture_buffer_range */
4124 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4125 GLintptr offset
, GLsizeiptr size
)
4127 struct gl_buffer_object
*bufObj
;
4129 GET_CURRENT_CONTEXT(ctx
);
4131 if (!(ctx
->API
== API_OPENGL_CORE
&&
4132 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4133 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4137 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4141 (offset
+ size
) > bufObj
->Size
) {
4142 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4145 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4146 _mesa_error(ctx
, GL_INVALID_VALUE
,
4147 "glTexBufferRange(invalid offset alignment)");
4150 } else if (buffer
) {
4151 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4159 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4163 /** GL_ARB_texture_multisample */
4165 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4166 GLint internalformat
, GLsizei width
,
4167 GLsizei height
, GLboolean fixedsamplelocations
)
4169 assert(!"Not implemented");
4170 /* allocate a single 2d multisample texture */
4174 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4175 GLint internalformat
, GLsizei width
,
4176 GLsizei height
, GLsizei depth
,
4177 GLboolean fixedsamplelocations
)
4179 assert(!"Not implemented");
4180 /* allocate an array of 2d multisample textures */