2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
44 #include "multisample.h"
45 #include "pixelstore.h"
47 #include "texcompress.h"
48 #include "texcompress_cpal.h"
52 #include "texstorage.h"
53 #include "textureview.h"
55 #include "glformats.h"
61 * State changes which we care about for glCopyTex[Sub]Image() calls.
62 * In particular, we care about pixel transfer state and buffer state
63 * (such as glReadBuffer to make sure we read from the right renderbuffer).
65 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
68 * Returns a corresponding internal floating point format for a given base
69 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
70 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
71 * needs to be a 16 bit component.
73 * For example, given base format GL_RGBA, type GL_FLOAT return GL_RGBA32F_ARB.
76 adjust_for_oes_float_texture(const struct gl_context
*ctx
,
77 GLenum format
, GLenum type
)
81 if (ctx
->Extensions
.OES_texture_float
) {
88 return GL_ALPHA32F_ARB
;
90 return GL_LUMINANCE32F_ARB
;
91 case GL_LUMINANCE_ALPHA
:
92 return GL_LUMINANCE_ALPHA32F_ARB
;
99 case GL_HALF_FLOAT_OES
:
100 if (ctx
->Extensions
.OES_texture_half_float
) {
107 return GL_ALPHA16F_ARB
;
109 return GL_LUMINANCE16F_ARB
;
110 case GL_LUMINANCE_ALPHA
:
111 return GL_LUMINANCE_ALPHA16F_ARB
;
127 * Install gl_texture_image in a gl_texture_object according to the target
128 * and level parameters.
130 * \param tObj texture object.
131 * \param target texture target.
132 * \param level image level.
133 * \param texImage texture image.
136 set_tex_image(struct gl_texture_object
*tObj
,
137 GLenum target
, GLint level
,
138 struct gl_texture_image
*texImage
)
140 const GLuint face
= _mesa_tex_target_to_face(target
);
144 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
147 tObj
->Image
[face
][level
] = texImage
;
149 /* Set the 'back' pointer */
150 texImage
->TexObject
= tObj
;
151 texImage
->Level
= level
;
152 texImage
->Face
= face
;
157 * Allocate a texture image structure.
159 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
162 * \return a pointer to gl_texture_image struct with all fields initialized to
165 struct gl_texture_image
*
166 _mesa_new_texture_image( struct gl_context
*ctx
)
169 return CALLOC_STRUCT(gl_texture_image
);
174 * Free a gl_texture_image and associated data.
175 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
177 * \param texImage texture image.
179 * Free the texture image structure and the associated image data.
182 _mesa_delete_texture_image(struct gl_context
*ctx
,
183 struct gl_texture_image
*texImage
)
185 /* Free texImage->Data and/or any other driver-specific texture
188 assert(ctx
->Driver
.FreeTextureImageBuffer
);
189 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
195 * Test if a target is a proxy target.
197 * \param target texture target.
199 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
202 _mesa_is_proxy_texture(GLenum target
)
205 static const GLenum targets
[] = {
209 GL_PROXY_TEXTURE_CUBE_MAP
,
210 GL_PROXY_TEXTURE_RECTANGLE
,
211 GL_PROXY_TEXTURE_1D_ARRAY
,
212 GL_PROXY_TEXTURE_2D_ARRAY
,
213 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
214 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
215 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
218 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
219 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
221 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
223 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
224 if (target
== targets
[i
])
231 * Test if a target is an array target.
233 * \param target texture target.
235 * \return true if the target is an array target, false otherwise.
238 _mesa_is_array_texture(GLenum target
)
241 case GL_TEXTURE_1D_ARRAY
:
242 case GL_TEXTURE_2D_ARRAY
:
243 case GL_TEXTURE_CUBE_MAP_ARRAY
:
244 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
252 * Test if a target is a cube map.
254 * \param target texture target.
256 * \return true if the target is a cube map, false otherwise.
259 _mesa_is_cube_map_texture(GLenum target
)
262 case GL_TEXTURE_CUBE_MAP
:
263 case GL_TEXTURE_CUBE_MAP_ARRAY
:
271 * Return the proxy target which corresponds to the given texture target
274 proxy_target(GLenum target
)
278 case GL_PROXY_TEXTURE_1D
:
279 return GL_PROXY_TEXTURE_1D
;
281 case GL_PROXY_TEXTURE_2D
:
282 return GL_PROXY_TEXTURE_2D
;
284 case GL_PROXY_TEXTURE_3D
:
285 return GL_PROXY_TEXTURE_3D
;
286 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
287 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
288 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
289 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
290 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
291 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
292 case GL_TEXTURE_CUBE_MAP
:
293 case GL_PROXY_TEXTURE_CUBE_MAP
:
294 return GL_PROXY_TEXTURE_CUBE_MAP
;
295 case GL_TEXTURE_RECTANGLE_NV
:
296 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
297 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
298 case GL_TEXTURE_1D_ARRAY_EXT
:
299 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
300 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
301 case GL_TEXTURE_2D_ARRAY_EXT
:
302 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
303 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
304 case GL_TEXTURE_CUBE_MAP_ARRAY
:
305 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
306 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
307 case GL_TEXTURE_2D_MULTISAMPLE
:
308 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
309 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
310 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
311 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
312 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
314 _mesa_problem(NULL
, "unexpected target in proxy_target()");
323 * Get a texture image pointer from a texture object, given a texture
324 * target and mipmap level. The target and level parameters should
325 * have already been error-checked.
327 * \param texObj texture unit.
328 * \param target texture target.
329 * \param level image level.
331 * \return pointer to the texture image structure, or NULL on failure.
333 struct gl_texture_image
*
334 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
335 GLenum target
, GLint level
)
337 const GLuint face
= _mesa_tex_target_to_face(target
);
341 assert(level
< MAX_TEXTURE_LEVELS
);
343 return texObj
->Image
[face
][level
];
348 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
349 * it and install it. Only return NULL if passed a bad parameter or run
352 struct gl_texture_image
*
353 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
354 GLenum target
, GLint level
)
356 struct gl_texture_image
*texImage
;
361 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
363 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
365 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
369 set_tex_image(texObj
, target
, level
, texImage
);
377 * Return pointer to the specified proxy texture image.
378 * Note that proxy textures are per-context, not per-texture unit.
379 * \return pointer to texture image or NULL if invalid target, invalid
380 * level, or out of memory.
382 static struct gl_texture_image
*
383 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
385 struct gl_texture_image
*texImage
;
392 case GL_PROXY_TEXTURE_1D
:
393 if (level
>= ctx
->Const
.MaxTextureLevels
)
395 texIndex
= TEXTURE_1D_INDEX
;
397 case GL_PROXY_TEXTURE_2D
:
398 if (level
>= ctx
->Const
.MaxTextureLevels
)
400 texIndex
= TEXTURE_2D_INDEX
;
402 case GL_PROXY_TEXTURE_3D
:
403 if (level
>= ctx
->Const
.Max3DTextureLevels
)
405 texIndex
= TEXTURE_3D_INDEX
;
407 case GL_PROXY_TEXTURE_CUBE_MAP
:
408 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
410 texIndex
= TEXTURE_CUBE_INDEX
;
412 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
415 texIndex
= TEXTURE_RECT_INDEX
;
417 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
418 if (level
>= ctx
->Const
.MaxTextureLevels
)
420 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
422 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
423 if (level
>= ctx
->Const
.MaxTextureLevels
)
425 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
427 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
428 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
430 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
432 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
435 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
437 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
440 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
446 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
448 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
450 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
453 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
454 /* Set the 'back' pointer */
455 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
462 * Get the maximum number of allowed mipmap levels.
464 * \param ctx GL context.
465 * \param target texture target.
467 * \return the maximum number of allowed mipmap levels for the given
468 * texture target, or zero if passed a bad target.
473 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
477 case GL_PROXY_TEXTURE_1D
:
479 case GL_PROXY_TEXTURE_2D
:
480 return ctx
->Const
.MaxTextureLevels
;
482 case GL_PROXY_TEXTURE_3D
:
483 return ctx
->Const
.Max3DTextureLevels
;
484 case GL_TEXTURE_CUBE_MAP
:
485 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
486 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
487 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
488 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
489 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
490 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
491 case GL_PROXY_TEXTURE_CUBE_MAP
:
492 return ctx
->Extensions
.ARB_texture_cube_map
493 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
494 case GL_TEXTURE_RECTANGLE_NV
:
495 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
496 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
497 case GL_TEXTURE_1D_ARRAY_EXT
:
498 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
499 case GL_TEXTURE_2D_ARRAY_EXT
:
500 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
501 return ctx
->Extensions
.EXT_texture_array
502 ? ctx
->Const
.MaxTextureLevels
: 0;
503 case GL_TEXTURE_CUBE_MAP_ARRAY
:
504 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
505 return _mesa_has_texture_cube_map_array(ctx
)
506 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
507 case GL_TEXTURE_BUFFER
:
508 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
509 _mesa_has_OES_texture_buffer(ctx
)) ? 1 : 0;
510 case GL_TEXTURE_2D_MULTISAMPLE
:
511 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
512 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
513 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
514 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
515 && ctx
->Extensions
.ARB_texture_multisample
517 case GL_TEXTURE_EXTERNAL_OES
:
520 return 0; /* bad target */
526 * Return number of dimensions per mipmap level for the given texture target.
529 _mesa_get_texture_dimensions(GLenum target
)
533 case GL_PROXY_TEXTURE_1D
:
536 case GL_TEXTURE_RECTANGLE
:
537 case GL_TEXTURE_CUBE_MAP
:
538 case GL_PROXY_TEXTURE_2D
:
539 case GL_PROXY_TEXTURE_RECTANGLE
:
540 case GL_PROXY_TEXTURE_CUBE_MAP
:
541 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
542 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
543 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
544 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
545 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
546 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
547 case GL_TEXTURE_1D_ARRAY
:
548 case GL_PROXY_TEXTURE_1D_ARRAY
:
549 case GL_TEXTURE_EXTERNAL_OES
:
550 case GL_TEXTURE_2D_MULTISAMPLE
:
551 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
554 case GL_PROXY_TEXTURE_3D
:
555 case GL_TEXTURE_2D_ARRAY
:
556 case GL_PROXY_TEXTURE_2D_ARRAY
:
557 case GL_TEXTURE_CUBE_MAP_ARRAY
:
558 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
559 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
560 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
562 case GL_TEXTURE_BUFFER
:
565 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
573 * Check if a texture target can have more than one layer.
576 _mesa_tex_target_is_layered(GLenum target
)
580 case GL_PROXY_TEXTURE_1D
:
582 case GL_PROXY_TEXTURE_2D
:
583 case GL_TEXTURE_RECTANGLE
:
584 case GL_PROXY_TEXTURE_RECTANGLE
:
585 case GL_TEXTURE_2D_MULTISAMPLE
:
586 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
587 case GL_TEXTURE_BUFFER
:
588 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
589 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
590 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
591 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
592 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
593 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
594 case GL_TEXTURE_EXTERNAL_OES
:
598 case GL_PROXY_TEXTURE_3D
:
599 case GL_TEXTURE_CUBE_MAP
:
600 case GL_PROXY_TEXTURE_CUBE_MAP
:
601 case GL_TEXTURE_1D_ARRAY
:
602 case GL_PROXY_TEXTURE_1D_ARRAY
:
603 case GL_TEXTURE_2D_ARRAY
:
604 case GL_PROXY_TEXTURE_2D_ARRAY
:
605 case GL_TEXTURE_CUBE_MAP_ARRAY
:
606 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
607 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
608 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
612 assert(!"Invalid texture target.");
619 * Return the number of layers present in the given level of an array,
620 * cubemap or 3D texture. If the texture is not layered return zero.
623 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
625 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
627 switch (texObj
->Target
) {
630 case GL_TEXTURE_RECTANGLE
:
631 case GL_TEXTURE_2D_MULTISAMPLE
:
632 case GL_TEXTURE_BUFFER
:
633 case GL_TEXTURE_EXTERNAL_OES
:
636 case GL_TEXTURE_CUBE_MAP
:
639 case GL_TEXTURE_1D_ARRAY
: {
640 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
641 return img
? img
->Height
: 0;
645 case GL_TEXTURE_2D_ARRAY
:
646 case GL_TEXTURE_CUBE_MAP_ARRAY
:
647 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
648 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
649 return img
? img
->Depth
: 0;
653 assert(!"Invalid texture target.");
660 * Return the maximum number of mipmap levels for the given target
661 * and the dimensions.
662 * The dimensions are expected not to include the border.
665 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
672 case GL_TEXTURE_1D_ARRAY
:
673 case GL_PROXY_TEXTURE_1D
:
674 case GL_PROXY_TEXTURE_1D_ARRAY
:
677 case GL_TEXTURE_CUBE_MAP
:
678 case GL_TEXTURE_CUBE_MAP_ARRAY
:
679 case GL_PROXY_TEXTURE_CUBE_MAP
:
680 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
684 case GL_TEXTURE_2D_ARRAY
:
685 case GL_PROXY_TEXTURE_2D
:
686 case GL_PROXY_TEXTURE_2D_ARRAY
:
687 size
= MAX2(width
, height
);
690 case GL_PROXY_TEXTURE_3D
:
691 size
= MAX3(width
, height
, depth
);
693 case GL_TEXTURE_RECTANGLE
:
694 case GL_TEXTURE_EXTERNAL_OES
:
695 case GL_TEXTURE_2D_MULTISAMPLE
:
696 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
697 case GL_PROXY_TEXTURE_RECTANGLE
:
698 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
699 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
706 return _mesa_logbase2(size
) + 1;
710 #if 000 /* not used anymore */
712 * glTexImage[123]D can accept a NULL image pointer. In this case we
713 * create a texture image with unspecified image contents per the OpenGL
717 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
719 const GLint components
= _mesa_components_in_format(format
);
720 const GLint numPixels
= width
* height
* depth
;
721 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
725 * Let's see if anyone finds this. If glTexImage2D() is called with
726 * a NULL image pointer then load the texture image with something
727 * interesting instead of leaving it indeterminate.
730 static const char message
[8][32] = {
734 " X X XXXX XXX XXXXX ",
737 " X X XXXXX XXX X X ",
741 GLubyte
*imgPtr
= data
;
743 for (h
= 0; h
< depth
; h
++) {
744 for (i
= 0; i
< height
; i
++) {
745 GLint srcRow
= 7 - (i
% 8);
746 for (j
= 0; j
< width
; j
++) {
747 GLint srcCol
= j
% 32;
748 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
749 for (k
= 0; k
< components
; k
++) {
765 * Set the size and format-related fields of a gl_texture_image struct
766 * to zero. This is used when a proxy texture test fails.
769 clear_teximage_fields(struct gl_texture_image
*img
)
772 img
->_BaseFormat
= 0;
773 img
->InternalFormat
= 0;
784 img
->TexFormat
= MESA_FORMAT_NONE
;
786 img
->FixedSampleLocations
= GL_TRUE
;
791 * Initialize basic fields of the gl_texture_image struct.
793 * \param ctx GL context.
794 * \param img texture image structure to be initialized.
795 * \param width image width.
796 * \param height image height.
797 * \param depth image depth.
798 * \param border image border.
799 * \param internalFormat internal format.
800 * \param format the actual hardware format (one of MESA_FORMAT_*)
801 * \param numSamples number of samples per texel, or zero for non-MS.
802 * \param fixedSampleLocations are sample locations fixed?
804 * Fills in the fields of \p img with the given information.
805 * Note: width, height and depth include the border.
808 init_teximage_fields_ms(struct gl_context
*ctx
,
809 struct gl_texture_image
*img
,
810 GLsizei width
, GLsizei height
, GLsizei depth
,
811 GLint border
, GLenum internalFormat
,
813 GLuint numSamples
, GLboolean fixedSampleLocations
)
821 target
= img
->TexObject
->Target
;
822 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
823 assert(img
->_BaseFormat
!= -1);
824 img
->InternalFormat
= internalFormat
;
825 img
->Border
= border
;
827 img
->Height
= height
;
830 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
831 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
834 img
->FixedSampleLocations
= GL_TRUE
;
838 case GL_TEXTURE_BUFFER
:
839 case GL_PROXY_TEXTURE_1D
:
851 case GL_TEXTURE_1D_ARRAY
:
852 case GL_PROXY_TEXTURE_1D_ARRAY
:
853 img
->Height2
= height
; /* no border */
854 img
->HeightLog2
= 0; /* not used */
862 case GL_TEXTURE_RECTANGLE
:
863 case GL_TEXTURE_CUBE_MAP
:
864 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
865 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
866 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
867 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
868 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
869 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
870 case GL_TEXTURE_EXTERNAL_OES
:
871 case GL_PROXY_TEXTURE_2D
:
872 case GL_PROXY_TEXTURE_RECTANGLE
:
873 case GL_PROXY_TEXTURE_CUBE_MAP
:
874 case GL_TEXTURE_2D_MULTISAMPLE
:
875 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
876 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
877 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
884 case GL_TEXTURE_2D_ARRAY
:
885 case GL_PROXY_TEXTURE_2D_ARRAY
:
886 case GL_TEXTURE_CUBE_MAP_ARRAY
:
887 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
888 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
889 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
890 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
891 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
892 img
->Depth2
= depth
; /* no border */
893 img
->DepthLog2
= 0; /* not used */
896 case GL_PROXY_TEXTURE_3D
:
897 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
898 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
899 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
900 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
903 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
908 _mesa_get_tex_max_num_levels(target
,
909 img
->Width2
, img
->Height2
, img
->Depth2
);
910 img
->TexFormat
= format
;
911 img
->NumSamples
= numSamples
;
912 img
->FixedSampleLocations
= fixedSampleLocations
;
917 _mesa_init_teximage_fields(struct gl_context
*ctx
,
918 struct gl_texture_image
*img
,
919 GLsizei width
, GLsizei height
, GLsizei depth
,
920 GLint border
, GLenum internalFormat
,
923 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
924 internalFormat
, format
, 0, GL_TRUE
);
929 * Free and clear fields of the gl_texture_image struct.
931 * \param ctx GL context.
932 * \param texImage texture image structure to be cleared.
934 * After the call, \p texImage will have no data associated with it. Its
935 * fields are cleared so that its parent object will test incomplete.
938 _mesa_clear_texture_image(struct gl_context
*ctx
,
939 struct gl_texture_image
*texImage
)
941 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
942 clear_teximage_fields(texImage
);
947 * Check the width, height, depth and border of a texture image are legal.
948 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
950 * The target and level parameters will have already been validated.
951 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
954 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
955 GLint level
, GLint width
, GLint height
,
956 GLint depth
, GLint border
)
962 case GL_PROXY_TEXTURE_1D
:
963 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
964 maxSize
>>= level
; /* level size */
965 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
967 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
968 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
974 case GL_PROXY_TEXTURE_2D
:
975 case GL_TEXTURE_2D_MULTISAMPLE
:
976 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
977 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
979 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
981 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
983 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
984 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
986 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
992 case GL_PROXY_TEXTURE_3D
:
993 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
995 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
997 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
999 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1001 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1002 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1004 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1006 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1011 case GL_TEXTURE_RECTANGLE_NV
:
1012 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1015 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1016 if (width
< 0 || width
> maxSize
)
1018 if (height
< 0 || height
> maxSize
)
1022 case GL_TEXTURE_CUBE_MAP
:
1023 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1024 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1025 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1026 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1027 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1028 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1029 case GL_PROXY_TEXTURE_CUBE_MAP
:
1030 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1032 if (width
!= height
)
1034 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1036 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1038 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1039 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1041 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1046 case GL_TEXTURE_1D_ARRAY_EXT
:
1047 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1048 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1050 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1052 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1054 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1055 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1060 case GL_TEXTURE_2D_ARRAY_EXT
:
1061 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1062 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1063 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1064 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1066 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1068 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1070 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1072 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1073 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1075 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1080 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1081 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1082 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1083 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1085 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1087 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1089 if (width
!= height
)
1091 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1093 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1094 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1096 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1101 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1107 error_check_subtexture_negative_dimensions(struct gl_context
*ctx
,
1116 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width=%d)", func
, subWidth
);
1120 if (dims
> 1 && subHeight
< 0) {
1121 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height=%d)", func
, subHeight
);
1125 if (dims
> 2 && subDepth
< 0) {
1126 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(depth=%d)", func
, subDepth
);
1134 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1135 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1136 * \param destImage the destination texture image.
1137 * \return GL_TRUE if error found, GL_FALSE otherwise.
1140 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1141 const struct gl_texture_image
*destImage
,
1142 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1143 GLsizei subWidth
, GLsizei subHeight
,
1144 GLsizei subDepth
, const char *func
)
1146 const GLenum target
= destImage
->TexObject
->Target
;
1149 /* check xoffset and width */
1150 if (xoffset
< - (GLint
) destImage
->Border
) {
1151 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1155 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1156 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1160 /* check yoffset and height */
1162 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1163 if (yoffset
< -yBorder
) {
1164 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1167 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1168 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1173 /* check zoffset and depth */
1176 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1177 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1178 0 : destImage
->Border
;
1180 if (zoffset
< -zBorder
) {
1181 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1185 depth
= (GLint
) destImage
->Depth
;
1186 if (target
== GL_TEXTURE_CUBE_MAP
)
1188 if (zoffset
+ subDepth
> depth
) {
1189 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1195 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1196 * compressed texture images can be updated. But, that restriction may be
1197 * relaxed for particular compressed formats. At this time, all the
1198 * compressed formats supported by Mesa allow sub-textures to be updated
1199 * along compressed block boundaries.
1201 _mesa_get_format_block_size_3d(destImage
->TexFormat
, &bw
, &bh
, &bd
);
1203 if (bw
!= 1 || bh
!= 1 || bd
!= 1) {
1204 /* offset must be multiple of block size */
1205 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0) || (zoffset
% bd
!= 0)) {
1206 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1207 "%s(xoffset = %d, yoffset = %d, zoffset = %d)",
1208 func
, xoffset
, yoffset
, zoffset
);
1212 /* The size must be a multiple of bw x bh, or we must be using a
1213 * offset+size that exactly hits the edge of the image. This
1214 * is important for small mipmap levels (1x1, 2x1, etc) and for
1217 if ((subWidth
% bw
!= 0) &&
1218 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1219 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1220 "%s(width = %d)", func
, subWidth
);
1224 if ((subHeight
% bh
!= 0) &&
1225 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1226 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1227 "%s(height = %d)", func
, subHeight
);
1231 if ((subDepth
% bd
!= 0) &&
1232 (zoffset
+ subDepth
!= (GLint
) destImage
->Depth
)) {
1233 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1234 "%s(depth = %d)", func
, subDepth
);
1246 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1247 * specific texture image size checks.
1249 * A hardware driver might override this function if, for example, the
1250 * max 3D texture size is 512x512x64 (i.e. not a cube).
1252 * Note that width, height, depth == 0 is not an error. However, a
1253 * texture with zero width/height/depth will be considered "incomplete"
1254 * and texturing will effectively be disabled.
1256 * \param target any texture target/type
1257 * \param numLevels number of mipmap levels in the texture or 0 if not known
1258 * \param level as passed to glTexImage
1259 * \param format the MESA_FORMAT_x for the tex image
1260 * \param numSamples number of samples per texel
1261 * \param width as passed to glTexImage
1262 * \param height as passed to glTexImage
1263 * \param depth as passed to glTexImage
1264 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1267 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
1268 GLuint numLevels
, GLint level
,
1269 mesa_format format
, GLuint numSamples
,
1270 GLint width
, GLint height
, GLint depth
)
1272 uint64_t bytes
, mbytes
;
1274 if (numLevels
> 0) {
1275 /* Compute total memory for a whole mipmap. This is the path
1276 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1284 for (l
= 0; l
< numLevels
; l
++) {
1285 GLint nextWidth
, nextHeight
, nextDepth
;
1287 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1289 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1290 &nextWidth
, &nextHeight
,
1293 height
= nextHeight
;
1300 /* We just compute the size of one mipmap level. This is the path
1301 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1303 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1306 bytes
*= _mesa_num_tex_faces(target
);
1307 bytes
*= MAX2(1, numSamples
);
1309 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1311 /* We just check if the image size is less than MaxTextureMbytes.
1312 * Some drivers may do more specific checks.
1314 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1319 * Return true if the format is only valid for glCompressedTexImage.
1322 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1325 case GL_PALETTE4_RGB8_OES
:
1326 case GL_PALETTE4_RGBA8_OES
:
1327 case GL_PALETTE4_R5_G6_B5_OES
:
1328 case GL_PALETTE4_RGBA4_OES
:
1329 case GL_PALETTE4_RGB5_A1_OES
:
1330 case GL_PALETTE8_RGB8_OES
:
1331 case GL_PALETTE8_RGBA8_OES
:
1332 case GL_PALETTE8_R5_G6_B5_OES
:
1333 case GL_PALETTE8_RGBA4_OES
:
1334 case GL_PALETTE8_RGB5_A1_OES
:
1342 * Return true if the format doesn't support online compression.
1345 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1347 return _mesa_is_astc_format(format
) ||
1348 _mesa_is_etc2_format(format
) ||
1349 compressedteximage_only_format(ctx
, format
);
1352 /* Writes to an GL error pointer if non-null and returns whether or not the
1353 * error is GL_NO_ERROR */
1355 write_error(GLenum
*err_ptr
, GLenum error
)
1360 return error
== GL_NO_ERROR
;
1364 * Helper function to determine whether a target and specific compression
1365 * format are supported. The error parameter returns GL_NO_ERROR if the
1366 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1367 * or GL_INVALID_ENUM, whichever is more appropriate.
1370 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1371 GLenum intFormat
, GLenum
*error
)
1373 GLboolean target_can_be_compresed
= GL_FALSE
;
1374 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1375 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1379 case GL_PROXY_TEXTURE_2D
:
1380 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1382 case GL_PROXY_TEXTURE_CUBE_MAP
:
1383 case GL_TEXTURE_CUBE_MAP
:
1384 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1385 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1388 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1390 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1392 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1393 case GL_TEXTURE_2D_ARRAY_EXT
:
1394 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1396 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1397 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1398 /* From the KHR_texture_compression_astc_hdr spec:
1400 * Add a second new column "3D Tex." which is empty for all non-ASTC
1401 * formats. If only the LDR profile is supported by the
1402 * implementation, this column is also empty for all ASTC formats. If
1403 * both the LDR and HDR profiles are supported only, this column is
1404 * checked for all ASTC formats.
1406 * Add a third new column "Cube Map Array Tex." which is empty for all
1407 * non-ASTC formats, and checked for all ASTC formats.
1411 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1412 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1413 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1414 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1415 * 8.19 is *not* checked'
1417 * The instances of <internalformat> above should say <target>.
1419 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1420 * have already been handled by normal ETC2/EAC behavior.
1423 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1425 * "The ETC2/EAC texture compression algorithm supports only
1426 * two-dimensional images. If internalformat is an ETC2/EAC format,
1427 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1428 * target is not TEXTURE_2D_ARRAY."
1430 * This should also be applicable for glTexStorage3D(). Other available
1431 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1433 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1434 return write_error(error
, GL_INVALID_OPERATION
);
1435 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1439 case MESA_FORMAT_LAYOUT_ETC2
:
1440 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1441 if (_mesa_is_gles3(ctx
))
1442 return write_error(error
, GL_INVALID_OPERATION
);
1444 case MESA_FORMAT_LAYOUT_BPTC
:
1445 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1447 case MESA_FORMAT_LAYOUT_ASTC
:
1448 target_can_be_compresed
=
1449 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1450 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1452 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1453 * neither of the above extensions are supported. See comment in
1454 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1456 if (!target_can_be_compresed
)
1457 return write_error(error
, GL_INVALID_OPERATION
);
1465 return write_error(error
,
1466 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1471 * Check if the given texture target value is legal for a
1472 * glTexImage1/2/3D call.
1475 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1481 case GL_PROXY_TEXTURE_1D
:
1482 return _mesa_is_desktop_gl(ctx
);
1490 case GL_PROXY_TEXTURE_2D
:
1491 return _mesa_is_desktop_gl(ctx
);
1492 case GL_PROXY_TEXTURE_CUBE_MAP
:
1493 return _mesa_is_desktop_gl(ctx
)
1494 && ctx
->Extensions
.ARB_texture_cube_map
;
1495 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1496 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1497 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1498 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1499 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1500 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1501 return ctx
->Extensions
.ARB_texture_cube_map
;
1502 case GL_TEXTURE_RECTANGLE_NV
:
1503 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1504 return _mesa_is_desktop_gl(ctx
)
1505 && ctx
->Extensions
.NV_texture_rectangle
;
1506 case GL_TEXTURE_1D_ARRAY_EXT
:
1507 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1508 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1516 case GL_PROXY_TEXTURE_3D
:
1517 return _mesa_is_desktop_gl(ctx
);
1518 case GL_TEXTURE_2D_ARRAY_EXT
:
1519 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1520 || _mesa_is_gles3(ctx
);
1521 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1522 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1523 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1524 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1525 return _mesa_has_texture_cube_map_array(ctx
);
1530 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1537 * Check if the given texture target value is legal for a
1538 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1539 * The difference compared to legal_teximage_target() above is that
1540 * proxy targets are not supported.
1543 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1548 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1553 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1554 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1555 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1556 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1557 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1558 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1559 return ctx
->Extensions
.ARB_texture_cube_map
;
1560 case GL_TEXTURE_RECTANGLE_NV
:
1561 return _mesa_is_desktop_gl(ctx
)
1562 && ctx
->Extensions
.NV_texture_rectangle
;
1563 case GL_TEXTURE_1D_ARRAY_EXT
:
1564 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1572 case GL_TEXTURE_2D_ARRAY_EXT
:
1573 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1574 || _mesa_is_gles3(ctx
);
1575 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1576 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1577 return _mesa_has_texture_cube_map_array(ctx
);
1579 /* Table 8.15 of the OpenGL 4.5 core profile spec
1580 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1581 * and CopyTextureSubImage3D.
1583 case GL_TEXTURE_CUBE_MAP
:
1589 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1597 * Helper function to determine if a texture object is mutable (in terms
1598 * of GL_ARB_texture_storage).
1601 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1603 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1607 return !texObj
->Immutable
;
1612 * Return expected size of a compressed texture.
1615 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1618 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1619 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1623 * Verify that a texture format is valid with a particular target
1625 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1626 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1629 * \param ctx GL context
1630 * \param target Texture target
1631 * \param internalFormat Internal format of the texture image
1633 * \returns true if the combination is legal, false otherwise.
1636 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1637 GLenum target
, GLenum internalFormat
)
1639 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1640 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1641 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1642 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1643 * Profile spec says:
1645 * "Textures with a base internal format of DEPTH_COMPONENT or
1646 * DEPTH_STENCIL are supported by texture image specification
1647 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1648 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1649 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1650 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1651 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1652 * formats in conjunction with any other target will result in an
1653 * INVALID_OPERATION error."
1655 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1656 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1658 if (target
!= GL_TEXTURE_1D
&&
1659 target
!= GL_PROXY_TEXTURE_1D
&&
1660 target
!= GL_TEXTURE_2D
&&
1661 target
!= GL_PROXY_TEXTURE_2D
&&
1662 target
!= GL_TEXTURE_1D_ARRAY
&&
1663 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1664 target
!= GL_TEXTURE_2D_ARRAY
&&
1665 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1666 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1667 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1668 !((_mesa_is_cube_face(target
) ||
1669 target
== GL_TEXTURE_CUBE_MAP
||
1670 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1671 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1672 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1673 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1674 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1675 _mesa_has_texture_cube_map_array(ctx
))) {
1684 texture_formats_agree(GLenum internalFormat
,
1687 GLboolean colorFormat
;
1688 GLboolean is_format_depth_or_depthstencil
;
1689 GLboolean is_internalFormat_depth_or_depthstencil
;
1691 /* Even though there are no color-index textures, we still have to support
1692 * uploading color-index data and remapping it to RGB via the
1693 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1695 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1697 is_internalFormat_depth_or_depthstencil
=
1698 _mesa_is_depth_format(internalFormat
) ||
1699 _mesa_is_depthstencil_format(internalFormat
);
1701 is_format_depth_or_depthstencil
=
1702 _mesa_is_depth_format(format
) ||
1703 _mesa_is_depthstencil_format(format
);
1705 colorFormat
= _mesa_is_color_format(format
);
1707 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1710 if (is_internalFormat_depth_or_depthstencil
!=
1711 is_format_depth_or_depthstencil
)
1714 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1721 * Test the combination of format, type and internal format arguments of
1722 * different texture operations on GLES.
1724 * \param ctx GL context.
1725 * \param format pixel data format given by the user.
1726 * \param type pixel data type given by the user.
1727 * \param internalFormat internal format given by the user.
1728 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1729 * \param callerName name of the caller function to print in the error message
1731 * \return true if a error is found, false otherwise
1733 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1736 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1737 GLenum type
, GLenum internalFormat
,
1738 GLuint dimensions
, const char *callerName
)
1742 if (_mesa_is_gles3(ctx
)) {
1743 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
1745 if (err
!= GL_NO_ERROR
) {
1746 _mesa_error(ctx
, err
,
1747 "%s(format = %s, type = %s, internalformat = %s)",
1748 callerName
, _mesa_enum_to_string(format
),
1749 _mesa_enum_to_string(type
),
1750 _mesa_enum_to_string(internalFormat
));
1755 err
= _mesa_es_error_check_format_and_type(ctx
, format
, type
, dimensions
);
1756 if (err
!= GL_NO_ERROR
) {
1757 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
1758 callerName
, _mesa_enum_to_string(format
),
1759 _mesa_enum_to_string(type
));
1768 * Test the glTexImage[123]D() parameters for errors.
1770 * \param ctx GL context.
1771 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1772 * \param target texture target given by the user (already validated).
1773 * \param level image level given by the user.
1774 * \param internalFormat internal format given by the user.
1775 * \param format pixel data format given by the user.
1776 * \param type pixel data type given by the user.
1777 * \param width image width given by the user.
1778 * \param height image height given by the user.
1779 * \param depth image depth given by the user.
1780 * \param border image border given by the user.
1782 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1784 * Verifies each of the parameters against the constants specified in
1785 * __struct gl_contextRec::Const and the supported extensions, and according
1786 * to the OpenGL specification.
1787 * Note that we don't fully error-check the width, height, depth values
1788 * here. That's done in _mesa_legal_texture_dimensions() which is used
1789 * by several other GL entrypoints. Plus, texture dims have a special
1790 * interaction with proxy textures.
1793 texture_error_check( struct gl_context
*ctx
,
1794 GLuint dimensions
, GLenum target
,
1795 GLint level
, GLint internalFormat
,
1796 GLenum format
, GLenum type
,
1797 GLint width
, GLint height
,
1798 GLint depth
, GLint border
,
1799 const GLvoid
*pixels
)
1803 /* Note: for proxy textures, some error conditions immediately generate
1804 * a GL error in the usual way. But others do not generate a GL error.
1805 * Instead, they cause the width, height, depth, format fields of the
1806 * texture image to be zeroed-out. The GL spec seems to indicate that the
1807 * zero-out behaviour is only used in cases related to memory allocation.
1811 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1812 _mesa_error(ctx
, GL_INVALID_VALUE
,
1813 "glTexImage%dD(level=%d)", dimensions
, level
);
1818 if (border
< 0 || border
> 1 ||
1819 ((ctx
->API
!= API_OPENGL_COMPAT
||
1820 target
== GL_TEXTURE_RECTANGLE_NV
||
1821 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
,
1823 "glTexImage%dD(border=%d)", dimensions
, border
);
1827 if (width
< 0 || height
< 0 || depth
< 0) {
1828 _mesa_error(ctx
, GL_INVALID_VALUE
,
1829 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1833 /* Check incoming image format and type */
1834 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1835 if (err
!= GL_NO_ERROR
) {
1836 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1837 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1839 * "Specifying a value for internalformat that is not one of the
1840 * above (acceptable) values generates the error INVALID VALUE."
1842 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1843 err
= GL_INVALID_VALUE
;
1845 _mesa_error(ctx
, err
,
1846 "glTexImage%dD(incompatible format = %s, type = %s)",
1847 dimensions
, _mesa_enum_to_string(format
),
1848 _mesa_enum_to_string(type
));
1852 /* Check internalFormat */
1853 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1854 _mesa_error(ctx
, GL_INVALID_VALUE
,
1855 "glTexImage%dD(internalFormat=%s)",
1856 dimensions
, _mesa_enum_to_string(internalFormat
));
1860 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1861 * combinations of format, internalFormat, and type that can be used.
1862 * Formats and types that require additional extensions (e.g., GL_FLOAT
1863 * requires GL_OES_texture_float) are filtered elsewhere.
1865 if (_mesa_is_gles(ctx
) &&
1866 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
1867 dimensions
, "glTexImage%dD")) {
1871 /* validate the bound PBO, if any */
1872 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1873 width
, height
, depth
, format
, type
,
1874 INT_MAX
, pixels
, "glTexImage")) {
1878 /* make sure internal format and format basically agree */
1879 if (!texture_formats_agree(internalFormat
, format
)) {
1880 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1881 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1882 dimensions
, _mesa_enum_to_string(internalFormat
),
1883 _mesa_enum_to_string(format
));
1887 /* additional checks for ycbcr textures */
1888 if (internalFormat
== GL_YCBCR_MESA
) {
1889 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1890 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1891 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1893 _mesa_snprintf(message
, sizeof(message
),
1894 "glTexImage%dD(format/type YCBCR mismatch)",
1896 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1897 return GL_TRUE
; /* error */
1899 if (target
!= GL_TEXTURE_2D
&&
1900 target
!= GL_PROXY_TEXTURE_2D
&&
1901 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1902 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1903 _mesa_error(ctx
, GL_INVALID_ENUM
,
1904 "glTexImage%dD(bad target for YCbCr texture)",
1910 _mesa_snprintf(message
, sizeof(message
),
1911 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1912 dimensions
, border
);
1913 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1918 /* additional checks for depth textures */
1919 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1920 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1921 "glTexImage%dD(bad target for texture)", dimensions
);
1925 /* additional checks for compressed textures */
1926 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1928 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1929 _mesa_error(ctx
, err
,
1930 "glTexImage%dD(target can't be compressed)", dimensions
);
1933 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
1934 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1935 "glTexImage%dD(no compression for format)", dimensions
);
1939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1940 "glTexImage%dD(border!=0)", dimensions
);
1945 /* additional checks for integer textures */
1946 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1947 (_mesa_is_enum_format_integer(format
) !=
1948 _mesa_is_enum_format_integer(internalFormat
))) {
1949 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1950 "glTexImage%dD(integer/non-integer format mismatch)",
1955 if (!mutable_tex_object(ctx
, target
)) {
1956 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1957 "glTexImage%dD(immutable texture)", dimensions
);
1961 /* if we get here, the parameters are OK */
1967 * Error checking for glCompressedTexImage[123]D().
1968 * Note that the width, height and depth values are not fully error checked
1970 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1973 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
1974 GLenum target
, GLint level
,
1975 GLenum internalFormat
, GLsizei width
,
1976 GLsizei height
, GLsizei depth
, GLint border
,
1977 GLsizei imageSize
, const GLvoid
*data
)
1979 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1981 GLenum error
= GL_NO_ERROR
;
1982 char *reason
= ""; /* no error */
1984 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
1989 /* This will detect any invalid internalFormat value */
1990 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
1991 _mesa_error(ctx
, GL_INVALID_ENUM
,
1992 "glCompressedTexImage%dD(internalFormat=%s)",
1993 dimensions
, _mesa_enum_to_string(internalFormat
));
1997 /* validate the bound PBO, if any */
1998 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2000 "glCompressedTexImage")) {
2004 switch (internalFormat
) {
2005 case GL_PALETTE4_RGB8_OES
:
2006 case GL_PALETTE4_RGBA8_OES
:
2007 case GL_PALETTE4_R5_G6_B5_OES
:
2008 case GL_PALETTE4_RGBA4_OES
:
2009 case GL_PALETTE4_RGB5_A1_OES
:
2010 case GL_PALETTE8_RGB8_OES
:
2011 case GL_PALETTE8_RGBA8_OES
:
2012 case GL_PALETTE8_R5_G6_B5_OES
:
2013 case GL_PALETTE8_RGBA4_OES
:
2014 case GL_PALETTE8_RGB5_A1_OES
:
2015 /* check level (note that level should be zero or less!) */
2016 if (level
> 0 || level
< -maxLevels
) {
2018 error
= GL_INVALID_VALUE
;
2022 if (dimensions
!= 2) {
2023 reason
= "compressed paletted textures must be 2D";
2024 error
= GL_INVALID_OPERATION
;
2028 /* Figure out the expected texture size (in bytes). This will be
2029 * checked against the actual size later.
2031 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2034 /* This is for the benefit of the TestProxyTexImage below. It expects
2035 * level to be non-negative. OES_compressed_paletted_texture uses a
2036 * weird mechanism where the level specified to glCompressedTexImage2D
2037 * is -(n-1) number of levels in the texture, and the data specifies the
2038 * complete mipmap stack. This is done to ensure the palette is the
2039 * same for all levels.
2046 if (level
< 0 || level
>= maxLevels
) {
2048 error
= GL_INVALID_VALUE
;
2052 /* Figure out the expected texture size (in bytes). This will be
2053 * checked against the actual size later.
2055 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2059 /* This should really never fail */
2060 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2061 reason
= "internalFormat";
2062 error
= GL_INVALID_ENUM
;
2066 /* No compressed formats support borders at this time */
2068 reason
= "border != 0";
2069 error
= GL_INVALID_VALUE
;
2073 /* Check for invalid pixel storage modes */
2074 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2076 "glCompressedTexImage")) {
2080 /* check image size in bytes */
2081 if (expectedSize
!= imageSize
) {
2082 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2083 * if <imageSize> is not consistent with the format, dimensions, and
2084 * contents of the specified image.
2086 reason
= "imageSize inconsistent with width/height/format";
2087 error
= GL_INVALID_VALUE
;
2091 if (!mutable_tex_object(ctx
, target
)) {
2092 reason
= "immutable texture";
2093 error
= GL_INVALID_OPERATION
;
2100 /* Note: not all error paths exit through here. */
2101 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2102 dimensions
, reason
);
2109 * Test glTexSubImage[123]D() parameters for errors.
2111 * \param ctx GL context.
2112 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2113 * \param target texture target given by the user (already validated)
2114 * \param level image level given by the user.
2115 * \param xoffset sub-image x offset given by the user.
2116 * \param yoffset sub-image y offset given by the user.
2117 * \param zoffset sub-image z offset given by the user.
2118 * \param format pixel data format given by the user.
2119 * \param type pixel data type given by the user.
2120 * \param width image width given by the user.
2121 * \param height image height given by the user.
2122 * \param depth image depth given by the user.
2124 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2126 * Verifies each of the parameters against the constants specified in
2127 * __struct gl_contextRec::Const and the supported extensions, and according
2128 * to the OpenGL specification.
2131 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2132 struct gl_texture_object
*texObj
,
2133 GLenum target
, GLint level
,
2134 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2135 GLint width
, GLint height
, GLint depth
,
2136 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2137 bool dsa
, const char *callerName
)
2139 struct gl_texture_image
*texImage
;
2143 /* must be out of memory */
2144 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2149 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2150 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2154 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2155 width
, height
, depth
,
2160 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2162 /* non-existant texture level */
2163 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2168 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2169 if (err
!= GL_NO_ERROR
) {
2170 _mesa_error(ctx
, err
,
2171 "%s(incompatible format = %s, type = %s)",
2172 callerName
, _mesa_enum_to_string(format
),
2173 _mesa_enum_to_string(type
));
2177 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2178 * combinations of format, internalFormat, and type that can be used.
2179 * Formats and types that require additional extensions (e.g., GL_FLOAT
2180 * requires GL_OES_texture_float) are filtered elsewhere.
2182 if (_mesa_is_gles(ctx
) &&
2183 texture_format_error_check_gles(ctx
, format
, type
,
2184 texImage
->InternalFormat
,
2185 dimensions
, callerName
)) {
2189 /* validate the bound PBO, if any */
2190 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2191 width
, height
, depth
, format
, type
,
2192 INT_MAX
, pixels
, callerName
)) {
2196 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2197 texImage
, xoffset
, yoffset
, zoffset
,
2198 width
, height
, depth
, callerName
)) {
2202 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2203 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2205 "%s(no compression for format)", callerName
);
2210 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2211 /* both source and dest must be integer-valued, or neither */
2212 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2213 _mesa_is_enum_format_integer(format
)) {
2214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2215 "%s(integer/non-integer format mismatch)", callerName
);
2225 * Test glCopyTexImage[12]D() parameters for errors.
2227 * \param ctx GL context.
2228 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2229 * \param target texture target given by the user.
2230 * \param level image level given by the user.
2231 * \param internalFormat internal format given by the user.
2232 * \param width image width given by the user.
2233 * \param height image height given by the user.
2234 * \param border texture border.
2236 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2238 * Verifies each of the parameters against the constants specified in
2239 * __struct gl_contextRec::Const and the supported extensions, and according
2240 * to the OpenGL specification.
2243 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2244 GLenum target
, GLint level
, GLint internalFormat
,
2245 GLint width
, GLint height
, GLint border
)
2248 GLint rb_base_format
;
2249 struct gl_renderbuffer
*rb
;
2250 GLenum rb_internal_format
;
2253 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2254 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2255 dimensions
, _mesa_enum_to_string(target
));
2260 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2261 _mesa_error(ctx
, GL_INVALID_VALUE
,
2262 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2266 /* Check that the source buffer is complete */
2267 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2268 if (ctx
->ReadBuffer
->_Status
== 0) {
2269 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2271 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2272 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2273 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2277 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2278 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2279 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2285 if (border
< 0 || border
> 1 ||
2286 ((ctx
->API
!= API_OPENGL_COMPAT
||
2287 target
== GL_TEXTURE_RECTANGLE_NV
||
2288 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2289 _mesa_error(ctx
, GL_INVALID_VALUE
,
2290 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2294 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2297 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2298 switch (internalFormat
) {
2303 case GL_LUMINANCE_ALPHA
:
2306 _mesa_error(ctx
, GL_INVALID_ENUM
,
2307 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2308 _mesa_enum_to_string(internalFormat
));
2313 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2314 * OpenGL 4.5 (Compatibility Profile) spec says:
2316 * "Parameters level, internalformat, and border are specified using
2317 * the same values, with the same meanings, as the corresponding
2318 * arguments of TexImage2D, except that internalformat may not be
2319 * specified as 1, 2, 3, or 4."
2321 if (internalFormat
>= 1 && internalFormat
<= 4) {
2322 _mesa_error(ctx
, GL_INVALID_ENUM
,
2323 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2329 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2330 if (baseFormat
< 0) {
2331 _mesa_error(ctx
, GL_INVALID_ENUM
,
2332 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2333 _mesa_enum_to_string(internalFormat
));
2337 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2339 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2340 "glCopyTexImage%dD(read buffer)", dimensions
);
2344 rb_internal_format
= rb
->InternalFormat
;
2345 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2346 if (_mesa_is_color_format(internalFormat
)) {
2347 if (rb_base_format
< 0) {
2348 _mesa_error(ctx
, GL_INVALID_VALUE
,
2349 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2350 _mesa_enum_to_string(internalFormat
));
2355 if (_mesa_is_gles(ctx
)) {
2357 if (_mesa_base_format_component_count(baseFormat
) >
2358 _mesa_base_format_component_count(rb_base_format
)) {
2361 if (baseFormat
== GL_DEPTH_COMPONENT
||
2362 baseFormat
== GL_DEPTH_STENCIL
||
2363 baseFormat
== GL_STENCIL_INDEX
||
2364 rb_base_format
== GL_DEPTH_COMPONENT
||
2365 rb_base_format
== GL_DEPTH_STENCIL
||
2366 rb_base_format
== GL_STENCIL_INDEX
||
2367 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2368 baseFormat
== GL_ALPHA
) &&
2369 rb_base_format
!= GL_RGBA
) ||
2370 internalFormat
== GL_RGB9_E5
) {
2373 if (internalFormat
== GL_RGB9_E5
) {
2377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2378 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2379 _mesa_enum_to_string(internalFormat
));
2384 if (_mesa_is_gles3(ctx
)) {
2385 bool rb_is_srgb
= false;
2386 bool dst_is_srgb
= false;
2388 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2389 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2393 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2397 if (rb_is_srgb
!= dst_is_srgb
) {
2398 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2399 * OpenGLES 3.0.0 spec says:
2401 * "The error INVALID_OPERATION is also generated if the
2402 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2403 * framebuffer attachment corresponding to the read buffer
2404 * is LINEAR (see section 6.1.13) and internalformat is
2405 * one of the sRGB formats described in section 3.8.16, or
2406 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2407 * SRGB and internalformat is not one of the sRGB formats."
2409 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2410 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2414 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2415 * types for SNORM formats. Also, conversion to SNORM formats is not
2416 * allowed by Table 3.2 on Page 110.
2418 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2421 _mesa_enum_to_string(internalFormat
));
2426 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2428 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2432 /* From the EXT_texture_integer spec:
2434 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2435 * if the texture internalformat is an integer format and the read color
2436 * buffer is not an integer format, or if the internalformat is not an
2437 * integer format and the read color buffer is an integer format."
2439 if (_mesa_is_color_format(internalFormat
)) {
2440 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2441 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2442 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2443 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2444 if (is_int
|| is_rbint
) {
2445 if (is_int
!= is_rbint
) {
2446 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2447 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2449 } else if (_mesa_is_gles(ctx
) &&
2450 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2451 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2452 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2453 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2458 /* From page 138 of OpenGL ES 3.0 spec:
2459 * "The error INVALID_OPERATION is generated if floating-point RGBA
2460 * data is required; if signed integer RGBA data is required and the
2461 * format of the current color buffer is not signed integer; if
2462 * unsigned integer RGBA data is required and the format of the
2463 * current color buffer is not unsigned integer; or if fixed-point
2464 * RGBA data is required and the format of the current color buffer
2465 * is not fixed-point.
2467 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2468 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2469 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2472 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2474 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2475 _mesa_error(ctx
, err
,
2476 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2479 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2480 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2481 "glCopyTexImage%dD(no compression for format)", dimensions
);
2485 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2486 "glCopyTexImage%dD(border!=0)", dimensions
);
2491 if (!mutable_tex_object(ctx
, target
)) {
2492 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2493 "glCopyTexImage%dD(immutable texture)", dimensions
);
2497 /* if we get here, the parameters are OK */
2503 * Test glCopyTexSubImage[12]D() parameters for errors.
2504 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2507 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2508 const struct gl_texture_object
*texObj
,
2509 GLenum target
, GLint level
,
2510 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2511 GLint width
, GLint height
, const char *caller
)
2513 struct gl_texture_image
*texImage
;
2515 /* Check that the source buffer is complete */
2516 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2517 if (ctx
->ReadBuffer
->_Status
== 0) {
2518 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2520 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2521 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2522 "%s(invalid readbuffer)", caller
);
2526 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2527 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2528 "%s(multisample FBO)", caller
);
2534 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2535 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2539 /* Get dest image pointers */
2541 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2545 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2547 /* destination image does not exist */
2548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2549 "%s(invalid texture image)", caller
);
2553 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2554 width
, height
, 1, caller
)) {
2558 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2559 xoffset
, yoffset
, zoffset
,
2560 width
, height
, 1, caller
)) {
2564 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2565 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2567 "%s(no compression for format)", caller
);
2572 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2577 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2579 "%s(missing readbuffer, format=%s)", caller
,
2580 _mesa_enum_to_string(texImage
->_BaseFormat
));
2584 /* From the EXT_texture_integer spec:
2586 * "INVALID_OPERATION is generated by CopyTexImage* and
2587 * CopyTexSubImage* if the texture internalformat is an integer format
2588 * and the read color buffer is not an integer format, or if the
2589 * internalformat is not an integer format and the read color buffer
2590 * is an integer format."
2592 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2593 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2595 if (_mesa_is_format_integer_color(rb
->Format
) !=
2596 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2598 "%s(integer vs non-integer)", caller
);
2603 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2604 * framebuffer/destination texture base internal format combinations),
2605 * all the entries for stencil are left blank (unsupported).
2607 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2612 /* if we get here, the parameters are OK */
2617 /** Callback info for walking over FBO hash table */
2620 struct gl_context
*ctx
;
2621 struct gl_texture_object
*texObj
;
2627 * Check render to texture callback. Called from _mesa_HashWalk().
2630 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2632 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2633 const struct cb_info
*info
= (struct cb_info
*) userData
;
2634 struct gl_context
*ctx
= info
->ctx
;
2635 const struct gl_texture_object
*texObj
= info
->texObj
;
2636 const GLuint level
= info
->level
, face
= info
->face
;
2638 /* If this is a user-created FBO */
2639 if (_mesa_is_user_fbo(fb
)) {
2641 /* check if any of the FBO's attachments point to 'texObj' */
2642 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2643 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2644 if (att
->Type
== GL_TEXTURE
&&
2645 att
->Texture
== texObj
&&
2646 att
->TextureLevel
== level
&&
2647 att
->CubeMapFace
== face
) {
2648 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2649 assert(att
->Renderbuffer
->TexImage
);
2650 /* Mark fb status as indeterminate to force re-validation */
2653 /* Make sure that the revalidation actually happens if this is
2654 * being done to currently-bound buffers.
2656 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2657 ctx
->NewState
|= _NEW_BUFFERS
;
2665 * When a texture image is specified we have to check if it's bound to
2666 * any framebuffer objects (render to texture) in order to detect changes
2667 * in size or format since that effects FBO completeness.
2668 * Any FBOs rendering into the texture must be re-validated.
2671 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2672 struct gl_texture_object
*texObj
,
2673 GLuint face
, GLuint level
)
2675 /* Only check this texture if it's been marked as RenderToTexture */
2676 if (texObj
->_RenderToTexture
) {
2677 struct cb_info info
;
2679 info
.texObj
= texObj
;
2682 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2688 * If the texture object's GenerateMipmap flag is set and we've
2689 * changed the texture base level image, regenerate the rest of the
2690 * mipmap levels now.
2693 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2694 struct gl_texture_object
*texObj
, GLint level
)
2696 if (texObj
->GenerateMipmap
&&
2697 level
== texObj
->BaseLevel
&&
2698 level
< texObj
->MaxLevel
) {
2699 assert(ctx
->Driver
.GenerateMipmap
);
2700 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2705 /** Debug helper: override the user-requested internal format */
2707 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2710 if (internalFormat
== GL_RGBA16F_ARB
||
2711 internalFormat
== GL_RGBA32F_ARB
) {
2712 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2715 else if (internalFormat
== GL_RGB16F_ARB
||
2716 internalFormat
== GL_RGB32F_ARB
) {
2717 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2720 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2721 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2722 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2723 return GL_LUMINANCE_ALPHA
;
2725 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2726 internalFormat
== GL_LUMINANCE32F_ARB
) {
2727 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2728 return GL_LUMINANCE
;
2730 else if (internalFormat
== GL_ALPHA16F_ARB
||
2731 internalFormat
== GL_ALPHA32F_ARB
) {
2732 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2736 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2737 internalFormat = GL_RGBA;
2741 return internalFormat
;
2744 return internalFormat
;
2750 * Choose the actual hardware format for a texture image.
2751 * Try to use the same format as the previous image level when possible.
2752 * Otherwise, ask the driver for the best format.
2753 * It's important to try to choose a consistant format for all levels
2754 * for efficient texture memory layout/allocation. In particular, this
2755 * comes up during automatic mipmap generation.
2758 _mesa_choose_texture_format(struct gl_context
*ctx
,
2759 struct gl_texture_object
*texObj
,
2760 GLenum target
, GLint level
,
2761 GLenum internalFormat
, GLenum format
, GLenum type
)
2765 /* see if we've already chosen a format for the previous level */
2767 struct gl_texture_image
*prevImage
=
2768 _mesa_select_tex_image(texObj
, target
, level
- 1);
2769 /* See if the prev level is defined and has an internal format which
2770 * matches the new internal format.
2773 prevImage
->Width
> 0 &&
2774 prevImage
->InternalFormat
== internalFormat
) {
2775 /* use the same format */
2776 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2777 return prevImage
->TexFormat
;
2781 /* If the application requested compression to an S3TC format but we don't
2782 * have the DXTn library, force a generic compressed format instead.
2784 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2785 const GLenum before
= internalFormat
;
2787 switch (internalFormat
) {
2788 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2789 if (!ctx
->Mesa_DXTn
)
2790 internalFormat
= GL_COMPRESSED_RGB
;
2792 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2793 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2794 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2795 if (!ctx
->Mesa_DXTn
)
2796 internalFormat
= GL_COMPRESSED_RGBA
;
2802 if (before
!= internalFormat
) {
2804 "DXT compression requested (%s), "
2805 "but libtxc_dxtn library not installed. Using %s "
2807 _mesa_enum_to_string(before
),
2808 _mesa_enum_to_string(internalFormat
));
2812 /* choose format from scratch */
2813 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2815 assert(f
!= MESA_FORMAT_NONE
);
2821 * Adjust pixel unpack params and image dimensions to strip off the
2822 * one-pixel texture border.
2824 * Gallium and intel don't support texture borders. They've seldem been used
2825 * and seldom been implemented correctly anyway.
2827 * \param unpackNew returns the new pixel unpack parameters
2830 strip_texture_border(GLenum target
,
2831 GLint
*width
, GLint
*height
, GLint
*depth
,
2832 const struct gl_pixelstore_attrib
*unpack
,
2833 struct gl_pixelstore_attrib
*unpackNew
)
2839 *unpackNew
= *unpack
;
2841 if (unpackNew
->RowLength
== 0)
2842 unpackNew
->RowLength
= *width
;
2844 if (unpackNew
->ImageHeight
== 0)
2845 unpackNew
->ImageHeight
= *height
;
2847 assert(*width
>= 3);
2848 unpackNew
->SkipPixels
++; /* skip the border */
2849 *width
= *width
- 2; /* reduce the width by two border pixels */
2851 /* The min height of a texture with a border is 3 */
2852 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2853 unpackNew
->SkipRows
++; /* skip the border */
2854 *height
= *height
- 2; /* reduce the height by two border pixels */
2858 target
!= GL_TEXTURE_2D_ARRAY
&&
2859 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2860 unpackNew
->SkipImages
++; /* skip the border */
2861 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2867 * Common code to implement all the glTexImage1D/2D/3D functions
2868 * as well as glCompressedTexImage1D/2D/3D.
2869 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2870 * \param format the user's image format (only used if !compressed)
2871 * \param type the user's image type (only used if !compressed)
2872 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2875 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2876 GLenum target
, GLint level
, GLint internalFormat
,
2877 GLsizei width
, GLsizei height
, GLsizei depth
,
2878 GLint border
, GLenum format
, GLenum type
,
2879 GLsizei imageSize
, const GLvoid
*pixels
)
2881 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2882 struct gl_pixelstore_attrib unpack_no_border
;
2883 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2884 struct gl_texture_object
*texObj
;
2885 mesa_format texFormat
;
2886 GLboolean dimensionsOK
, sizeOK
;
2888 FLUSH_VERTICES(ctx
, 0);
2890 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2893 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2895 _mesa_enum_to_string(target
), level
,
2896 _mesa_enum_to_string(internalFormat
),
2897 width
, height
, depth
, border
, pixels
);
2900 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2902 _mesa_enum_to_string(target
), level
,
2903 _mesa_enum_to_string(internalFormat
),
2904 width
, height
, depth
, border
,
2905 _mesa_enum_to_string(format
),
2906 _mesa_enum_to_string(type
), pixels
);
2909 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2911 /* target error checking */
2912 if (!legal_teximage_target(ctx
, dims
, target
)) {
2913 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2914 func
, dims
, _mesa_enum_to_string(target
));
2918 /* general error checking */
2920 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2922 width
, height
, depth
,
2923 border
, imageSize
, pixels
))
2927 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2928 format
, type
, width
, height
, depth
, border
,
2933 /* Here we convert a cpal compressed image into a regular glTexImage2D
2934 * call by decompressing the texture. If we really want to support cpal
2935 * textures in any driver this would have to be changed.
2937 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2938 switch (internalFormat
) {
2939 case GL_PALETTE4_RGB8_OES
:
2940 case GL_PALETTE4_RGBA8_OES
:
2941 case GL_PALETTE4_R5_G6_B5_OES
:
2942 case GL_PALETTE4_RGBA4_OES
:
2943 case GL_PALETTE4_RGB5_A1_OES
:
2944 case GL_PALETTE8_RGB8_OES
:
2945 case GL_PALETTE8_RGBA8_OES
:
2946 case GL_PALETTE8_R5_G6_B5_OES
:
2947 case GL_PALETTE8_RGBA4_OES
:
2948 case GL_PALETTE8_RGB5_A1_OES
:
2949 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2950 width
, height
, imageSize
, pixels
);
2955 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2959 /* For glCompressedTexImage() the driver has no choice about the
2960 * texture format since we'll never transcode the user's compressed
2961 * image data. The internalFormat was error checked earlier.
2963 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
2966 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
2967 * internal floating point format for the given base format.
2969 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
2970 if (type
== GL_FLOAT
) {
2971 texObj
->_IsFloat
= GL_TRUE
;
2972 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
2973 texObj
->_IsHalfFloat
= GL_TRUE
;
2976 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
2979 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2980 internalFormat
, format
, type
);
2983 assert(texFormat
!= MESA_FORMAT_NONE
);
2985 /* check that width, height, depth are legal for the mipmap level */
2986 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2987 height
, depth
, border
);
2989 /* check that the texture won't take too much memory, etc */
2990 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
2991 0, level
, texFormat
, 1,
2992 width
, height
, depth
);
2994 if (_mesa_is_proxy_texture(target
)) {
2995 /* Proxy texture: just clear or set state depending on error checking */
2996 struct gl_texture_image
*texImage
=
2997 get_proxy_tex_image(ctx
, target
, level
);
3000 return; /* GL_OUT_OF_MEMORY already recorded */
3002 if (dimensionsOK
&& sizeOK
) {
3003 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3004 border
, internalFormat
, texFormat
);
3007 clear_teximage_fields(texImage
);
3011 /* non-proxy target */
3012 const GLuint face
= _mesa_tex_target_to_face(target
);
3013 struct gl_texture_image
*texImage
;
3015 if (!dimensionsOK
) {
3016 _mesa_error(ctx
, GL_INVALID_VALUE
,
3017 "%s%uD(invalid width or height or depth)",
3023 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3024 "%s%uD(image too large: %d x %d x %d, %s format)",
3025 func
, dims
, width
, height
, depth
,
3026 _mesa_enum_to_string(internalFormat
));
3030 /* Allow a hardware driver to just strip out the border, to provide
3031 * reliable but slightly incorrect hardware rendering instead of
3032 * rarely-tested software fallback rendering.
3034 if (border
&& ctx
->Const
.StripTextureBorder
) {
3035 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3038 unpack
= &unpack_no_border
;
3041 if (ctx
->NewState
& _NEW_PIXEL
)
3042 _mesa_update_state(ctx
);
3044 _mesa_lock_texture(ctx
, texObj
);
3046 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3049 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3052 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3054 _mesa_init_teximage_fields(ctx
, texImage
,
3055 width
, height
, depth
,
3056 border
, internalFormat
, texFormat
);
3058 /* Give the texture to the driver. <pixels> may be null. */
3059 if (width
> 0 && height
> 0 && depth
> 0) {
3061 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3065 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3066 type
, pixels
, unpack
);
3070 check_gen_mipmap(ctx
, target
, texObj
, level
);
3072 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3074 _mesa_dirty_texobj(ctx
, texObj
);
3077 _mesa_unlock_texture(ctx
, texObj
);
3084 * Called from the API. Note that width includes the border.
3087 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3088 GLsizei width
, GLint border
, GLenum format
,
3089 GLenum type
, const GLvoid
*pixels
)
3091 GET_CURRENT_CONTEXT(ctx
);
3092 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3093 border
, format
, type
, 0, pixels
);
3098 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3099 GLsizei width
, GLsizei height
, GLint border
,
3100 GLenum format
, GLenum type
,
3101 const GLvoid
*pixels
)
3103 GET_CURRENT_CONTEXT(ctx
);
3104 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3105 border
, format
, type
, 0, pixels
);
3110 * Called by the API or display list executor.
3111 * Note that width and height include the border.
3114 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3115 GLsizei width
, GLsizei height
, GLsizei depth
,
3116 GLint border
, GLenum format
, GLenum type
,
3117 const GLvoid
*pixels
)
3119 GET_CURRENT_CONTEXT(ctx
);
3120 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3121 width
, height
, depth
,
3122 border
, format
, type
, 0, pixels
);
3127 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3128 GLsizei width
, GLsizei height
, GLsizei depth
,
3129 GLint border
, GLenum format
, GLenum type
,
3130 const GLvoid
*pixels
)
3132 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3133 depth
, border
, format
, type
, pixels
);
3138 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3140 struct gl_texture_object
*texObj
;
3141 struct gl_texture_image
*texImage
;
3143 GET_CURRENT_CONTEXT(ctx
);
3144 FLUSH_VERTICES(ctx
, 0);
3148 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3150 case GL_TEXTURE_EXTERNAL_OES
:
3152 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3155 valid_target
= false;
3159 if (!valid_target
) {
3160 _mesa_error(ctx
, GL_INVALID_ENUM
,
3161 "glEGLImageTargetTexture2D(target=%d)", target
);
3166 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3167 "glEGLImageTargetTexture2D(image=%p)", image
);
3171 if (ctx
->NewState
& _NEW_PIXEL
)
3172 _mesa_update_state(ctx
);
3174 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3178 _mesa_lock_texture(ctx
, texObj
);
3180 if (texObj
->Immutable
) {
3181 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3182 "glEGLImageTargetTexture2D(texture is immutable)");
3183 _mesa_unlock_texture(ctx
, texObj
);
3187 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3189 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3191 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3193 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3194 texObj
, texImage
, image
);
3196 _mesa_dirty_texobj(ctx
, texObj
);
3198 _mesa_unlock_texture(ctx
, texObj
);
3203 * Helper that implements the glTexSubImage1/2/3D()
3204 * and glTextureSubImage1/2/3D() functions.
3207 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3208 struct gl_texture_object
*texObj
,
3209 struct gl_texture_image
*texImage
,
3210 GLenum target
, GLint level
,
3211 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3212 GLsizei width
, GLsizei height
, GLsizei depth
,
3213 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3216 FLUSH_VERTICES(ctx
, 0);
3218 if (ctx
->NewState
& _NEW_PIXEL
)
3219 _mesa_update_state(ctx
);
3221 _mesa_lock_texture(ctx
, texObj
);
3223 if (width
> 0 && height
> 0 && depth
> 0) {
3224 /* If we have a border, offset=-1 is legal. Bias by border width. */
3227 if (target
!= GL_TEXTURE_2D_ARRAY
)
3228 zoffset
+= texImage
->Border
;
3231 if (target
!= GL_TEXTURE_1D_ARRAY
)
3232 yoffset
+= texImage
->Border
;
3235 xoffset
+= texImage
->Border
;
3238 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3239 xoffset
, yoffset
, zoffset
,
3240 width
, height
, depth
,
3241 format
, type
, pixels
, &ctx
->Unpack
);
3243 check_gen_mipmap(ctx
, target
, texObj
, level
);
3245 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3246 * the texel data, not the texture format, size, etc.
3250 _mesa_unlock_texture(ctx
, texObj
);
3254 * Implement all the glTexSubImage1/2/3D() functions.
3255 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3258 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3259 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3260 GLsizei width
, GLsizei height
, GLsizei depth
,
3261 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3262 const char *callerName
)
3264 struct gl_texture_object
*texObj
;
3265 struct gl_texture_image
*texImage
;
3267 /* check target (proxies not allowed) */
3268 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3269 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3270 dims
, _mesa_enum_to_string(target
));
3274 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3278 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3279 xoffset
, yoffset
, zoffset
,
3280 width
, height
, depth
, format
, type
,
3281 pixels
, false, callerName
)) {
3282 return; /* error was detected */
3285 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3286 /* texsubimage_error_check ensures that texImage is not NULL */
3288 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3289 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3291 _mesa_enum_to_string(target
), level
,
3292 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3293 _mesa_enum_to_string(format
),
3294 _mesa_enum_to_string(type
), pixels
);
3296 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3297 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3298 format
, type
, pixels
, false);
3303 * Implement all the glTextureSubImage1/2/3D() functions.
3304 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3307 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3308 GLuint texture
, GLint level
,
3309 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3310 GLsizei width
, GLsizei height
, GLsizei depth
,
3311 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3312 const char *callerName
)
3314 struct gl_texture_object
*texObj
;
3315 struct gl_texture_image
*texImage
;
3318 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3320 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3321 dims
, texture
, level
,
3322 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3323 _mesa_enum_to_string(format
),
3324 _mesa_enum_to_string(type
), pixels
);
3326 /* Get the texture object by Name. */
3327 texObj
= _mesa_lookup_texture(ctx
, texture
);
3329 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3334 /* check target (proxies not allowed) */
3335 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3336 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3337 callerName
, _mesa_enum_to_string(texObj
->Target
));
3341 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3342 xoffset
, yoffset
, zoffset
,
3343 width
, height
, depth
, format
, type
,
3344 pixels
, true, callerName
)) {
3345 return; /* error was detected */
3349 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3350 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3354 * What do we do if the user created a texture with the following code
3355 * and then called this function with its handle?
3358 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3359 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3360 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3361 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3362 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3363 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3364 * // wrong format, or given the wrong size, etc.
3365 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3366 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3368 * A bug has been filed against the spec for this case. In the
3369 * meantime, we will check for cube completeness.
3371 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3372 * Core Profile spec (30.10.2014):
3373 * "[A] cube map texture is cube complete if the
3374 * following conditions all hold true: The [base level] texture
3375 * images of each of the six cube map faces have identical, positive,
3376 * and square dimensions. The [base level] images were each specified
3377 * with the same internal format."
3379 * It seems reasonable to check for cube completeness of an arbitrary
3380 * level here so that the image data has a consistent format and size.
3382 if (!_mesa_cube_level_complete(texObj
, level
)) {
3383 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3384 "glTextureSubImage%uD(cube map incomplete)",
3389 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3391 /* Copy in each face. */
3392 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3393 texImage
= texObj
->Image
[i
][level
];
3396 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3397 level
, xoffset
, yoffset
, 0,
3398 width
, height
, 1, format
,
3399 type
, pixels
, true);
3400 pixels
= (GLubyte
*) pixels
+ imageStride
;
3404 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3407 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3408 level
, xoffset
, yoffset
, zoffset
,
3409 width
, height
, depth
, format
,
3410 type
, pixels
, true);
3416 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3417 GLint xoffset
, GLsizei width
,
3418 GLenum format
, GLenum type
,
3419 const GLvoid
*pixels
)
3421 GET_CURRENT_CONTEXT(ctx
);
3422 texsubimage(ctx
, 1, target
, level
,
3425 format
, type
, pixels
, "glTexSubImage1D");
3430 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3431 GLint xoffset
, GLint yoffset
,
3432 GLsizei width
, GLsizei height
,
3433 GLenum format
, GLenum type
,
3434 const GLvoid
*pixels
)
3436 GET_CURRENT_CONTEXT(ctx
);
3437 texsubimage(ctx
, 2, target
, level
,
3438 xoffset
, yoffset
, 0,
3440 format
, type
, pixels
, "glTexSubImage2D");
3446 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3447 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3448 GLsizei width
, GLsizei height
, GLsizei depth
,
3449 GLenum format
, GLenum type
,
3450 const GLvoid
*pixels
)
3452 GET_CURRENT_CONTEXT(ctx
);
3453 texsubimage(ctx
, 3, target
, level
,
3454 xoffset
, yoffset
, zoffset
,
3455 width
, height
, depth
,
3456 format
, type
, pixels
, "glTexSubImage3D");
3460 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3461 GLint xoffset
, GLsizei width
,
3462 GLenum format
, GLenum type
,
3463 const GLvoid
*pixels
)
3465 GET_CURRENT_CONTEXT(ctx
);
3466 texturesubimage(ctx
, 1, texture
, level
,
3469 format
, type
, pixels
, "glTextureSubImage1D");
3474 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3475 GLint xoffset
, GLint yoffset
,
3476 GLsizei width
, GLsizei height
,
3477 GLenum format
, GLenum type
,
3478 const GLvoid
*pixels
)
3480 GET_CURRENT_CONTEXT(ctx
);
3481 texturesubimage(ctx
, 2, texture
, level
,
3482 xoffset
, yoffset
, 0,
3484 format
, type
, pixels
, "glTextureSubImage2D");
3489 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3490 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3491 GLsizei width
, GLsizei height
, GLsizei depth
,
3492 GLenum format
, GLenum type
,
3493 const GLvoid
*pixels
)
3495 GET_CURRENT_CONTEXT(ctx
);
3496 texturesubimage(ctx
, 3, texture
, level
,
3497 xoffset
, yoffset
, zoffset
,
3498 width
, height
, depth
,
3499 format
, type
, pixels
, "glTextureSubImage3D");
3504 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3505 * from. This depends on whether the texture contains color or depth values.
3507 static struct gl_renderbuffer
*
3508 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3510 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3511 /* reading from depth/stencil buffer */
3512 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3513 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3514 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3516 /* copying from color buffer */
3517 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3522 copytexsubimage_by_slice(struct gl_context
*ctx
,
3523 struct gl_texture_image
*texImage
,
3525 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3526 struct gl_renderbuffer
*rb
,
3528 GLsizei width
, GLsizei height
)
3530 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3533 /* For 1D arrays, we copy each scanline of the source rectangle into the
3536 assert(zoffset
== 0);
3538 for (slice
= 0; slice
< height
; slice
++) {
3539 assert(yoffset
+ slice
< texImage
->Height
);
3540 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3541 xoffset
, 0, yoffset
+ slice
,
3542 rb
, x
, y
+ slice
, width
, 1);
3545 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3546 xoffset
, yoffset
, zoffset
,
3547 rb
, x
, y
, width
, height
);
3552 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3554 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3555 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3556 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3557 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3559 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3560 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3561 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3562 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3564 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3565 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3566 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3567 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3575 * Check if the given texture format and size arguments match those
3576 * of the texture image.
3577 * \param return true if arguments match, false otherwise.
3580 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3581 GLenum internalFormat
,
3582 mesa_format texFormat
, GLint x
, GLint y
, GLsizei width
,
3583 GLsizei height
, GLint border
)
3585 if (texImage
->InternalFormat
!= internalFormat
)
3587 if (texImage
->TexFormat
!= texFormat
)
3589 if (texImage
->Border
!= border
)
3591 if (texImage
->Width2
!= width
)
3593 if (texImage
->Height2
!= height
)
3599 * Implement the glCopyTexImage1/2D() functions.
3602 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3603 GLenum target
, GLint level
, GLenum internalFormat
,
3604 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3606 struct gl_texture_object
*texObj
;
3607 struct gl_texture_image
*texImage
;
3608 const GLuint face
= _mesa_tex_target_to_face(target
);
3609 mesa_format texFormat
;
3610 struct gl_renderbuffer
*rb
;
3612 FLUSH_VERTICES(ctx
, 0);
3614 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3615 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3617 _mesa_enum_to_string(target
), level
,
3618 _mesa_enum_to_string(internalFormat
),
3619 x
, y
, width
, height
, border
);
3621 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3622 _mesa_update_state(ctx
);
3624 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3625 width
, height
, border
))
3628 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3630 _mesa_error(ctx
, GL_INVALID_VALUE
,
3631 "glCopyTexImage%uD(invalid width or height)", dims
);
3635 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3638 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3639 internalFormat
, GL_NONE
, GL_NONE
);
3641 /* First check if reallocating the texture buffer can be avoided.
3642 * Without the realloc the copy can be 20x faster.
3644 _mesa_lock_texture(ctx
, texObj
);
3646 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3647 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3648 x
, y
, width
, height
, border
)) {
3649 _mesa_unlock_texture(ctx
, texObj
);
3650 _mesa_copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
,
3651 0, 0, 0, x
, y
, width
, height
,
3656 _mesa_unlock_texture(ctx
, texObj
);
3657 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3658 "can't avoid reallocating texture storage\n");
3660 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3662 if (_mesa_is_gles3(ctx
)) {
3663 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3664 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3665 * OpenGL ES 3.0. Khronos bug# 9807.
3667 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3668 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3669 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3670 " and writing to unsized internal format)", dims
);
3674 /* From Page 139 of OpenGL ES 3.0 spec:
3675 * "If internalformat is sized, the internal format of the new texel
3676 * array is internalformat, and this is also the new texel array’s
3677 * effective internal format. If the component sizes of internalformat
3678 * do not exactly match the corresponding component sizes of the source
3679 * buffer’s effective internal format, described below, an
3680 * INVALID_OPERATION error is generated. If internalformat is unsized,
3681 * the internal format of the new texel array is the effective internal
3682 * format of the source buffer, and this is also the new texel array’s
3683 * effective internal format.
3685 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3686 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3687 "glCopyTexImage%uD(componenet size changed in"
3688 " internal format)", dims
);
3693 assert(texFormat
!= MESA_FORMAT_NONE
);
3695 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3696 0, level
, texFormat
, 1,
3697 width
, height
, 1)) {
3698 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3699 "glCopyTexImage%uD(image too large)", dims
);
3703 if (border
&& ctx
->Const
.StripTextureBorder
) {
3705 width
-= border
* 2;
3708 height
-= border
* 2;
3713 _mesa_lock_texture(ctx
, texObj
);
3715 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3718 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3721 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3723 /* Free old texture image */
3724 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3726 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3727 border
, internalFormat
, texFormat
);
3729 if (width
&& height
) {
3730 /* Allocate texture memory (no pixel data yet) */
3731 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3733 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3735 struct gl_renderbuffer
*srcRb
=
3736 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3738 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3740 srcRb
, srcX
, srcY
, width
, height
);
3743 check_gen_mipmap(ctx
, target
, texObj
, level
);
3746 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3748 _mesa_dirty_texobj(ctx
, texObj
);
3751 _mesa_unlock_texture(ctx
, texObj
);
3757 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3758 GLenum internalFormat
,
3760 GLsizei width
, GLint border
)
3762 GET_CURRENT_CONTEXT(ctx
);
3763 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3769 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3770 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3773 GET_CURRENT_CONTEXT(ctx
);
3774 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3775 x
, y
, width
, height
, border
);
3779 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3782 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3783 struct gl_texture_object
*texObj
,
3784 GLenum target
, GLint level
,
3785 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3787 GLsizei width
, GLsizei height
,
3790 struct gl_texture_image
*texImage
;
3792 FLUSH_VERTICES(ctx
, 0);
3794 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3795 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3796 _mesa_enum_to_string(target
),
3797 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3799 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3800 _mesa_update_state(ctx
);
3802 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3803 xoffset
, yoffset
, zoffset
,
3804 width
, height
, caller
)) {
3808 _mesa_lock_texture(ctx
, texObj
);
3810 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3812 /* If we have a border, offset=-1 is legal. Bias by border width. */
3815 if (target
!= GL_TEXTURE_2D_ARRAY
)
3816 zoffset
+= texImage
->Border
;
3819 if (target
!= GL_TEXTURE_1D_ARRAY
)
3820 yoffset
+= texImage
->Border
;
3823 xoffset
+= texImage
->Border
;
3826 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3828 struct gl_renderbuffer
*srcRb
=
3829 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3831 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3832 xoffset
, yoffset
, zoffset
,
3833 srcRb
, x
, y
, width
, height
);
3835 check_gen_mipmap(ctx
, target
, texObj
, level
);
3837 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3838 * the texel data, not the texture format, size, etc.
3842 _mesa_unlock_texture(ctx
, texObj
);
3846 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3847 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3849 struct gl_texture_object
* texObj
;
3850 const char *self
= "glCopyTexSubImage1D";
3851 GET_CURRENT_CONTEXT(ctx
);
3853 /* Check target (proxies not allowed). Target must be checked prior to
3854 * calling _mesa_get_current_tex_object.
3856 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
3857 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3858 _mesa_enum_to_string(target
));
3862 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3866 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
3867 x
, y
, width
, 1, self
);
3873 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3874 GLint xoffset
, GLint yoffset
,
3875 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3877 struct gl_texture_object
* texObj
;
3878 const char *self
= "glCopyTexSubImage2D";
3879 GET_CURRENT_CONTEXT(ctx
);
3881 /* Check target (proxies not allowed). Target must be checked prior to
3882 * calling _mesa_get_current_tex_object.
3884 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
3885 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3886 _mesa_enum_to_string(target
));
3890 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3894 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
3895 xoffset
, yoffset
, 0,
3896 x
, y
, width
, height
, self
);
3902 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3903 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3904 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3906 struct gl_texture_object
* texObj
;
3907 const char *self
= "glCopyTexSubImage3D";
3908 GET_CURRENT_CONTEXT(ctx
);
3910 /* Check target (proxies not allowed). Target must be checked prior to
3911 * calling _mesa_get_current_tex_object.
3913 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
3914 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3915 _mesa_enum_to_string(target
));
3919 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3923 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
3924 xoffset
, yoffset
, zoffset
,
3925 x
, y
, width
, height
, self
);
3929 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
3930 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3932 struct gl_texture_object
* texObj
;
3933 const char *self
= "glCopyTextureSubImage1D";
3934 GET_CURRENT_CONTEXT(ctx
);
3936 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3940 /* Check target (proxies not allowed). */
3941 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
3942 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
3943 _mesa_enum_to_string(texObj
->Target
));
3947 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
3948 xoffset
, 0, 0, x
, y
, width
, 1, self
);
3952 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
3953 GLint xoffset
, GLint yoffset
,
3954 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3956 struct gl_texture_object
* texObj
;
3957 const char *self
= "glCopyTextureSubImage2D";
3958 GET_CURRENT_CONTEXT(ctx
);
3960 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3964 /* Check target (proxies not allowed). */
3965 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
3966 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
3967 _mesa_enum_to_string(texObj
->Target
));
3971 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
3972 xoffset
, yoffset
, 0,
3973 x
, y
, width
, height
, self
);
3979 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
3980 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3981 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3983 struct gl_texture_object
* texObj
;
3984 const char *self
= "glCopyTextureSubImage3D";
3985 GET_CURRENT_CONTEXT(ctx
);
3987 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3991 /* Check target (proxies not allowed). */
3992 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
3993 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
3994 _mesa_enum_to_string(texObj
->Target
));
3998 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3999 /* Act like CopyTexSubImage2D */
4000 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4001 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4002 level
, xoffset
, yoffset
, 0,
4003 x
, y
, width
, height
, self
);
4006 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4007 xoffset
, yoffset
, zoffset
,
4008 x
, y
, width
, height
, self
);
4012 check_clear_tex_image(struct gl_context
*ctx
,
4013 const char *function
,
4014 struct gl_texture_image
*texImage
,
4015 GLenum format
, GLenum type
,
4017 GLubyte
*clearValue
)
4019 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4020 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4021 GLenum internalFormat
= texImage
->InternalFormat
;
4024 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4026 "%s(buffer texture)", function
);
4030 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4031 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4032 "%s(compressed texture)", function
);
4036 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4037 if (err
!= GL_NO_ERROR
) {
4038 _mesa_error(ctx
, err
,
4039 "%s(incompatible format = %s, type = %s)",
4041 _mesa_enum_to_string(format
),
4042 _mesa_enum_to_string(type
));
4046 /* make sure internal format and format basically agree */
4047 if (!texture_formats_agree(internalFormat
, format
)) {
4048 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4049 "%s(incompatible internalFormat = %s, format = %s)",
4051 _mesa_enum_to_string(internalFormat
),
4052 _mesa_enum_to_string(format
));
4056 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4057 /* both source and dest must be integer-valued, or neither */
4058 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4059 _mesa_is_enum_format_integer(format
)) {
4060 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4061 "%s(integer/non-integer format mismatch)",
4067 if (!_mesa_texstore(ctx
,
4069 texImage
->_BaseFormat
,
4070 texImage
->TexFormat
,
4071 0, /* dstRowStride */
4073 1, 1, 1, /* srcWidth/Height/Depth */
4075 data
? data
: zeroData
,
4076 &ctx
->DefaultPacking
)) {
4077 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4084 static struct gl_texture_object
*
4085 get_tex_obj_for_clear(struct gl_context
*ctx
,
4086 const char *function
,
4089 struct gl_texture_object
*texObj
;
4092 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4096 texObj
= _mesa_lookup_texture(ctx
, texture
);
4098 if (texObj
== NULL
) {
4099 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4103 if (texObj
->Target
== 0) {
4104 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4112 get_tex_images_for_clear(struct gl_context
*ctx
,
4113 const char *function
,
4114 struct gl_texture_object
*texObj
,
4116 struct gl_texture_image
**texImages
)
4121 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4122 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4126 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4127 for (i
= 0; i
< MAX_FACES
; i
++) {
4128 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4130 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4131 if (texImages
[i
] == NULL
) {
4132 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4133 "%s(invalid level)", function
);
4141 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4143 if (texImages
[0] == NULL
) {
4144 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4152 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4153 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4154 GLsizei width
, GLsizei height
, GLsizei depth
,
4155 GLenum format
, GLenum type
, const void *data
)
4157 GET_CURRENT_CONTEXT(ctx
);
4158 struct gl_texture_object
*texObj
;
4159 struct gl_texture_image
*texImages
[MAX_FACES
];
4160 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4162 int minDepth
, maxDepth
;
4164 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4169 _mesa_lock_texture(ctx
, texObj
);
4171 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4172 texObj
, level
, texImages
);
4176 if (numImages
== 1) {
4177 minDepth
= -(int) texImages
[0]->Border
;
4178 maxDepth
= texImages
[0]->Depth
;
4181 maxDepth
= numImages
;
4184 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4185 yoffset
< -(GLint
) texImages
[0]->Border
||
4186 zoffset
< minDepth
||
4190 xoffset
+ width
> texImages
[0]->Width
||
4191 yoffset
+ height
> texImages
[0]->Height
||
4192 zoffset
+ depth
> maxDepth
) {
4193 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4194 "glClearSubTexImage(invalid dimensions)");
4198 if (numImages
== 1) {
4199 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4201 format
, type
, data
, clearValue
[0])) {
4202 ctx
->Driver
.ClearTexSubImage(ctx
,
4204 xoffset
, yoffset
, zoffset
,
4205 width
, height
, depth
,
4206 data
? clearValue
[0] : NULL
);
4209 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4210 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4212 format
, type
, data
, clearValue
[i
]))
4215 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4216 ctx
->Driver
.ClearTexSubImage(ctx
,
4218 xoffset
, yoffset
, 0,
4220 data
? clearValue
[i
] : NULL
);
4225 _mesa_unlock_texture(ctx
, texObj
);
4229 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4230 GLenum format
, GLenum type
, const void *data
)
4232 GET_CURRENT_CONTEXT(ctx
);
4233 struct gl_texture_object
*texObj
;
4234 struct gl_texture_image
*texImages
[MAX_FACES
];
4235 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4238 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4243 _mesa_lock_texture(ctx
, texObj
);
4245 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4246 texObj
, level
, texImages
);
4248 for (i
= 0; i
< numImages
; i
++) {
4249 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4256 for (i
= 0; i
< numImages
; i
++) {
4257 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4258 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4259 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4260 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4261 texImages
[i
]->Width
,
4262 texImages
[i
]->Height
,
4263 texImages
[i
]->Depth
,
4264 data
? clearValue
[i
] : NULL
);
4268 _mesa_unlock_texture(ctx
, texObj
);
4274 /**********************************************************************/
4275 /****** Compressed Textures ******/
4276 /**********************************************************************/
4280 * Target checking for glCompressedTexSubImage[123]D().
4281 * \return GL_TRUE if error, GL_FALSE if no error
4282 * Must come before other error checking so that the texture object can
4283 * be correctly retrieved using _mesa_get_current_tex_object.
4286 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4287 GLint dims
, GLenum format
, bool dsa
,
4292 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4293 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4294 _mesa_enum_to_string(target
));
4304 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4305 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4306 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4307 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4308 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4309 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4310 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4313 targetOK
= GL_FALSE
;
4319 case GL_TEXTURE_CUBE_MAP
:
4320 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4322 case GL_TEXTURE_2D_ARRAY
:
4323 targetOK
= _mesa_is_gles3(ctx
) ||
4324 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4326 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4327 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4332 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4334 * "An INVALID_OPERATION error is generated by
4335 * CompressedTex*SubImage3D if the internal format of the texture
4336 * is one of the EAC, ETC2, or RGTC formats and either border is
4337 * non-zero, or the effective target for the texture is not
4338 * TEXTURE_2D_ARRAY."
4340 * NOTE: that's probably a spec error. It should probably say
4341 * "... or the effective target for the texture is not
4342 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4343 * GL_TEXTURE_CUBE_MAP_ARRAY."
4344 * since those targets are 2D images and they support all compression
4347 * Instead of listing all these, just list those which are allowed,
4348 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4349 * more) are valid here, which they are not, but of course not
4350 * mentioned by core spec.
4353 /* These are the only 3D compression formats supported at this time */
4354 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4355 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4356 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4357 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4361 /* invalid format */
4362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4363 "%s(invalid target %s for format %s)", caller
,
4364 _mesa_enum_to_string(target
),
4365 _mesa_enum_to_string(format
));
4370 targetOK
= GL_FALSE
;
4376 /* no 1D compressed textures at this time */
4377 targetOK
= GL_FALSE
;
4382 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4383 _mesa_enum_to_string(target
));
4391 * Error checking for glCompressedTexSubImage[123]D().
4392 * \return GL_TRUE if error, GL_FALSE if no error
4395 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4396 const struct gl_texture_object
*texObj
,
4397 GLenum target
, GLint level
,
4398 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4399 GLsizei width
, GLsizei height
, GLsizei depth
,
4400 GLenum format
, GLsizei imageSize
,
4401 const GLvoid
*data
, const char *callerName
)
4403 struct gl_texture_image
*texImage
;
4406 /* this will catch any invalid compressed format token */
4407 if (!_mesa_is_compressed_format(ctx
, format
)) {
4408 _mesa_error(ctx
, GL_INVALID_ENUM
,
4409 "%s(format)", callerName
);
4413 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4414 _mesa_error(ctx
, GL_INVALID_VALUE
,
4420 /* validate the bound PBO, if any */
4421 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4422 imageSize
, data
, callerName
)) {
4426 /* Check for invalid pixel storage modes */
4427 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4428 &ctx
->Unpack
, callerName
)) {
4432 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4433 if (expectedSize
!= imageSize
) {
4434 _mesa_error(ctx
, GL_INVALID_VALUE
,
4436 callerName
, imageSize
);
4440 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4443 "%s(invalid texture image)",
4448 if ((GLint
) format
!= texImage
->InternalFormat
) {
4449 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4451 callerName
, _mesa_enum_to_string(format
));
4455 if (compressedteximage_only_format(ctx
, format
)) {
4456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4457 "%s(format=%s cannot be updated)",
4458 callerName
, _mesa_enum_to_string(format
));
4462 if (error_check_subtexture_negative_dimensions(ctx
, dims
,
4463 width
, height
, depth
,
4468 if (error_check_subtexture_dimensions(ctx
, dims
,
4469 texImage
, xoffset
, yoffset
, zoffset
,
4470 width
, height
, depth
,
4480 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4481 GLenum internalFormat
, GLsizei width
,
4482 GLint border
, GLsizei imageSize
,
4485 GET_CURRENT_CONTEXT(ctx
);
4486 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4487 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4492 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4493 GLenum internalFormat
, GLsizei width
,
4494 GLsizei height
, GLint border
, GLsizei imageSize
,
4497 GET_CURRENT_CONTEXT(ctx
);
4498 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4499 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4504 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4505 GLenum internalFormat
, GLsizei width
,
4506 GLsizei height
, GLsizei depth
, GLint border
,
4507 GLsizei imageSize
, const GLvoid
*data
)
4509 GET_CURRENT_CONTEXT(ctx
);
4510 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4511 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4516 * Common helper for glCompressedTexSubImage1/2/3D() and
4517 * glCompressedTextureSubImage1/2/3D().
4520 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4521 struct gl_texture_object
*texObj
,
4522 struct gl_texture_image
*texImage
,
4523 GLenum target
, GLint level
,
4524 GLint xoffset
, GLint yoffset
,
4526 GLsizei width
, GLsizei height
,
4528 GLenum format
, GLsizei imageSize
,
4531 FLUSH_VERTICES(ctx
, 0);
4533 _mesa_lock_texture(ctx
, texObj
);
4535 if (width
> 0 && height
> 0 && depth
> 0) {
4536 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4537 xoffset
, yoffset
, zoffset
,
4538 width
, height
, depth
,
4539 format
, imageSize
, data
);
4541 check_gen_mipmap(ctx
, target
, texObj
, level
);
4543 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4544 * the texel data, not the texture format, size, etc.
4548 _mesa_unlock_texture(ctx
, texObj
);
4553 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4554 GLsizei width
, GLenum format
,
4555 GLsizei imageSize
, const GLvoid
*data
)
4557 struct gl_texture_object
*texObj
;
4558 struct gl_texture_image
*texImage
;
4560 GET_CURRENT_CONTEXT(ctx
);
4562 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4563 "glCompressedTexSubImage1D")) {
4567 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4571 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4572 level
, xoffset
, 0, 0,
4574 format
, imageSize
, data
,
4575 "glCompressedTexSubImage1D")) {
4579 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4582 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4583 xoffset
, 0, 0, width
, 1, 1,
4584 format
, imageSize
, data
);
4588 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4589 GLsizei width
, GLenum format
,
4590 GLsizei imageSize
, const GLvoid
*data
)
4592 struct gl_texture_object
*texObj
;
4593 struct gl_texture_image
*texImage
;
4595 GET_CURRENT_CONTEXT(ctx
);
4597 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4598 "glCompressedTextureSubImage1D");
4602 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4603 "glCompressedTextureSubImage1D")) {
4607 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4608 level
, xoffset
, 0, 0,
4610 format
, imageSize
, data
,
4611 "glCompressedTextureSubImage1D")) {
4615 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4618 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4619 texObj
->Target
, level
,
4620 xoffset
, 0, 0, width
, 1, 1,
4621 format
, imageSize
, data
);
4626 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4627 GLint yoffset
, GLsizei width
, GLsizei height
,
4628 GLenum format
, GLsizei imageSize
,
4631 struct gl_texture_object
*texObj
;
4632 struct gl_texture_image
*texImage
;
4634 GET_CURRENT_CONTEXT(ctx
);
4636 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4637 "glCompressedTexSubImage2D")) {
4641 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4645 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4646 level
, xoffset
, yoffset
, 0,
4648 format
, imageSize
, data
,
4649 "glCompressedTexSubImage2D")) {
4654 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4657 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4658 xoffset
, yoffset
, 0, width
, height
, 1,
4659 format
, imageSize
, data
);
4663 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4665 GLsizei width
, GLsizei height
,
4666 GLenum format
, GLsizei imageSize
,
4669 struct gl_texture_object
*texObj
;
4670 struct gl_texture_image
*texImage
;
4672 GET_CURRENT_CONTEXT(ctx
);
4674 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4675 "glCompressedTextureSubImage2D");
4679 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
4680 "glCompressedTextureSubImage2D")) {
4684 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4685 level
, xoffset
, yoffset
, 0,
4687 format
, imageSize
, data
,
4688 "glCompressedTextureSubImage2D")) {
4692 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4695 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4696 texObj
->Target
, level
,
4697 xoffset
, yoffset
, 0, width
, height
, 1,
4698 format
, imageSize
, data
);
4702 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4703 GLint yoffset
, GLint zoffset
, GLsizei width
,
4704 GLsizei height
, GLsizei depth
, GLenum format
,
4705 GLsizei imageSize
, const GLvoid
*data
)
4707 struct gl_texture_object
*texObj
;
4708 struct gl_texture_image
*texImage
;
4710 GET_CURRENT_CONTEXT(ctx
);
4712 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4713 "glCompressedTexSubImage3D")) {
4717 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4721 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4722 level
, xoffset
, yoffset
, zoffset
,
4723 width
, height
, depth
,
4724 format
, imageSize
, data
,
4725 "glCompressedTexSubImage3D")) {
4730 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4733 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4734 xoffset
, yoffset
, zoffset
,
4735 width
, height
, depth
,
4736 format
, imageSize
, data
);
4740 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4741 GLint yoffset
, GLint zoffset
, GLsizei width
,
4742 GLsizei height
, GLsizei depth
,
4743 GLenum format
, GLsizei imageSize
,
4746 struct gl_texture_object
*texObj
;
4747 struct gl_texture_image
*texImage
;
4749 GET_CURRENT_CONTEXT(ctx
);
4751 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4752 "glCompressedTextureSubImage3D");
4756 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
4757 "glCompressedTextureSubImage3D")) {
4761 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4762 level
, xoffset
, yoffset
, zoffset
,
4763 width
, height
, depth
,
4764 format
, imageSize
, data
,
4765 "glCompressedTextureSubImage3D")) {
4769 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4770 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4771 const char *pixels
= data
;
4775 /* Make sure the texture object is a proper cube.
4776 * (See texturesubimage in teximage.c for details on why this check is
4779 if (!_mesa_cube_level_complete(texObj
, level
)) {
4780 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4781 "glCompressedTextureSubImage3D(cube map incomplete)");
4785 /* Copy in each face. */
4786 for (i
= 0; i
< 6; ++i
) {
4787 texImage
= texObj
->Image
[i
][level
];
4790 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
4791 texObj
->Target
, level
,
4792 xoffset
, yoffset
, zoffset
,
4794 format
, imageSize
, pixels
);
4796 /* Compressed images don't have a client format */
4797 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
4799 texImage
->Height
, 1);
4801 pixels
+= image_stride
;
4802 imageSize
-= image_stride
;
4806 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4809 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
4810 texObj
->Target
, level
,
4811 xoffset
, yoffset
, zoffset
,
4812 width
, height
, depth
,
4813 format
, imageSize
, data
);
4818 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4820 if (ctx
->API
== API_OPENGL_COMPAT
) {
4821 switch (internalFormat
) {
4823 return MESA_FORMAT_A_UNORM8
;
4825 return MESA_FORMAT_A_UNORM16
;
4826 case GL_ALPHA16F_ARB
:
4827 return MESA_FORMAT_A_FLOAT16
;
4828 case GL_ALPHA32F_ARB
:
4829 return MESA_FORMAT_A_FLOAT32
;
4830 case GL_ALPHA8I_EXT
:
4831 return MESA_FORMAT_A_SINT8
;
4832 case GL_ALPHA16I_EXT
:
4833 return MESA_FORMAT_A_SINT16
;
4834 case GL_ALPHA32I_EXT
:
4835 return MESA_FORMAT_A_SINT32
;
4836 case GL_ALPHA8UI_EXT
:
4837 return MESA_FORMAT_A_UINT8
;
4838 case GL_ALPHA16UI_EXT
:
4839 return MESA_FORMAT_A_UINT16
;
4840 case GL_ALPHA32UI_EXT
:
4841 return MESA_FORMAT_A_UINT32
;
4843 return MESA_FORMAT_L_UNORM8
;
4844 case GL_LUMINANCE16
:
4845 return MESA_FORMAT_L_UNORM16
;
4846 case GL_LUMINANCE16F_ARB
:
4847 return MESA_FORMAT_L_FLOAT16
;
4848 case GL_LUMINANCE32F_ARB
:
4849 return MESA_FORMAT_L_FLOAT32
;
4850 case GL_LUMINANCE8I_EXT
:
4851 return MESA_FORMAT_L_SINT8
;
4852 case GL_LUMINANCE16I_EXT
:
4853 return MESA_FORMAT_L_SINT16
;
4854 case GL_LUMINANCE32I_EXT
:
4855 return MESA_FORMAT_L_SINT32
;
4856 case GL_LUMINANCE8UI_EXT
:
4857 return MESA_FORMAT_L_UINT8
;
4858 case GL_LUMINANCE16UI_EXT
:
4859 return MESA_FORMAT_L_UINT16
;
4860 case GL_LUMINANCE32UI_EXT
:
4861 return MESA_FORMAT_L_UINT32
;
4862 case GL_LUMINANCE8_ALPHA8
:
4863 return MESA_FORMAT_L8A8_UNORM
;
4864 case GL_LUMINANCE16_ALPHA16
:
4865 return MESA_FORMAT_L16A16_UNORM
;
4866 case GL_LUMINANCE_ALPHA16F_ARB
:
4867 return MESA_FORMAT_LA_FLOAT16
;
4868 case GL_LUMINANCE_ALPHA32F_ARB
:
4869 return MESA_FORMAT_LA_FLOAT32
;
4870 case GL_LUMINANCE_ALPHA8I_EXT
:
4871 return MESA_FORMAT_LA_SINT8
;
4872 case GL_LUMINANCE_ALPHA16I_EXT
:
4873 return MESA_FORMAT_LA_SINT16
;
4874 case GL_LUMINANCE_ALPHA32I_EXT
:
4875 return MESA_FORMAT_LA_SINT32
;
4876 case GL_LUMINANCE_ALPHA8UI_EXT
:
4877 return MESA_FORMAT_LA_UINT8
;
4878 case GL_LUMINANCE_ALPHA16UI_EXT
:
4879 return MESA_FORMAT_LA_UINT16
;
4880 case GL_LUMINANCE_ALPHA32UI_EXT
:
4881 return MESA_FORMAT_LA_UINT32
;
4883 return MESA_FORMAT_I_UNORM8
;
4884 case GL_INTENSITY16
:
4885 return MESA_FORMAT_I_UNORM16
;
4886 case GL_INTENSITY16F_ARB
:
4887 return MESA_FORMAT_I_FLOAT16
;
4888 case GL_INTENSITY32F_ARB
:
4889 return MESA_FORMAT_I_FLOAT32
;
4890 case GL_INTENSITY8I_EXT
:
4891 return MESA_FORMAT_I_SINT8
;
4892 case GL_INTENSITY16I_EXT
:
4893 return MESA_FORMAT_I_SINT16
;
4894 case GL_INTENSITY32I_EXT
:
4895 return MESA_FORMAT_I_SINT32
;
4896 case GL_INTENSITY8UI_EXT
:
4897 return MESA_FORMAT_I_UINT8
;
4898 case GL_INTENSITY16UI_EXT
:
4899 return MESA_FORMAT_I_UINT16
;
4900 case GL_INTENSITY32UI_EXT
:
4901 return MESA_FORMAT_I_UINT32
;
4907 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
4908 _mesa_has_OES_texture_buffer(ctx
)) {
4909 switch (internalFormat
) {
4911 return MESA_FORMAT_RGB_FLOAT32
;
4913 return MESA_FORMAT_RGB_UINT32
;
4915 return MESA_FORMAT_RGB_SINT32
;
4921 switch (internalFormat
) {
4923 return MESA_FORMAT_R8G8B8A8_UNORM
;
4925 if (_mesa_is_gles(ctx
))
4926 return MESA_FORMAT_NONE
;
4927 return MESA_FORMAT_RGBA_UNORM16
;
4928 case GL_RGBA16F_ARB
:
4929 return MESA_FORMAT_RGBA_FLOAT16
;
4930 case GL_RGBA32F_ARB
:
4931 return MESA_FORMAT_RGBA_FLOAT32
;
4933 return MESA_FORMAT_RGBA_SINT8
;
4934 case GL_RGBA16I_EXT
:
4935 return MESA_FORMAT_RGBA_SINT16
;
4936 case GL_RGBA32I_EXT
:
4937 return MESA_FORMAT_RGBA_SINT32
;
4938 case GL_RGBA8UI_EXT
:
4939 return MESA_FORMAT_RGBA_UINT8
;
4940 case GL_RGBA16UI_EXT
:
4941 return MESA_FORMAT_RGBA_UINT16
;
4942 case GL_RGBA32UI_EXT
:
4943 return MESA_FORMAT_RGBA_UINT32
;
4946 return MESA_FORMAT_R8G8_UNORM
;
4948 if (_mesa_is_gles(ctx
))
4949 return MESA_FORMAT_NONE
;
4950 return MESA_FORMAT_R16G16_UNORM
;
4952 return MESA_FORMAT_RG_FLOAT16
;
4954 return MESA_FORMAT_RG_FLOAT32
;
4956 return MESA_FORMAT_RG_SINT8
;
4958 return MESA_FORMAT_RG_SINT16
;
4960 return MESA_FORMAT_RG_SINT32
;
4962 return MESA_FORMAT_RG_UINT8
;
4964 return MESA_FORMAT_RG_UINT16
;
4966 return MESA_FORMAT_RG_UINT32
;
4969 return MESA_FORMAT_R_UNORM8
;
4971 if (_mesa_is_gles(ctx
))
4972 return MESA_FORMAT_NONE
;
4973 return MESA_FORMAT_R_UNORM16
;
4975 return MESA_FORMAT_R_FLOAT16
;
4977 return MESA_FORMAT_R_FLOAT32
;
4979 return MESA_FORMAT_R_SINT8
;
4981 return MESA_FORMAT_R_SINT16
;
4983 return MESA_FORMAT_R_SINT32
;
4985 return MESA_FORMAT_R_UINT8
;
4987 return MESA_FORMAT_R_UINT16
;
4989 return MESA_FORMAT_R_UINT32
;
4992 return MESA_FORMAT_NONE
;
4998 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4999 GLenum internalFormat
)
5001 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5004 if (format
== MESA_FORMAT_NONE
)
5005 return MESA_FORMAT_NONE
;
5007 datatype
= _mesa_get_format_datatype(format
);
5009 /* The GL_ARB_texture_buffer_object spec says:
5011 * "If ARB_texture_float is not supported, references to the
5012 * floating-point internal formats provided by that extension should be
5013 * removed, and such formats may not be passed to TexBufferARB."
5015 * As a result, GL_HALF_FLOAT internal format depends on both
5016 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5018 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5019 !ctx
->Extensions
.ARB_texture_float
)
5020 return MESA_FORMAT_NONE
;
5022 if (!ctx
->Extensions
.ARB_texture_rg
) {
5023 GLenum base_format
= _mesa_get_format_base_format(format
);
5024 if (base_format
== GL_R
|| base_format
== GL_RG
)
5025 return MESA_FORMAT_NONE
;
5028 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5029 GLenum base_format
= _mesa_get_format_base_format(format
);
5030 if (base_format
== GL_RGB
)
5031 return MESA_FORMAT_NONE
;
5038 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5039 * and glTextureBufferRange, including some error checking.
5042 texture_buffer_range(struct gl_context
*ctx
,
5043 struct gl_texture_object
*texObj
,
5044 GLenum internalFormat
,
5045 struct gl_buffer_object
*bufObj
,
5046 GLintptr offset
, GLsizeiptr size
,
5049 GLintptr oldOffset
= texObj
->BufferOffset
;
5050 GLsizeiptr oldSize
= texObj
->BufferSize
;
5053 /* NOTE: ARB_texture_buffer_object has interactions with
5054 * the compatibility profile that are not implemented.
5056 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5057 !_mesa_has_OES_texture_buffer(ctx
)) {
5058 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5059 "%s(ARB_texture_buffer_object is not"
5060 " implemented for the compatibility profile)", caller
);
5064 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5065 if (format
== MESA_FORMAT_NONE
) {
5066 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5067 caller
, _mesa_enum_to_string(internalFormat
));
5071 FLUSH_VERTICES(ctx
, 0);
5073 _mesa_lock_texture(ctx
, texObj
);
5075 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5076 texObj
->BufferObjectFormat
= internalFormat
;
5077 texObj
->_BufferObjectFormat
= format
;
5078 texObj
->BufferOffset
= offset
;
5079 texObj
->BufferSize
= size
;
5081 _mesa_unlock_texture(ctx
, texObj
);
5083 if (ctx
->Driver
.TexParameter
) {
5084 if (offset
!= oldOffset
) {
5085 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5087 if (size
!= oldSize
) {
5088 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5092 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5095 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5101 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5102 * Return true if it is, and return false if it is not
5103 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5104 * core spec, 02.02.2015, PDF page 245).
5107 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5110 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5111 _mesa_error(ctx
, GL_INVALID_ENUM
,
5112 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5120 * Check for errors related to the texture buffer range.
5121 * Return false if errors are found, true if none are found.
5124 check_texture_buffer_range(struct gl_context
*ctx
,
5125 struct gl_buffer_object
*bufObj
,
5126 GLintptr offset
, GLsizeiptr size
,
5129 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5130 * Textures (PDF page 245):
5131 * "An INVALID_VALUE error is generated if offset is negative, if
5132 * size is less than or equal to zero, or if offset + size is greater
5133 * than the value of BUFFER_SIZE for the buffer bound to target."
5136 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5142 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5147 if (offset
+ size
> bufObj
->Size
) {
5148 _mesa_error(ctx
, GL_INVALID_VALUE
,
5149 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5150 (int) offset
, (int) size
, (int) bufObj
->Size
);
5154 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5155 * Textures (PDF page 245):
5156 * "An INVALID_VALUE error is generated if offset is not an integer
5157 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5159 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5160 _mesa_error(ctx
, GL_INVALID_VALUE
,
5161 "%s(invalid offset alignment)", caller
);
5169 /** GL_ARB_texture_buffer_object */
5171 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5173 struct gl_texture_object
*texObj
;
5174 struct gl_buffer_object
*bufObj
;
5176 GET_CURRENT_CONTEXT(ctx
);
5178 /* Need to catch a bad target before it gets to
5179 * _mesa_get_current_tex_object.
5181 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5185 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5191 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5195 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5196 buffer
? -1 : 0, "glTexBuffer");
5200 /** GL_ARB_texture_buffer_range */
5202 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5203 GLintptr offset
, GLsizeiptr size
)
5205 struct gl_texture_object
*texObj
;
5206 struct gl_buffer_object
*bufObj
;
5208 GET_CURRENT_CONTEXT(ctx
);
5210 /* Need to catch a bad target before it gets to
5211 * _mesa_get_current_tex_object.
5213 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5217 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5221 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5222 "glTexBufferRange"))
5226 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5227 * Textures (PDF page 254):
5228 * "If buffer is zero, then any buffer object attached to the buffer
5229 * texture is detached, the values offset and size are ignored and
5230 * the state for offset and size for the buffer texture are reset to
5238 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5242 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5243 offset
, size
, "glTexBufferRange");
5247 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5249 struct gl_texture_object
*texObj
;
5250 struct gl_buffer_object
*bufObj
;
5252 GET_CURRENT_CONTEXT(ctx
);
5255 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5261 /* Get the texture object by Name. */
5262 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5266 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5269 texture_buffer_range(ctx
, texObj
, internalFormat
,
5270 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5274 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5275 GLintptr offset
, GLsizeiptr size
)
5277 struct gl_texture_object
*texObj
;
5278 struct gl_buffer_object
*bufObj
;
5280 GET_CURRENT_CONTEXT(ctx
);
5283 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5284 "glTextureBufferRange");
5288 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5289 "glTextureBufferRange"))
5293 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5294 * Textures (PDF page 254):
5295 * "If buffer is zero, then any buffer object attached to the buffer
5296 * texture is detached, the values offset and size are ignored and
5297 * the state for offset and size for the buffer texture are reset to
5305 /* Get the texture object by Name. */
5306 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5310 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5311 "glTextureBufferRange"))
5314 texture_buffer_range(ctx
, texObj
, internalFormat
,
5315 bufObj
, offset
, size
, "glTextureBufferRange");
5319 _mesa_is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5321 /* Everything that is allowed for renderbuffers,
5322 * except for a base format of GL_STENCIL_INDEX, unless supported.
5324 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5325 if (ctx
->Extensions
.ARB_texture_stencil8
)
5326 return baseFormat
!= 0;
5328 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5332 /** GL_ARB_texture_multisample */
5334 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5337 case GL_TEXTURE_2D_MULTISAMPLE
:
5339 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5340 return dims
== 2 && !dsa
;
5341 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5343 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5344 return dims
== 3 && !dsa
;
5352 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5353 struct gl_texture_object
*texObj
,
5354 GLenum target
, GLsizei samples
,
5355 GLint internalformat
, GLsizei width
,
5356 GLsizei height
, GLsizei depth
,
5357 GLboolean fixedsamplelocations
,
5358 GLboolean immutable
, const char *func
)
5360 struct gl_texture_image
*texImage
;
5361 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5362 mesa_format texFormat
;
5363 GLenum sample_count_error
;
5364 bool dsa
= strstr(func
, "ture") ? true : false;
5366 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5367 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5368 _mesa_enum_to_string(target
), samples
);
5371 if (!((ctx
->Extensions
.ARB_texture_multisample
5372 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5373 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5378 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5382 if (!check_multisample_target(dims
, target
, dsa
)) {
5384 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5388 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5393 /* check that the specified internalformat is color/depth/stencil-renderable;
5394 * refer GL3.1 spec 4.4.4
5397 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5398 _mesa_error(ctx
, GL_INVALID_ENUM
,
5399 "%s(internalformat=%s not legal for immutable-format)",
5400 func
, _mesa_enum_to_string(internalformat
));
5404 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5405 /* Page 172 of OpenGL ES 3.1 spec says:
5406 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5407 * color-renderable, depth-renderable, or stencil-renderable (as
5408 * defined in section 9.4).
5410 * (Same error is also defined for desktop OpenGL for multisample
5411 * teximage/texstorage functions.)
5413 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5414 _mesa_enum_to_string(internalformat
));
5418 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5419 internalformat
, samples
);
5420 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5422 /* Page 254 of OpenGL 4.4 spec says:
5423 * "Proxy arrays for two-dimensional multisample and two-dimensional
5424 * multisample array textures are operated on in the same way when
5425 * TexImage2DMultisample is called with target specified as
5426 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5427 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5428 * However, if samples is not supported, then no error is generated.
5430 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5431 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5435 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5437 "%s(texture object 0)",
5442 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5444 if (texImage
== NULL
) {
5445 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5449 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5450 internalformat
, GL_NONE
, GL_NONE
);
5451 assert(texFormat
!= MESA_FORMAT_NONE
);
5453 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5454 width
, height
, depth
, 0);
5456 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5457 samples
, width
, height
, depth
);
5459 if (_mesa_is_proxy_texture(target
)) {
5460 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5461 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5462 internalformat
, texFormat
,
5463 samples
, fixedsamplelocations
);
5466 /* clear all image fields */
5467 clear_teximage_fields(texImage
);
5471 if (!dimensionsOK
) {
5472 _mesa_error(ctx
, GL_INVALID_VALUE
,
5473 "%s(invalid width or height)", func
);
5478 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5482 /* Check if texObj->Immutable is set */
5483 if (texObj
->Immutable
) {
5484 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5488 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5490 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5491 internalformat
, texFormat
,
5492 samples
, fixedsamplelocations
);
5494 if (width
> 0 && height
> 0 && depth
> 0) {
5495 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5496 width
, height
, depth
)) {
5497 /* tidy up the texture image state. strictly speaking,
5498 * we're allowed to just leave this in whatever state we
5499 * like, but being tidy is good.
5501 _mesa_init_teximage_fields(ctx
, texImage
,
5502 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5506 texObj
->Immutable
|= immutable
;
5509 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5512 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5518 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5519 GLenum internalformat
, GLsizei width
,
5520 GLsizei height
, GLboolean fixedsamplelocations
)
5522 struct gl_texture_object
*texObj
;
5523 GET_CURRENT_CONTEXT(ctx
);
5525 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5529 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5530 internalformat
, width
, height
, 1,
5531 fixedsamplelocations
, GL_FALSE
,
5532 "glTexImage2DMultisample");
5537 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5538 GLenum internalformat
, GLsizei width
,
5539 GLsizei height
, GLsizei depth
,
5540 GLboolean fixedsamplelocations
)
5542 struct gl_texture_object
*texObj
;
5543 GET_CURRENT_CONTEXT(ctx
);
5545 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5549 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5550 internalformat
, width
, height
, depth
,
5551 fixedsamplelocations
, GL_FALSE
,
5552 "glTexImage3DMultisample");
5556 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5557 GLsizei samples
, unsigned dims
)
5559 GET_CURRENT_CONTEXT(ctx
);
5561 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5562 _mesa_error(ctx
, GL_INVALID_VALUE
,
5563 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5564 dims
, width
, height
, depth
);
5571 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5572 GLenum internalformat
, GLsizei width
,
5573 GLsizei height
, GLboolean fixedsamplelocations
)
5575 struct gl_texture_object
*texObj
;
5576 GET_CURRENT_CONTEXT(ctx
);
5578 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5582 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5585 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5586 internalformat
, width
, height
, 1,
5587 fixedsamplelocations
, GL_TRUE
,
5588 "glTexStorage2DMultisample");
5592 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5593 GLenum internalformat
, GLsizei width
,
5594 GLsizei height
, GLsizei depth
,
5595 GLboolean fixedsamplelocations
)
5597 struct gl_texture_object
*texObj
;
5598 GET_CURRENT_CONTEXT(ctx
);
5600 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5604 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5607 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5608 internalformat
, width
, height
, depth
,
5609 fixedsamplelocations
, GL_TRUE
,
5610 "glTexStorage3DMultisample");
5614 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5615 GLenum internalformat
, GLsizei width
,
5617 GLboolean fixedsamplelocations
)
5619 struct gl_texture_object
*texObj
;
5620 GET_CURRENT_CONTEXT(ctx
);
5622 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5623 "glTextureStorage2DMultisample");
5627 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5630 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5631 internalformat
, width
, height
, 1,
5632 fixedsamplelocations
, GL_TRUE
,
5633 "glTextureStorage2DMultisample");
5637 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5638 GLenum internalformat
, GLsizei width
,
5639 GLsizei height
, GLsizei depth
,
5640 GLboolean fixedsamplelocations
)
5642 struct gl_texture_object
*texObj
;
5643 GET_CURRENT_CONTEXT(ctx
);
5645 /* Get the texture object by Name. */
5646 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5647 "glTextureStorage3DMultisample");
5651 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5654 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5655 internalformat
, width
, height
, depth
,
5656 fixedsamplelocations
, GL_TRUE
,
5657 "glTextureStorage3DMultisample");