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_ETC1_RGB8_OES
:
1326 case GL_PALETTE4_RGB8_OES
:
1327 case GL_PALETTE4_RGBA8_OES
:
1328 case GL_PALETTE4_R5_G6_B5_OES
:
1329 case GL_PALETTE4_RGBA4_OES
:
1330 case GL_PALETTE4_RGB5_A1_OES
:
1331 case GL_PALETTE8_RGB8_OES
:
1332 case GL_PALETTE8_RGBA8_OES
:
1333 case GL_PALETTE8_R5_G6_B5_OES
:
1334 case GL_PALETTE8_RGBA4_OES
:
1335 case GL_PALETTE8_RGB5_A1_OES
:
1343 * Return true if the format doesn't support online compression.
1346 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1348 return _mesa_is_astc_format(format
) ||
1349 _mesa_is_etc2_format(format
) ||
1350 compressedteximage_only_format(ctx
, format
);
1353 /* Writes to an GL error pointer if non-null and returns whether or not the
1354 * error is GL_NO_ERROR */
1356 write_error(GLenum
*err_ptr
, GLenum error
)
1361 return error
== GL_NO_ERROR
;
1365 * Helper function to determine whether a target and specific compression
1366 * format are supported. The error parameter returns GL_NO_ERROR if the
1367 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1368 * or GL_INVALID_ENUM, whichever is more appropriate.
1371 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1372 GLenum intFormat
, GLenum
*error
)
1374 GLboolean target_can_be_compresed
= GL_FALSE
;
1375 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1376 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1380 case GL_PROXY_TEXTURE_2D
:
1381 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1383 case GL_PROXY_TEXTURE_CUBE_MAP
:
1384 case GL_TEXTURE_CUBE_MAP
:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1391 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1393 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1394 case GL_TEXTURE_2D_ARRAY_EXT
:
1395 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1397 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1398 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1399 /* From the KHR_texture_compression_astc_hdr spec:
1401 * Add a second new column "3D Tex." which is empty for all non-ASTC
1402 * formats. If only the LDR profile is supported by the
1403 * implementation, this column is also empty for all ASTC formats. If
1404 * both the LDR and HDR profiles are supported only, this column is
1405 * checked for all ASTC formats.
1407 * Add a third new column "Cube Map Array Tex." which is empty for all
1408 * non-ASTC formats, and checked for all ASTC formats.
1412 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1413 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1414 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1415 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1416 * 8.19 is *not* checked'
1418 * The instances of <internalformat> above should say <target>.
1420 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1421 * have already been handled by normal ETC2/EAC behavior.
1424 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1426 * "The ETC2/EAC texture compression algorithm supports only
1427 * two-dimensional images. If internalformat is an ETC2/EAC format,
1428 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1429 * target is not TEXTURE_2D_ARRAY."
1431 * This should also be applicable for glTexStorage3D(). Other available
1432 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1434 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1435 return write_error(error
, GL_INVALID_OPERATION
);
1436 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1440 case MESA_FORMAT_LAYOUT_ETC2
:
1441 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1442 if (_mesa_is_gles3(ctx
))
1443 return write_error(error
, GL_INVALID_OPERATION
);
1445 case MESA_FORMAT_LAYOUT_BPTC
:
1446 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1448 case MESA_FORMAT_LAYOUT_ASTC
:
1449 target_can_be_compresed
=
1450 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1451 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1453 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1454 * neither of the above extensions are supported. See comment in
1455 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1457 if (!target_can_be_compresed
)
1458 return write_error(error
, GL_INVALID_OPERATION
);
1466 return write_error(error
,
1467 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1472 * Check if the given texture target value is legal for a
1473 * glTexImage1/2/3D call.
1476 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1482 case GL_PROXY_TEXTURE_1D
:
1483 return _mesa_is_desktop_gl(ctx
);
1491 case GL_PROXY_TEXTURE_2D
:
1492 return _mesa_is_desktop_gl(ctx
);
1493 case GL_PROXY_TEXTURE_CUBE_MAP
:
1494 return _mesa_is_desktop_gl(ctx
)
1495 && ctx
->Extensions
.ARB_texture_cube_map
;
1496 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1497 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1498 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1499 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1500 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1501 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1502 return ctx
->Extensions
.ARB_texture_cube_map
;
1503 case GL_TEXTURE_RECTANGLE_NV
:
1504 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1505 return _mesa_is_desktop_gl(ctx
)
1506 && ctx
->Extensions
.NV_texture_rectangle
;
1507 case GL_TEXTURE_1D_ARRAY_EXT
:
1508 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1509 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1517 case GL_PROXY_TEXTURE_3D
:
1518 return _mesa_is_desktop_gl(ctx
);
1519 case GL_TEXTURE_2D_ARRAY_EXT
:
1520 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1521 || _mesa_is_gles3(ctx
);
1522 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1523 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1524 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1525 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1526 return _mesa_has_texture_cube_map_array(ctx
);
1531 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1538 * Check if the given texture target value is legal for a
1539 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1540 * The difference compared to legal_teximage_target() above is that
1541 * proxy targets are not supported.
1544 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1549 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1554 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1555 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1556 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1557 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1558 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1559 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1560 return ctx
->Extensions
.ARB_texture_cube_map
;
1561 case GL_TEXTURE_RECTANGLE_NV
:
1562 return _mesa_is_desktop_gl(ctx
)
1563 && ctx
->Extensions
.NV_texture_rectangle
;
1564 case GL_TEXTURE_1D_ARRAY_EXT
:
1565 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1573 case GL_TEXTURE_2D_ARRAY_EXT
:
1574 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1575 || _mesa_is_gles3(ctx
);
1576 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1577 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1578 return _mesa_has_texture_cube_map_array(ctx
);
1580 /* Table 8.15 of the OpenGL 4.5 core profile spec
1581 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1582 * and CopyTextureSubImage3D.
1584 case GL_TEXTURE_CUBE_MAP
:
1590 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1598 * Helper function to determine if a texture object is mutable (in terms
1599 * of GL_ARB_texture_storage).
1602 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1604 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1608 return !texObj
->Immutable
;
1613 * Return expected size of a compressed texture.
1616 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1619 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1620 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1624 * Verify that a texture format is valid with a particular target
1626 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1627 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1630 * \param ctx GL context
1631 * \param target Texture target
1632 * \param internalFormat Internal format of the texture image
1634 * \returns true if the combination is legal, false otherwise.
1637 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1638 GLenum target
, GLenum internalFormat
)
1640 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1641 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1642 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1643 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1644 * Profile spec says:
1646 * "Textures with a base internal format of DEPTH_COMPONENT or
1647 * DEPTH_STENCIL are supported by texture image specification
1648 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1649 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1650 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1651 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1652 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1653 * formats in conjunction with any other target will result in an
1654 * INVALID_OPERATION error."
1656 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1657 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1659 if (target
!= GL_TEXTURE_1D
&&
1660 target
!= GL_PROXY_TEXTURE_1D
&&
1661 target
!= GL_TEXTURE_2D
&&
1662 target
!= GL_PROXY_TEXTURE_2D
&&
1663 target
!= GL_TEXTURE_1D_ARRAY
&&
1664 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1665 target
!= GL_TEXTURE_2D_ARRAY
&&
1666 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1667 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1668 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1669 !((_mesa_is_cube_face(target
) ||
1670 target
== GL_TEXTURE_CUBE_MAP
||
1671 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1672 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1673 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1674 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1675 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1676 _mesa_has_texture_cube_map_array(ctx
))) {
1685 texture_formats_agree(GLenum internalFormat
,
1688 GLboolean colorFormat
;
1689 GLboolean is_format_depth_or_depthstencil
;
1690 GLboolean is_internalFormat_depth_or_depthstencil
;
1692 /* Even though there are no color-index textures, we still have to support
1693 * uploading color-index data and remapping it to RGB via the
1694 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1696 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1698 is_internalFormat_depth_or_depthstencil
=
1699 _mesa_is_depth_format(internalFormat
) ||
1700 _mesa_is_depthstencil_format(internalFormat
);
1702 is_format_depth_or_depthstencil
=
1703 _mesa_is_depth_format(format
) ||
1704 _mesa_is_depthstencil_format(format
);
1706 colorFormat
= _mesa_is_color_format(format
);
1708 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1711 if (is_internalFormat_depth_or_depthstencil
!=
1712 is_format_depth_or_depthstencil
)
1715 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1722 * Test the combination of format, type and internal format arguments of
1723 * different texture operations on GLES.
1725 * \param ctx GL context.
1726 * \param format pixel data format given by the user.
1727 * \param type pixel data type given by the user.
1728 * \param internalFormat internal format given by the user.
1729 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1730 * \param callerName name of the caller function to print in the error message
1732 * \return true if a error is found, false otherwise
1734 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1737 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1738 GLenum type
, GLenum internalFormat
,
1739 GLuint dimensions
, const char *callerName
)
1743 if (_mesa_is_gles3(ctx
)) {
1744 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
1746 if (err
!= GL_NO_ERROR
) {
1747 _mesa_error(ctx
, err
,
1748 "%s(format = %s, type = %s, internalformat = %s)",
1749 callerName
, _mesa_enum_to_string(format
),
1750 _mesa_enum_to_string(type
),
1751 _mesa_enum_to_string(internalFormat
));
1756 err
= _mesa_es_error_check_format_and_type(ctx
, format
, type
, dimensions
);
1757 if (err
!= GL_NO_ERROR
) {
1758 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
1759 callerName
, _mesa_enum_to_string(format
),
1760 _mesa_enum_to_string(type
));
1769 * Test the glTexImage[123]D() parameters for errors.
1771 * \param ctx GL context.
1772 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1773 * \param target texture target given by the user (already validated).
1774 * \param level image level given by the user.
1775 * \param internalFormat internal format given by the user.
1776 * \param format pixel data format given by the user.
1777 * \param type pixel data type given by the user.
1778 * \param width image width given by the user.
1779 * \param height image height given by the user.
1780 * \param depth image depth given by the user.
1781 * \param border image border given by the user.
1783 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1785 * Verifies each of the parameters against the constants specified in
1786 * __struct gl_contextRec::Const and the supported extensions, and according
1787 * to the OpenGL specification.
1788 * Note that we don't fully error-check the width, height, depth values
1789 * here. That's done in _mesa_legal_texture_dimensions() which is used
1790 * by several other GL entrypoints. Plus, texture dims have a special
1791 * interaction with proxy textures.
1794 texture_error_check( struct gl_context
*ctx
,
1795 GLuint dimensions
, GLenum target
,
1796 GLint level
, GLint internalFormat
,
1797 GLenum format
, GLenum type
,
1798 GLint width
, GLint height
,
1799 GLint depth
, GLint border
,
1800 const GLvoid
*pixels
)
1804 /* Note: for proxy textures, some error conditions immediately generate
1805 * a GL error in the usual way. But others do not generate a GL error.
1806 * Instead, they cause the width, height, depth, format fields of the
1807 * texture image to be zeroed-out. The GL spec seems to indicate that the
1808 * zero-out behaviour is only used in cases related to memory allocation.
1812 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
,
1814 "glTexImage%dD(level=%d)", dimensions
, level
);
1819 if (border
< 0 || border
> 1 ||
1820 ((ctx
->API
!= API_OPENGL_COMPAT
||
1821 target
== GL_TEXTURE_RECTANGLE_NV
||
1822 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1823 _mesa_error(ctx
, GL_INVALID_VALUE
,
1824 "glTexImage%dD(border=%d)", dimensions
, border
);
1828 if (width
< 0 || height
< 0 || depth
< 0) {
1829 _mesa_error(ctx
, GL_INVALID_VALUE
,
1830 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1834 /* Check incoming image format and type */
1835 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1836 if (err
!= GL_NO_ERROR
) {
1837 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1838 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1840 * "Specifying a value for internalformat that is not one of the
1841 * above (acceptable) values generates the error INVALID VALUE."
1843 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1844 err
= GL_INVALID_VALUE
;
1846 _mesa_error(ctx
, err
,
1847 "glTexImage%dD(incompatible format = %s, type = %s)",
1848 dimensions
, _mesa_enum_to_string(format
),
1849 _mesa_enum_to_string(type
));
1853 /* Check internalFormat */
1854 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1855 _mesa_error(ctx
, GL_INVALID_VALUE
,
1856 "glTexImage%dD(internalFormat=%s)",
1857 dimensions
, _mesa_enum_to_string(internalFormat
));
1861 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1862 * combinations of format, internalFormat, and type that can be used.
1863 * Formats and types that require additional extensions (e.g., GL_FLOAT
1864 * requires GL_OES_texture_float) are filtered elsewhere.
1866 if (_mesa_is_gles(ctx
) &&
1867 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
1868 dimensions
, "glTexImage%dD")) {
1872 /* validate the bound PBO, if any */
1873 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1874 width
, height
, depth
, format
, type
,
1875 INT_MAX
, pixels
, "glTexImage")) {
1879 /* make sure internal format and format basically agree */
1880 if (!texture_formats_agree(internalFormat
, format
)) {
1881 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1882 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1883 dimensions
, _mesa_enum_to_string(internalFormat
),
1884 _mesa_enum_to_string(format
));
1888 /* additional checks for ycbcr textures */
1889 if (internalFormat
== GL_YCBCR_MESA
) {
1890 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1891 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1892 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1894 _mesa_snprintf(message
, sizeof(message
),
1895 "glTexImage%dD(format/type YCBCR mismatch)",
1897 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1898 return GL_TRUE
; /* error */
1900 if (target
!= GL_TEXTURE_2D
&&
1901 target
!= GL_PROXY_TEXTURE_2D
&&
1902 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1903 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1904 _mesa_error(ctx
, GL_INVALID_ENUM
,
1905 "glTexImage%dD(bad target for YCbCr texture)",
1911 _mesa_snprintf(message
, sizeof(message
),
1912 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1913 dimensions
, border
);
1914 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1919 /* additional checks for depth textures */
1920 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1921 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1922 "glTexImage%dD(bad target for texture)", dimensions
);
1926 /* additional checks for compressed textures */
1927 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1929 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1930 _mesa_error(ctx
, err
,
1931 "glTexImage%dD(target can't be compressed)", dimensions
);
1934 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
1935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1936 "glTexImage%dD(no compression for format)", dimensions
);
1940 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1941 "glTexImage%dD(border!=0)", dimensions
);
1946 /* additional checks for integer textures */
1947 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1948 (_mesa_is_enum_format_integer(format
) !=
1949 _mesa_is_enum_format_integer(internalFormat
))) {
1950 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1951 "glTexImage%dD(integer/non-integer format mismatch)",
1956 if (!mutable_tex_object(ctx
, target
)) {
1957 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1958 "glTexImage%dD(immutable texture)", dimensions
);
1962 /* if we get here, the parameters are OK */
1968 * Error checking for glCompressedTexImage[123]D().
1969 * Note that the width, height and depth values are not fully error checked
1971 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1974 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
1975 GLenum target
, GLint level
,
1976 GLenum internalFormat
, GLsizei width
,
1977 GLsizei height
, GLsizei depth
, GLint border
,
1978 GLsizei imageSize
, const GLvoid
*data
)
1980 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1982 GLenum error
= GL_NO_ERROR
;
1983 char *reason
= ""; /* no error */
1985 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
1990 /* This will detect any invalid internalFormat value */
1991 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
1992 _mesa_error(ctx
, GL_INVALID_ENUM
,
1993 "glCompressedTexImage%dD(internalFormat=%s)",
1994 dimensions
, _mesa_enum_to_string(internalFormat
));
1998 /* validate the bound PBO, if any */
1999 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2001 "glCompressedTexImage")) {
2005 switch (internalFormat
) {
2006 case GL_PALETTE4_RGB8_OES
:
2007 case GL_PALETTE4_RGBA8_OES
:
2008 case GL_PALETTE4_R5_G6_B5_OES
:
2009 case GL_PALETTE4_RGBA4_OES
:
2010 case GL_PALETTE4_RGB5_A1_OES
:
2011 case GL_PALETTE8_RGB8_OES
:
2012 case GL_PALETTE8_RGBA8_OES
:
2013 case GL_PALETTE8_R5_G6_B5_OES
:
2014 case GL_PALETTE8_RGBA4_OES
:
2015 case GL_PALETTE8_RGB5_A1_OES
:
2016 /* check level (note that level should be zero or less!) */
2017 if (level
> 0 || level
< -maxLevels
) {
2019 error
= GL_INVALID_VALUE
;
2023 if (dimensions
!= 2) {
2024 reason
= "compressed paletted textures must be 2D";
2025 error
= GL_INVALID_OPERATION
;
2029 /* Figure out the expected texture size (in bytes). This will be
2030 * checked against the actual size later.
2032 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2035 /* This is for the benefit of the TestProxyTexImage below. It expects
2036 * level to be non-negative. OES_compressed_paletted_texture uses a
2037 * weird mechanism where the level specified to glCompressedTexImage2D
2038 * is -(n-1) number of levels in the texture, and the data specifies the
2039 * complete mipmap stack. This is done to ensure the palette is the
2040 * same for all levels.
2047 if (level
< 0 || level
>= maxLevels
) {
2049 error
= GL_INVALID_VALUE
;
2053 /* Figure out the expected texture size (in bytes). This will be
2054 * checked against the actual size later.
2056 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2060 /* This should really never fail */
2061 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2062 reason
= "internalFormat";
2063 error
= GL_INVALID_ENUM
;
2067 /* No compressed formats support borders at this time */
2069 reason
= "border != 0";
2070 error
= GL_INVALID_VALUE
;
2074 /* Check for invalid pixel storage modes */
2075 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2077 "glCompressedTexImage")) {
2081 /* check image size in bytes */
2082 if (expectedSize
!= imageSize
) {
2083 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2084 * if <imageSize> is not consistent with the format, dimensions, and
2085 * contents of the specified image.
2087 reason
= "imageSize inconsistent with width/height/format";
2088 error
= GL_INVALID_VALUE
;
2092 if (!mutable_tex_object(ctx
, target
)) {
2093 reason
= "immutable texture";
2094 error
= GL_INVALID_OPERATION
;
2101 /* Note: not all error paths exit through here. */
2102 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2103 dimensions
, reason
);
2110 * Test glTexSubImage[123]D() parameters for errors.
2112 * \param ctx GL context.
2113 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2114 * \param target texture target given by the user (already validated)
2115 * \param level image level given by the user.
2116 * \param xoffset sub-image x offset given by the user.
2117 * \param yoffset sub-image y offset given by the user.
2118 * \param zoffset sub-image z offset given by the user.
2119 * \param format pixel data format given by the user.
2120 * \param type pixel data type given by the user.
2121 * \param width image width given by the user.
2122 * \param height image height given by the user.
2123 * \param depth image depth given by the user.
2125 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2127 * Verifies each of the parameters against the constants specified in
2128 * __struct gl_contextRec::Const and the supported extensions, and according
2129 * to the OpenGL specification.
2132 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2133 struct gl_texture_object
*texObj
,
2134 GLenum target
, GLint level
,
2135 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2136 GLint width
, GLint height
, GLint depth
,
2137 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2138 bool dsa
, const char *callerName
)
2140 struct gl_texture_image
*texImage
;
2144 /* must be out of memory */
2145 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2150 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2155 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2156 width
, height
, depth
,
2161 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2163 /* non-existant texture level */
2164 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2169 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2170 if (err
!= GL_NO_ERROR
) {
2171 _mesa_error(ctx
, err
,
2172 "%s(incompatible format = %s, type = %s)",
2173 callerName
, _mesa_enum_to_string(format
),
2174 _mesa_enum_to_string(type
));
2178 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2179 * combinations of format, internalFormat, and type that can be used.
2180 * Formats and types that require additional extensions (e.g., GL_FLOAT
2181 * requires GL_OES_texture_float) are filtered elsewhere.
2183 if (_mesa_is_gles(ctx
) &&
2184 texture_format_error_check_gles(ctx
, format
, type
,
2185 texImage
->InternalFormat
,
2186 dimensions
, callerName
)) {
2190 /* validate the bound PBO, if any */
2191 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2192 width
, height
, depth
, format
, type
,
2193 INT_MAX
, pixels
, callerName
)) {
2197 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2198 texImage
, xoffset
, yoffset
, zoffset
,
2199 width
, height
, depth
, callerName
)) {
2203 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2204 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2206 "%s(no compression for format)", callerName
);
2211 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2212 /* both source and dest must be integer-valued, or neither */
2213 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2214 _mesa_is_enum_format_integer(format
)) {
2215 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2216 "%s(integer/non-integer format mismatch)", callerName
);
2226 * Test glCopyTexImage[12]D() parameters for errors.
2228 * \param ctx GL context.
2229 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2230 * \param target texture target given by the user.
2231 * \param level image level given by the user.
2232 * \param internalFormat internal format given by the user.
2233 * \param width image width given by the user.
2234 * \param height image height given by the user.
2235 * \param border texture border.
2237 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2239 * Verifies each of the parameters against the constants specified in
2240 * __struct gl_contextRec::Const and the supported extensions, and according
2241 * to the OpenGL specification.
2244 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2245 GLenum target
, GLint level
, GLint internalFormat
,
2246 GLint width
, GLint height
, GLint border
)
2249 GLint rb_base_format
;
2250 struct gl_renderbuffer
*rb
;
2251 GLenum rb_internal_format
;
2254 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2255 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2256 dimensions
, _mesa_enum_to_string(target
));
2261 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2262 _mesa_error(ctx
, GL_INVALID_VALUE
,
2263 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2267 /* Check that the source buffer is complete */
2268 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2269 if (ctx
->ReadBuffer
->_Status
== 0) {
2270 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2272 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2273 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2274 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2278 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2279 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2280 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2286 if (border
< 0 || border
> 1 ||
2287 ((ctx
->API
!= API_OPENGL_COMPAT
||
2288 target
== GL_TEXTURE_RECTANGLE_NV
||
2289 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2290 _mesa_error(ctx
, GL_INVALID_VALUE
,
2291 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2295 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2298 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2299 switch (internalFormat
) {
2304 case GL_LUMINANCE_ALPHA
:
2307 _mesa_error(ctx
, GL_INVALID_ENUM
,
2308 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2309 _mesa_enum_to_string(internalFormat
));
2314 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2315 * OpenGL 4.5 (Compatibility Profile) spec says:
2317 * "Parameters level, internalformat, and border are specified using
2318 * the same values, with the same meanings, as the corresponding
2319 * arguments of TexImage2D, except that internalformat may not be
2320 * specified as 1, 2, 3, or 4."
2322 if (internalFormat
>= 1 && internalFormat
<= 4) {
2323 _mesa_error(ctx
, GL_INVALID_ENUM
,
2324 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2330 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2331 if (baseFormat
< 0) {
2332 _mesa_error(ctx
, GL_INVALID_ENUM
,
2333 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2334 _mesa_enum_to_string(internalFormat
));
2338 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2341 "glCopyTexImage%dD(read buffer)", dimensions
);
2345 rb_internal_format
= rb
->InternalFormat
;
2346 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2347 if (_mesa_is_color_format(internalFormat
)) {
2348 if (rb_base_format
< 0) {
2349 _mesa_error(ctx
, GL_INVALID_VALUE
,
2350 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2351 _mesa_enum_to_string(internalFormat
));
2356 if (_mesa_is_gles(ctx
)) {
2358 if (_mesa_base_format_component_count(baseFormat
) >
2359 _mesa_base_format_component_count(rb_base_format
)) {
2362 if (baseFormat
== GL_DEPTH_COMPONENT
||
2363 baseFormat
== GL_DEPTH_STENCIL
||
2364 baseFormat
== GL_STENCIL_INDEX
||
2365 rb_base_format
== GL_DEPTH_COMPONENT
||
2366 rb_base_format
== GL_DEPTH_STENCIL
||
2367 rb_base_format
== GL_STENCIL_INDEX
||
2368 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2369 baseFormat
== GL_ALPHA
) &&
2370 rb_base_format
!= GL_RGBA
) ||
2371 internalFormat
== GL_RGB9_E5
) {
2374 if (internalFormat
== GL_RGB9_E5
) {
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2379 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2380 _mesa_enum_to_string(internalFormat
));
2385 if (_mesa_is_gles3(ctx
)) {
2386 bool rb_is_srgb
= false;
2387 bool dst_is_srgb
= false;
2389 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2390 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2394 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2398 if (rb_is_srgb
!= dst_is_srgb
) {
2399 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2400 * OpenGLES 3.0.0 spec says:
2402 * "The error INVALID_OPERATION is also generated if the
2403 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2404 * framebuffer attachment corresponding to the read buffer
2405 * is LINEAR (see section 6.1.13) and internalformat is
2406 * one of the sRGB formats described in section 3.8.16, or
2407 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2408 * SRGB and internalformat is not one of the sRGB formats."
2410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2411 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2415 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2416 * types for SNORM formats. Also, conversion to SNORM formats is not
2417 * allowed by Table 3.2 on Page 110.
2419 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2421 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2422 _mesa_enum_to_string(internalFormat
));
2427 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2429 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2433 /* From the EXT_texture_integer spec:
2435 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2436 * if the texture internalformat is an integer format and the read color
2437 * buffer is not an integer format, or if the internalformat is not an
2438 * integer format and the read color buffer is an integer format."
2440 if (_mesa_is_color_format(internalFormat
)) {
2441 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2442 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2443 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2444 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2445 if (is_int
|| is_rbint
) {
2446 if (is_int
!= is_rbint
) {
2447 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2448 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2450 } else if (_mesa_is_gles(ctx
) &&
2451 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2452 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2453 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2454 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2459 /* From page 138 of OpenGL ES 3.0 spec:
2460 * "The error INVALID_OPERATION is generated if floating-point RGBA
2461 * data is required; if signed integer RGBA data is required and the
2462 * format of the current color buffer is not signed integer; if
2463 * unsigned integer RGBA data is required and the format of the
2464 * current color buffer is not unsigned integer; or if fixed-point
2465 * RGBA data is required and the format of the current color buffer
2466 * is not fixed-point.
2468 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2469 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2470 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2473 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2475 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2476 _mesa_error(ctx
, err
,
2477 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2480 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2482 "glCopyTexImage%dD(no compression for format)", dimensions
);
2486 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2487 "glCopyTexImage%dD(border!=0)", dimensions
);
2492 if (!mutable_tex_object(ctx
, target
)) {
2493 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2494 "glCopyTexImage%dD(immutable texture)", dimensions
);
2498 /* if we get here, the parameters are OK */
2504 * Test glCopyTexSubImage[12]D() parameters for errors.
2505 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2508 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2509 const struct gl_texture_object
*texObj
,
2510 GLenum target
, GLint level
,
2511 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2512 GLint width
, GLint height
, const char *caller
)
2514 struct gl_texture_image
*texImage
;
2516 /* Check that the source buffer is complete */
2517 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2518 if (ctx
->ReadBuffer
->_Status
== 0) {
2519 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2521 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2522 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2523 "%s(invalid readbuffer)", caller
);
2527 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2529 "%s(multisample FBO)", caller
);
2535 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2536 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2540 /* Get dest image pointers */
2542 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2546 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2548 /* destination image does not exist */
2549 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2550 "%s(invalid texture image)", caller
);
2554 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2555 width
, height
, 1, caller
)) {
2559 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2560 xoffset
, yoffset
, zoffset
,
2561 width
, height
, 1, caller
)) {
2565 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2566 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2567 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2568 "%s(no compression for format)", caller
);
2573 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2574 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2578 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2579 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2580 "%s(missing readbuffer, format=%s)", caller
,
2581 _mesa_enum_to_string(texImage
->_BaseFormat
));
2585 /* From the EXT_texture_integer spec:
2587 * "INVALID_OPERATION is generated by CopyTexImage* and
2588 * CopyTexSubImage* if the texture internalformat is an integer format
2589 * and the read color buffer is not an integer format, or if the
2590 * internalformat is not an integer format and the read color buffer
2591 * is an integer format."
2593 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2594 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2596 if (_mesa_is_format_integer_color(rb
->Format
) !=
2597 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2599 "%s(integer vs non-integer)", caller
);
2604 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2605 * framebuffer/destination texture base internal format combinations),
2606 * all the entries for stencil are left blank (unsupported).
2608 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2609 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2613 /* if we get here, the parameters are OK */
2618 /** Callback info for walking over FBO hash table */
2621 struct gl_context
*ctx
;
2622 struct gl_texture_object
*texObj
;
2628 * Check render to texture callback. Called from _mesa_HashWalk().
2631 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2633 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2634 const struct cb_info
*info
= (struct cb_info
*) userData
;
2635 struct gl_context
*ctx
= info
->ctx
;
2636 const struct gl_texture_object
*texObj
= info
->texObj
;
2637 const GLuint level
= info
->level
, face
= info
->face
;
2639 /* If this is a user-created FBO */
2640 if (_mesa_is_user_fbo(fb
)) {
2642 /* check if any of the FBO's attachments point to 'texObj' */
2643 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2644 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2645 if (att
->Type
== GL_TEXTURE
&&
2646 att
->Texture
== texObj
&&
2647 att
->TextureLevel
== level
&&
2648 att
->CubeMapFace
== face
) {
2649 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2650 assert(att
->Renderbuffer
->TexImage
);
2651 /* Mark fb status as indeterminate to force re-validation */
2654 /* Make sure that the revalidation actually happens if this is
2655 * being done to currently-bound buffers.
2657 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2658 ctx
->NewState
|= _NEW_BUFFERS
;
2666 * When a texture image is specified we have to check if it's bound to
2667 * any framebuffer objects (render to texture) in order to detect changes
2668 * in size or format since that effects FBO completeness.
2669 * Any FBOs rendering into the texture must be re-validated.
2672 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2673 struct gl_texture_object
*texObj
,
2674 GLuint face
, GLuint level
)
2676 /* Only check this texture if it's been marked as RenderToTexture */
2677 if (texObj
->_RenderToTexture
) {
2678 struct cb_info info
;
2680 info
.texObj
= texObj
;
2683 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2689 * If the texture object's GenerateMipmap flag is set and we've
2690 * changed the texture base level image, regenerate the rest of the
2691 * mipmap levels now.
2694 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2695 struct gl_texture_object
*texObj
, GLint level
)
2697 if (texObj
->GenerateMipmap
&&
2698 level
== texObj
->BaseLevel
&&
2699 level
< texObj
->MaxLevel
) {
2700 assert(ctx
->Driver
.GenerateMipmap
);
2701 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2706 /** Debug helper: override the user-requested internal format */
2708 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2711 if (internalFormat
== GL_RGBA16F_ARB
||
2712 internalFormat
== GL_RGBA32F_ARB
) {
2713 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2716 else if (internalFormat
== GL_RGB16F_ARB
||
2717 internalFormat
== GL_RGB32F_ARB
) {
2718 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2721 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2722 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2723 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2724 return GL_LUMINANCE_ALPHA
;
2726 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2727 internalFormat
== GL_LUMINANCE32F_ARB
) {
2728 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2729 return GL_LUMINANCE
;
2731 else if (internalFormat
== GL_ALPHA16F_ARB
||
2732 internalFormat
== GL_ALPHA32F_ARB
) {
2733 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2737 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2738 internalFormat = GL_RGBA;
2742 return internalFormat
;
2745 return internalFormat
;
2751 * Choose the actual hardware format for a texture image.
2752 * Try to use the same format as the previous image level when possible.
2753 * Otherwise, ask the driver for the best format.
2754 * It's important to try to choose a consistant format for all levels
2755 * for efficient texture memory layout/allocation. In particular, this
2756 * comes up during automatic mipmap generation.
2759 _mesa_choose_texture_format(struct gl_context
*ctx
,
2760 struct gl_texture_object
*texObj
,
2761 GLenum target
, GLint level
,
2762 GLenum internalFormat
, GLenum format
, GLenum type
)
2766 /* see if we've already chosen a format for the previous level */
2768 struct gl_texture_image
*prevImage
=
2769 _mesa_select_tex_image(texObj
, target
, level
- 1);
2770 /* See if the prev level is defined and has an internal format which
2771 * matches the new internal format.
2774 prevImage
->Width
> 0 &&
2775 prevImage
->InternalFormat
== internalFormat
) {
2776 /* use the same format */
2777 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2778 return prevImage
->TexFormat
;
2782 /* If the application requested compression to an S3TC format but we don't
2783 * have the DXTn library, force a generic compressed format instead.
2785 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2786 const GLenum before
= internalFormat
;
2788 switch (internalFormat
) {
2789 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2790 if (!ctx
->Mesa_DXTn
)
2791 internalFormat
= GL_COMPRESSED_RGB
;
2793 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2794 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2795 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2796 if (!ctx
->Mesa_DXTn
)
2797 internalFormat
= GL_COMPRESSED_RGBA
;
2803 if (before
!= internalFormat
) {
2805 "DXT compression requested (%s), "
2806 "but libtxc_dxtn library not installed. Using %s "
2808 _mesa_enum_to_string(before
),
2809 _mesa_enum_to_string(internalFormat
));
2813 /* choose format from scratch */
2814 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2816 assert(f
!= MESA_FORMAT_NONE
);
2822 * Adjust pixel unpack params and image dimensions to strip off the
2823 * one-pixel texture border.
2825 * Gallium and intel don't support texture borders. They've seldem been used
2826 * and seldom been implemented correctly anyway.
2828 * \param unpackNew returns the new pixel unpack parameters
2831 strip_texture_border(GLenum target
,
2832 GLint
*width
, GLint
*height
, GLint
*depth
,
2833 const struct gl_pixelstore_attrib
*unpack
,
2834 struct gl_pixelstore_attrib
*unpackNew
)
2840 *unpackNew
= *unpack
;
2842 if (unpackNew
->RowLength
== 0)
2843 unpackNew
->RowLength
= *width
;
2845 if (unpackNew
->ImageHeight
== 0)
2846 unpackNew
->ImageHeight
= *height
;
2848 assert(*width
>= 3);
2849 unpackNew
->SkipPixels
++; /* skip the border */
2850 *width
= *width
- 2; /* reduce the width by two border pixels */
2852 /* The min height of a texture with a border is 3 */
2853 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2854 unpackNew
->SkipRows
++; /* skip the border */
2855 *height
= *height
- 2; /* reduce the height by two border pixels */
2859 target
!= GL_TEXTURE_2D_ARRAY
&&
2860 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2861 unpackNew
->SkipImages
++; /* skip the border */
2862 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2868 * Common code to implement all the glTexImage1D/2D/3D functions
2869 * as well as glCompressedTexImage1D/2D/3D.
2870 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2871 * \param format the user's image format (only used if !compressed)
2872 * \param type the user's image type (only used if !compressed)
2873 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2876 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2877 GLenum target
, GLint level
, GLint internalFormat
,
2878 GLsizei width
, GLsizei height
, GLsizei depth
,
2879 GLint border
, GLenum format
, GLenum type
,
2880 GLsizei imageSize
, const GLvoid
*pixels
)
2882 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2883 struct gl_pixelstore_attrib unpack_no_border
;
2884 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2885 struct gl_texture_object
*texObj
;
2886 mesa_format texFormat
;
2887 GLboolean dimensionsOK
, sizeOK
;
2889 FLUSH_VERTICES(ctx
, 0);
2891 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2894 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2896 _mesa_enum_to_string(target
), level
,
2897 _mesa_enum_to_string(internalFormat
),
2898 width
, height
, depth
, border
, pixels
);
2901 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2903 _mesa_enum_to_string(target
), level
,
2904 _mesa_enum_to_string(internalFormat
),
2905 width
, height
, depth
, border
,
2906 _mesa_enum_to_string(format
),
2907 _mesa_enum_to_string(type
), pixels
);
2910 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2912 /* target error checking */
2913 if (!legal_teximage_target(ctx
, dims
, target
)) {
2914 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2915 func
, dims
, _mesa_enum_to_string(target
));
2919 /* general error checking */
2921 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2923 width
, height
, depth
,
2924 border
, imageSize
, pixels
))
2928 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2929 format
, type
, width
, height
, depth
, border
,
2934 /* Here we convert a cpal compressed image into a regular glTexImage2D
2935 * call by decompressing the texture. If we really want to support cpal
2936 * textures in any driver this would have to be changed.
2938 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2939 switch (internalFormat
) {
2940 case GL_PALETTE4_RGB8_OES
:
2941 case GL_PALETTE4_RGBA8_OES
:
2942 case GL_PALETTE4_R5_G6_B5_OES
:
2943 case GL_PALETTE4_RGBA4_OES
:
2944 case GL_PALETTE4_RGB5_A1_OES
:
2945 case GL_PALETTE8_RGB8_OES
:
2946 case GL_PALETTE8_RGBA8_OES
:
2947 case GL_PALETTE8_R5_G6_B5_OES
:
2948 case GL_PALETTE8_RGBA4_OES
:
2949 case GL_PALETTE8_RGB5_A1_OES
:
2950 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2951 width
, height
, imageSize
, pixels
);
2956 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2960 /* For glCompressedTexImage() the driver has no choice about the
2961 * texture format since we'll never transcode the user's compressed
2962 * image data. The internalFormat was error checked earlier.
2964 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
2967 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
2968 * internal floating point format for the given base format.
2970 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
2971 if (type
== GL_FLOAT
) {
2972 texObj
->_IsFloat
= GL_TRUE
;
2973 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
2974 texObj
->_IsHalfFloat
= GL_TRUE
;
2977 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
2980 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2981 internalFormat
, format
, type
);
2984 assert(texFormat
!= MESA_FORMAT_NONE
);
2986 /* check that width, height, depth are legal for the mipmap level */
2987 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2988 height
, depth
, border
);
2990 /* check that the texture won't take too much memory, etc */
2991 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
2992 0, level
, texFormat
, 1,
2993 width
, height
, depth
);
2995 if (_mesa_is_proxy_texture(target
)) {
2996 /* Proxy texture: just clear or set state depending on error checking */
2997 struct gl_texture_image
*texImage
=
2998 get_proxy_tex_image(ctx
, target
, level
);
3001 return; /* GL_OUT_OF_MEMORY already recorded */
3003 if (dimensionsOK
&& sizeOK
) {
3004 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3005 border
, internalFormat
, texFormat
);
3008 clear_teximage_fields(texImage
);
3012 /* non-proxy target */
3013 const GLuint face
= _mesa_tex_target_to_face(target
);
3014 struct gl_texture_image
*texImage
;
3016 if (!dimensionsOK
) {
3017 _mesa_error(ctx
, GL_INVALID_VALUE
,
3018 "%s%uD(invalid width or height or depth)",
3024 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3025 "%s%uD(image too large: %d x %d x %d, %s format)",
3026 func
, dims
, width
, height
, depth
,
3027 _mesa_enum_to_string(internalFormat
));
3031 /* Allow a hardware driver to just strip out the border, to provide
3032 * reliable but slightly incorrect hardware rendering instead of
3033 * rarely-tested software fallback rendering.
3035 if (border
&& ctx
->Const
.StripTextureBorder
) {
3036 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3039 unpack
= &unpack_no_border
;
3042 if (ctx
->NewState
& _NEW_PIXEL
)
3043 _mesa_update_state(ctx
);
3045 _mesa_lock_texture(ctx
, texObj
);
3047 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3050 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3053 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3055 _mesa_init_teximage_fields(ctx
, texImage
,
3056 width
, height
, depth
,
3057 border
, internalFormat
, texFormat
);
3059 /* Give the texture to the driver. <pixels> may be null. */
3060 if (width
> 0 && height
> 0 && depth
> 0) {
3062 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3066 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3067 type
, pixels
, unpack
);
3071 check_gen_mipmap(ctx
, target
, texObj
, level
);
3073 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3075 _mesa_dirty_texobj(ctx
, texObj
);
3078 _mesa_unlock_texture(ctx
, texObj
);
3085 * Called from the API. Note that width includes the border.
3088 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3089 GLsizei width
, GLint border
, GLenum format
,
3090 GLenum type
, const GLvoid
*pixels
)
3092 GET_CURRENT_CONTEXT(ctx
);
3093 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3094 border
, format
, type
, 0, pixels
);
3099 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3100 GLsizei width
, GLsizei height
, GLint border
,
3101 GLenum format
, GLenum type
,
3102 const GLvoid
*pixels
)
3104 GET_CURRENT_CONTEXT(ctx
);
3105 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3106 border
, format
, type
, 0, pixels
);
3111 * Called by the API or display list executor.
3112 * Note that width and height include the border.
3115 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3116 GLsizei width
, GLsizei height
, GLsizei depth
,
3117 GLint border
, GLenum format
, GLenum type
,
3118 const GLvoid
*pixels
)
3120 GET_CURRENT_CONTEXT(ctx
);
3121 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3122 width
, height
, depth
,
3123 border
, format
, type
, 0, pixels
);
3128 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3129 GLsizei width
, GLsizei height
, GLsizei depth
,
3130 GLint border
, GLenum format
, GLenum type
,
3131 const GLvoid
*pixels
)
3133 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3134 depth
, border
, format
, type
, pixels
);
3139 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3141 struct gl_texture_object
*texObj
;
3142 struct gl_texture_image
*texImage
;
3144 GET_CURRENT_CONTEXT(ctx
);
3145 FLUSH_VERTICES(ctx
, 0);
3149 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3151 case GL_TEXTURE_EXTERNAL_OES
:
3153 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3156 valid_target
= false;
3160 if (!valid_target
) {
3161 _mesa_error(ctx
, GL_INVALID_ENUM
,
3162 "glEGLImageTargetTexture2D(target=%d)", target
);
3167 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3168 "glEGLImageTargetTexture2D(image=%p)", image
);
3172 if (ctx
->NewState
& _NEW_PIXEL
)
3173 _mesa_update_state(ctx
);
3175 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3179 _mesa_lock_texture(ctx
, texObj
);
3181 if (texObj
->Immutable
) {
3182 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3183 "glEGLImageTargetTexture2D(texture is immutable)");
3184 _mesa_unlock_texture(ctx
, texObj
);
3188 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3190 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3192 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3194 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3195 texObj
, texImage
, image
);
3197 _mesa_dirty_texobj(ctx
, texObj
);
3199 _mesa_unlock_texture(ctx
, texObj
);
3204 * Helper that implements the glTexSubImage1/2/3D()
3205 * and glTextureSubImage1/2/3D() functions.
3208 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3209 struct gl_texture_object
*texObj
,
3210 struct gl_texture_image
*texImage
,
3211 GLenum target
, GLint level
,
3212 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3213 GLsizei width
, GLsizei height
, GLsizei depth
,
3214 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3217 FLUSH_VERTICES(ctx
, 0);
3219 if (ctx
->NewState
& _NEW_PIXEL
)
3220 _mesa_update_state(ctx
);
3222 _mesa_lock_texture(ctx
, texObj
);
3224 if (width
> 0 && height
> 0 && depth
> 0) {
3225 /* If we have a border, offset=-1 is legal. Bias by border width. */
3228 if (target
!= GL_TEXTURE_2D_ARRAY
)
3229 zoffset
+= texImage
->Border
;
3232 if (target
!= GL_TEXTURE_1D_ARRAY
)
3233 yoffset
+= texImage
->Border
;
3236 xoffset
+= texImage
->Border
;
3239 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3240 xoffset
, yoffset
, zoffset
,
3241 width
, height
, depth
,
3242 format
, type
, pixels
, &ctx
->Unpack
);
3244 check_gen_mipmap(ctx
, target
, texObj
, level
);
3246 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3247 * the texel data, not the texture format, size, etc.
3251 _mesa_unlock_texture(ctx
, texObj
);
3255 * Implement all the glTexSubImage1/2/3D() functions.
3256 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3259 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3260 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3261 GLsizei width
, GLsizei height
, GLsizei depth
,
3262 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3263 const char *callerName
)
3265 struct gl_texture_object
*texObj
;
3266 struct gl_texture_image
*texImage
;
3268 /* check target (proxies not allowed) */
3269 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3270 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3271 dims
, _mesa_enum_to_string(target
));
3275 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3279 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3280 xoffset
, yoffset
, zoffset
,
3281 width
, height
, depth
, format
, type
,
3282 pixels
, false, callerName
)) {
3283 return; /* error was detected */
3286 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3287 /* texsubimage_error_check ensures that texImage is not NULL */
3289 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3290 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3292 _mesa_enum_to_string(target
), level
,
3293 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3294 _mesa_enum_to_string(format
),
3295 _mesa_enum_to_string(type
), pixels
);
3297 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3298 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3299 format
, type
, pixels
, false);
3304 * Implement all the glTextureSubImage1/2/3D() functions.
3305 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3308 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3309 GLuint texture
, GLint level
,
3310 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3311 GLsizei width
, GLsizei height
, GLsizei depth
,
3312 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3313 const char *callerName
)
3315 struct gl_texture_object
*texObj
;
3316 struct gl_texture_image
*texImage
;
3319 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3321 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3322 dims
, texture
, level
,
3323 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3324 _mesa_enum_to_string(format
),
3325 _mesa_enum_to_string(type
), pixels
);
3327 /* Get the texture object by Name. */
3328 texObj
= _mesa_lookup_texture(ctx
, texture
);
3330 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3335 /* check target (proxies not allowed) */
3336 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3337 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3338 callerName
, _mesa_enum_to_string(texObj
->Target
));
3342 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3343 xoffset
, yoffset
, zoffset
,
3344 width
, height
, depth
, format
, type
,
3345 pixels
, true, callerName
)) {
3346 return; /* error was detected */
3350 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3351 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3355 * What do we do if the user created a texture with the following code
3356 * and then called this function with its handle?
3359 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3360 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3361 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3362 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3363 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3364 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3365 * // wrong format, or given the wrong size, etc.
3366 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3367 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3369 * A bug has been filed against the spec for this case. In the
3370 * meantime, we will check for cube completeness.
3372 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3373 * Core Profile spec (30.10.2014):
3374 * "[A] cube map texture is cube complete if the
3375 * following conditions all hold true: The [base level] texture
3376 * images of each of the six cube map faces have identical, positive,
3377 * and square dimensions. The [base level] images were each specified
3378 * with the same internal format."
3380 * It seems reasonable to check for cube completeness of an arbitrary
3381 * level here so that the image data has a consistent format and size.
3383 if (!_mesa_cube_level_complete(texObj
, level
)) {
3384 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3385 "glTextureSubImage%uD(cube map incomplete)",
3390 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3392 /* Copy in each face. */
3393 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3394 texImage
= texObj
->Image
[i
][level
];
3397 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3398 level
, xoffset
, yoffset
, 0,
3399 width
, height
, 1, format
,
3400 type
, pixels
, true);
3401 pixels
= (GLubyte
*) pixels
+ imageStride
;
3405 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3408 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3409 level
, xoffset
, yoffset
, zoffset
,
3410 width
, height
, depth
, format
,
3411 type
, pixels
, true);
3417 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3418 GLint xoffset
, GLsizei width
,
3419 GLenum format
, GLenum type
,
3420 const GLvoid
*pixels
)
3422 GET_CURRENT_CONTEXT(ctx
);
3423 texsubimage(ctx
, 1, target
, level
,
3426 format
, type
, pixels
, "glTexSubImage1D");
3431 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3432 GLint xoffset
, GLint yoffset
,
3433 GLsizei width
, GLsizei height
,
3434 GLenum format
, GLenum type
,
3435 const GLvoid
*pixels
)
3437 GET_CURRENT_CONTEXT(ctx
);
3438 texsubimage(ctx
, 2, target
, level
,
3439 xoffset
, yoffset
, 0,
3441 format
, type
, pixels
, "glTexSubImage2D");
3447 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3448 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3449 GLsizei width
, GLsizei height
, GLsizei depth
,
3450 GLenum format
, GLenum type
,
3451 const GLvoid
*pixels
)
3453 GET_CURRENT_CONTEXT(ctx
);
3454 texsubimage(ctx
, 3, target
, level
,
3455 xoffset
, yoffset
, zoffset
,
3456 width
, height
, depth
,
3457 format
, type
, pixels
, "glTexSubImage3D");
3461 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3462 GLint xoffset
, GLsizei width
,
3463 GLenum format
, GLenum type
,
3464 const GLvoid
*pixels
)
3466 GET_CURRENT_CONTEXT(ctx
);
3467 texturesubimage(ctx
, 1, texture
, level
,
3470 format
, type
, pixels
, "glTextureSubImage1D");
3475 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3476 GLint xoffset
, GLint yoffset
,
3477 GLsizei width
, GLsizei height
,
3478 GLenum format
, GLenum type
,
3479 const GLvoid
*pixels
)
3481 GET_CURRENT_CONTEXT(ctx
);
3482 texturesubimage(ctx
, 2, texture
, level
,
3483 xoffset
, yoffset
, 0,
3485 format
, type
, pixels
, "glTextureSubImage2D");
3490 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3491 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3492 GLsizei width
, GLsizei height
, GLsizei depth
,
3493 GLenum format
, GLenum type
,
3494 const GLvoid
*pixels
)
3496 GET_CURRENT_CONTEXT(ctx
);
3497 texturesubimage(ctx
, 3, texture
, level
,
3498 xoffset
, yoffset
, zoffset
,
3499 width
, height
, depth
,
3500 format
, type
, pixels
, "glTextureSubImage3D");
3505 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3506 * from. This depends on whether the texture contains color or depth values.
3508 static struct gl_renderbuffer
*
3509 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3511 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3512 /* reading from depth/stencil buffer */
3513 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3514 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3515 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3517 /* copying from color buffer */
3518 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3523 copytexsubimage_by_slice(struct gl_context
*ctx
,
3524 struct gl_texture_image
*texImage
,
3526 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3527 struct gl_renderbuffer
*rb
,
3529 GLsizei width
, GLsizei height
)
3531 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3534 /* For 1D arrays, we copy each scanline of the source rectangle into the
3537 assert(zoffset
== 0);
3539 for (slice
= 0; slice
< height
; slice
++) {
3540 assert(yoffset
+ slice
< texImage
->Height
);
3541 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3542 xoffset
, 0, yoffset
+ slice
,
3543 rb
, x
, y
+ slice
, width
, 1);
3546 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3547 xoffset
, yoffset
, zoffset
,
3548 rb
, x
, y
, width
, height
);
3553 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3555 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3556 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3557 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3558 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3560 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3561 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3562 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3563 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3565 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3566 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3567 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3568 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3576 * Check if the given texture format and size arguments match those
3577 * of the texture image.
3578 * \param return true if arguments match, false otherwise.
3581 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3582 GLenum internalFormat
,
3583 mesa_format texFormat
, GLint x
, GLint y
, GLsizei width
,
3584 GLsizei height
, GLint border
)
3586 if (texImage
->InternalFormat
!= internalFormat
)
3588 if (texImage
->TexFormat
!= texFormat
)
3590 if (texImage
->Border
!= border
)
3592 if (texImage
->Width2
!= width
)
3594 if (texImage
->Height2
!= height
)
3600 * Implement the glCopyTexImage1/2D() functions.
3603 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3604 GLenum target
, GLint level
, GLenum internalFormat
,
3605 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3607 struct gl_texture_object
*texObj
;
3608 struct gl_texture_image
*texImage
;
3609 const GLuint face
= _mesa_tex_target_to_face(target
);
3610 mesa_format texFormat
;
3611 struct gl_renderbuffer
*rb
;
3613 FLUSH_VERTICES(ctx
, 0);
3615 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3616 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3618 _mesa_enum_to_string(target
), level
,
3619 _mesa_enum_to_string(internalFormat
),
3620 x
, y
, width
, height
, border
);
3622 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3623 _mesa_update_state(ctx
);
3625 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3626 width
, height
, border
))
3629 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3631 _mesa_error(ctx
, GL_INVALID_VALUE
,
3632 "glCopyTexImage%uD(invalid width or height)", dims
);
3636 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3639 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3640 internalFormat
, GL_NONE
, GL_NONE
);
3642 /* First check if reallocating the texture buffer can be avoided.
3643 * Without the realloc the copy can be 20x faster.
3645 _mesa_lock_texture(ctx
, texObj
);
3647 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3648 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3649 x
, y
, width
, height
, border
)) {
3650 _mesa_unlock_texture(ctx
, texObj
);
3651 return _mesa_copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
,
3652 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_ENUM
, "%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_ENUM
, "%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_ENUM
, "%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
,
5086 (const GLfloat
*) &offset
);
5088 if (size
!= oldSize
) {
5089 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
,
5090 (const GLfloat
*) &size
);
5094 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5097 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5103 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5104 * Return true if it is, and return false if it is not
5105 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5106 * core spec, 02.02.2015, PDF page 245).
5109 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5112 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5113 _mesa_error(ctx
, GL_INVALID_ENUM
,
5114 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5122 * Check for errors related to the texture buffer range.
5123 * Return false if errors are found, true if none are found.
5126 check_texture_buffer_range(struct gl_context
*ctx
,
5127 struct gl_buffer_object
*bufObj
,
5128 GLintptr offset
, GLsizeiptr size
,
5131 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5132 * Textures (PDF page 245):
5133 * "An INVALID_VALUE error is generated if offset is negative, if
5134 * size is less than or equal to zero, or if offset + size is greater
5135 * than the value of BUFFER_SIZE for the buffer bound to target."
5138 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5144 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5149 if (offset
+ size
> bufObj
->Size
) {
5150 _mesa_error(ctx
, GL_INVALID_VALUE
,
5151 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5152 (int) offset
, (int) size
, (int) bufObj
->Size
);
5156 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5157 * Textures (PDF page 245):
5158 * "An INVALID_VALUE error is generated if offset is not an integer
5159 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5161 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5162 _mesa_error(ctx
, GL_INVALID_VALUE
,
5163 "%s(invalid offset alignment)", caller
);
5171 /** GL_ARB_texture_buffer_object */
5173 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5175 struct gl_texture_object
*texObj
;
5176 struct gl_buffer_object
*bufObj
;
5178 GET_CURRENT_CONTEXT(ctx
);
5180 /* Need to catch a bad target before it gets to
5181 * _mesa_get_current_tex_object.
5183 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5187 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5193 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5197 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5198 buffer
? -1 : 0, "glTexBuffer");
5202 /** GL_ARB_texture_buffer_range */
5204 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5205 GLintptr offset
, GLsizeiptr size
)
5207 struct gl_texture_object
*texObj
;
5208 struct gl_buffer_object
*bufObj
;
5210 GET_CURRENT_CONTEXT(ctx
);
5212 /* Need to catch a bad target before it gets to
5213 * _mesa_get_current_tex_object.
5215 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5219 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5223 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5224 "glTexBufferRange"))
5228 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5229 * Textures (PDF page 254):
5230 * "If buffer is zero, then any buffer object attached to the buffer
5231 * texture is detached, the values offset and size are ignored and
5232 * the state for offset and size for the buffer texture are reset to
5240 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5244 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5245 offset
, size
, "glTexBufferRange");
5249 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5251 struct gl_texture_object
*texObj
;
5252 struct gl_buffer_object
*bufObj
;
5254 GET_CURRENT_CONTEXT(ctx
);
5257 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5263 /* Get the texture object by Name. */
5264 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5268 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5271 texture_buffer_range(ctx
, texObj
, internalFormat
,
5272 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5276 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5277 GLintptr offset
, GLsizeiptr size
)
5279 struct gl_texture_object
*texObj
;
5280 struct gl_buffer_object
*bufObj
;
5282 GET_CURRENT_CONTEXT(ctx
);
5285 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5286 "glTextureBufferRange");
5290 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5291 "glTextureBufferRange"))
5295 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5296 * Textures (PDF page 254):
5297 * "If buffer is zero, then any buffer object attached to the buffer
5298 * texture is detached, the values offset and size are ignored and
5299 * the state for offset and size for the buffer texture are reset to
5307 /* Get the texture object by Name. */
5308 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5312 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5313 "glTextureBufferRange"))
5316 texture_buffer_range(ctx
, texObj
, internalFormat
,
5317 bufObj
, offset
, size
, "glTextureBufferRange");
5321 _mesa_is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5323 /* Everything that is allowed for renderbuffers,
5324 * except for a base format of GL_STENCIL_INDEX, unless supported.
5326 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5327 if (ctx
->Extensions
.ARB_texture_stencil8
)
5328 return baseFormat
!= 0;
5330 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5334 /** GL_ARB_texture_multisample */
5336 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5339 case GL_TEXTURE_2D_MULTISAMPLE
:
5341 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5342 return dims
== 2 && !dsa
;
5343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5345 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5346 return dims
== 3 && !dsa
;
5354 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5355 struct gl_texture_object
*texObj
,
5356 GLenum target
, GLsizei samples
,
5357 GLint internalformat
, GLsizei width
,
5358 GLsizei height
, GLsizei depth
,
5359 GLboolean fixedsamplelocations
,
5360 GLboolean immutable
, const char *func
)
5362 struct gl_texture_image
*texImage
;
5363 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5364 mesa_format texFormat
;
5365 GLenum sample_count_error
;
5366 bool dsa
= strstr(func
, "ture") ? true : false;
5368 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5369 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5370 _mesa_enum_to_string(target
), samples
);
5373 if (!((ctx
->Extensions
.ARB_texture_multisample
5374 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5375 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5380 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5384 if (!check_multisample_target(dims
, target
, dsa
)) {
5386 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5390 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5395 /* check that the specified internalformat is color/depth/stencil-renderable;
5396 * refer GL3.1 spec 4.4.4
5399 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5400 _mesa_error(ctx
, GL_INVALID_ENUM
,
5401 "%s(internalformat=%s not legal for immutable-format)",
5402 func
, _mesa_enum_to_string(internalformat
));
5406 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5407 /* Page 172 of OpenGL ES 3.1 spec says:
5408 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5409 * color-renderable, depth-renderable, or stencil-renderable (as
5410 * defined in section 9.4).
5412 * (Same error is also defined for desktop OpenGL for multisample
5413 * teximage/texstorage functions.)
5415 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5416 _mesa_enum_to_string(internalformat
));
5420 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5421 internalformat
, samples
);
5422 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5424 /* Page 254 of OpenGL 4.4 spec says:
5425 * "Proxy arrays for two-dimensional multisample and two-dimensional
5426 * multisample array textures are operated on in the same way when
5427 * TexImage2DMultisample is called with target specified as
5428 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5429 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5430 * However, if samples is not supported, then no error is generated.
5432 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5433 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5437 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5439 "%s(texture object 0)",
5444 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5446 if (texImage
== NULL
) {
5447 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5451 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5452 internalformat
, GL_NONE
, GL_NONE
);
5453 assert(texFormat
!= MESA_FORMAT_NONE
);
5455 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5456 width
, height
, depth
, 0);
5458 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5459 samples
, width
, height
, depth
);
5461 if (_mesa_is_proxy_texture(target
)) {
5462 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5463 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5464 internalformat
, texFormat
,
5465 samples
, fixedsamplelocations
);
5468 /* clear all image fields */
5469 clear_teximage_fields(texImage
);
5473 if (!dimensionsOK
) {
5474 _mesa_error(ctx
, GL_INVALID_VALUE
,
5475 "%s(invalid width or height)", func
);
5480 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5484 /* Check if texObj->Immutable is set */
5485 if (texObj
->Immutable
) {
5486 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5490 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5492 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5493 internalformat
, texFormat
,
5494 samples
, fixedsamplelocations
);
5496 if (width
> 0 && height
> 0 && depth
> 0) {
5497 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5498 width
, height
, depth
)) {
5499 /* tidy up the texture image state. strictly speaking,
5500 * we're allowed to just leave this in whatever state we
5501 * like, but being tidy is good.
5503 _mesa_init_teximage_fields(ctx
, texImage
,
5504 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5508 texObj
->Immutable
|= immutable
;
5511 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5514 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5520 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5521 GLenum internalformat
, GLsizei width
,
5522 GLsizei height
, GLboolean fixedsamplelocations
)
5524 struct gl_texture_object
*texObj
;
5525 GET_CURRENT_CONTEXT(ctx
);
5527 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5531 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5532 internalformat
, width
, height
, 1,
5533 fixedsamplelocations
, GL_FALSE
,
5534 "glTexImage2DMultisample");
5539 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5540 GLenum internalformat
, GLsizei width
,
5541 GLsizei height
, GLsizei depth
,
5542 GLboolean fixedsamplelocations
)
5544 struct gl_texture_object
*texObj
;
5545 GET_CURRENT_CONTEXT(ctx
);
5547 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5551 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5552 internalformat
, width
, height
, depth
,
5553 fixedsamplelocations
, GL_FALSE
,
5554 "glTexImage3DMultisample");
5558 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5559 GLsizei samples
, unsigned dims
)
5561 GET_CURRENT_CONTEXT(ctx
);
5563 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5564 _mesa_error(ctx
, GL_INVALID_VALUE
,
5565 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5566 dims
, width
, height
, depth
);
5573 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5574 GLenum internalformat
, GLsizei width
,
5575 GLsizei height
, GLboolean fixedsamplelocations
)
5577 struct gl_texture_object
*texObj
;
5578 GET_CURRENT_CONTEXT(ctx
);
5580 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5584 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5587 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5588 internalformat
, width
, height
, 1,
5589 fixedsamplelocations
, GL_TRUE
,
5590 "glTexStorage2DMultisample");
5594 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5595 GLenum internalformat
, GLsizei width
,
5596 GLsizei height
, GLsizei depth
,
5597 GLboolean fixedsamplelocations
)
5599 struct gl_texture_object
*texObj
;
5600 GET_CURRENT_CONTEXT(ctx
);
5602 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5606 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5609 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5610 internalformat
, width
, height
, depth
,
5611 fixedsamplelocations
, GL_TRUE
,
5612 "glTexStorage3DMultisample");
5616 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5617 GLenum internalformat
, GLsizei width
,
5619 GLboolean fixedsamplelocations
)
5621 struct gl_texture_object
*texObj
;
5622 GET_CURRENT_CONTEXT(ctx
);
5624 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5625 "glTextureStorage2DMultisample");
5629 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5632 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5633 internalformat
, width
, height
, 1,
5634 fixedsamplelocations
, GL_TRUE
,
5635 "glTextureStorage2DMultisample");
5639 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5640 GLenum internalformat
, GLsizei width
,
5641 GLsizei height
, GLsizei depth
,
5642 GLboolean fixedsamplelocations
)
5644 struct gl_texture_object
*texObj
;
5645 GET_CURRENT_CONTEXT(ctx
);
5647 /* Get the texture object by Name. */
5648 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5649 "glTextureStorage3DMultisample");
5653 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5656 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5657 internalformat
, width
, height
, depth
,
5658 fixedsamplelocations
, GL_TRUE
,
5659 "glTextureStorage3DMultisample");