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 ctx
->Extensions
.ARB_texture_cube_map_array
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 assert(numSamples
> 0);
1276 if (numLevels
> 0) {
1277 /* Compute total memory for a whole mipmap. This is the path
1278 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1286 for (l
= 0; l
< numLevels
; l
++) {
1287 GLint nextWidth
, nextHeight
, nextDepth
;
1289 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1291 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1292 &nextWidth
, &nextHeight
,
1295 height
= nextHeight
;
1302 /* We just compute the size of one mipmap level. This is the path
1303 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1305 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1308 bytes
*= _mesa_num_tex_faces(target
);
1309 bytes
*= numSamples
;
1311 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1313 /* We just check if the image size is less than MaxTextureMbytes.
1314 * Some drivers may do more specific checks.
1316 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1321 * Return true if the format is only valid for glCompressedTexImage.
1324 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1327 case GL_ETC1_RGB8_OES
:
1328 case GL_PALETTE4_RGB8_OES
:
1329 case GL_PALETTE4_RGBA8_OES
:
1330 case GL_PALETTE4_R5_G6_B5_OES
:
1331 case GL_PALETTE4_RGBA4_OES
:
1332 case GL_PALETTE4_RGB5_A1_OES
:
1333 case GL_PALETTE8_RGB8_OES
:
1334 case GL_PALETTE8_RGBA8_OES
:
1335 case GL_PALETTE8_R5_G6_B5_OES
:
1336 case GL_PALETTE8_RGBA4_OES
:
1337 case GL_PALETTE8_RGB5_A1_OES
:
1345 * Return true if the format doesn't support online compression.
1348 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1350 return _mesa_is_astc_format(format
) ||
1351 _mesa_is_etc2_format(format
) ||
1352 compressedteximage_only_format(ctx
, format
);
1355 /* Writes to an GL error pointer if non-null and returns whether or not the
1356 * error is GL_NO_ERROR */
1358 write_error(GLenum
*err_ptr
, GLenum error
)
1363 return error
== GL_NO_ERROR
;
1367 * Helper function to determine whether a target and specific compression
1368 * format are supported. The error parameter returns GL_NO_ERROR if the
1369 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1370 * or GL_INVALID_ENUM, whichever is more appropriate.
1373 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1374 GLenum intFormat
, GLenum
*error
)
1376 GLboolean target_can_be_compresed
= GL_FALSE
;
1377 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1378 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1382 case GL_PROXY_TEXTURE_2D
:
1383 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1385 case GL_PROXY_TEXTURE_CUBE_MAP
:
1386 case GL_TEXTURE_CUBE_MAP
:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1391 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1393 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1395 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1396 case GL_TEXTURE_2D_ARRAY_EXT
:
1397 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1399 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1400 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1401 /* From the KHR_texture_compression_astc_hdr spec:
1403 * Add a second new column "3D Tex." which is empty for all non-ASTC
1404 * formats. If only the LDR profile is supported by the
1405 * implementation, this column is also empty for all ASTC formats. If
1406 * both the LDR and HDR profiles are supported only, this column is
1407 * checked for all ASTC formats.
1409 * Add a third new column "Cube Map Array Tex." which is empty for all
1410 * non-ASTC formats, and checked for all ASTC formats.
1414 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1415 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1416 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1417 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1418 * 8.19 is *not* checked'
1420 * The instances of <internalformat> above should say <target>.
1422 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1423 * have already been handled by normal ETC2/EAC behavior.
1426 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1428 * "The ETC2/EAC texture compression algorithm supports only
1429 * two-dimensional images. If internalformat is an ETC2/EAC format,
1430 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1431 * target is not TEXTURE_2D_ARRAY."
1433 * This should also be applicable for glTexStorage3D(). Other available
1434 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1436 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1437 return write_error(error
, GL_INVALID_OPERATION
);
1438 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1442 case MESA_FORMAT_LAYOUT_ETC2
:
1443 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1444 if (_mesa_is_gles3(ctx
))
1445 return write_error(error
, GL_INVALID_OPERATION
);
1447 case MESA_FORMAT_LAYOUT_BPTC
:
1448 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1450 case MESA_FORMAT_LAYOUT_ASTC
:
1451 target_can_be_compresed
=
1452 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1454 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1455 * and the hdr extension is not supported.
1456 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1458 if (!target_can_be_compresed
)
1459 return write_error(error
, GL_INVALID_OPERATION
);
1467 return write_error(error
,
1468 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1473 * Check if the given texture target value is legal for a
1474 * glTexImage1/2/3D call.
1477 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1483 case GL_PROXY_TEXTURE_1D
:
1484 return _mesa_is_desktop_gl(ctx
);
1492 case GL_PROXY_TEXTURE_2D
:
1493 return _mesa_is_desktop_gl(ctx
);
1494 case GL_PROXY_TEXTURE_CUBE_MAP
:
1495 return _mesa_is_desktop_gl(ctx
)
1496 && ctx
->Extensions
.ARB_texture_cube_map
;
1497 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1498 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1499 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1500 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1501 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1502 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1503 return ctx
->Extensions
.ARB_texture_cube_map
;
1504 case GL_TEXTURE_RECTANGLE_NV
:
1505 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1506 return _mesa_is_desktop_gl(ctx
)
1507 && ctx
->Extensions
.NV_texture_rectangle
;
1508 case GL_TEXTURE_1D_ARRAY_EXT
:
1509 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1510 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1518 case GL_PROXY_TEXTURE_3D
:
1519 return _mesa_is_desktop_gl(ctx
);
1520 case GL_TEXTURE_2D_ARRAY_EXT
:
1521 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1522 || _mesa_is_gles3(ctx
);
1523 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1524 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1525 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1526 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1527 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1532 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1539 * Check if the given texture target value is legal for a
1540 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1541 * The difference compared to legal_teximage_target() above is that
1542 * proxy targets are not supported.
1545 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1550 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1555 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1556 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1557 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1558 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1559 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1560 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1561 return ctx
->Extensions
.ARB_texture_cube_map
;
1562 case GL_TEXTURE_RECTANGLE_NV
:
1563 return _mesa_is_desktop_gl(ctx
)
1564 && ctx
->Extensions
.NV_texture_rectangle
;
1565 case GL_TEXTURE_1D_ARRAY_EXT
:
1566 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1574 case GL_TEXTURE_2D_ARRAY_EXT
:
1575 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1576 || _mesa_is_gles3(ctx
);
1577 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1578 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1579 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1581 /* Table 8.15 of the OpenGL 4.5 core profile spec
1582 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1583 * and CopyTextureSubImage3D.
1585 case GL_TEXTURE_CUBE_MAP
:
1591 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1599 * Helper function to determine if a texture object is mutable (in terms
1600 * of GL_ARB_texture_storage).
1603 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1605 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1609 return !texObj
->Immutable
;
1614 * Return expected size of a compressed texture.
1617 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1620 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1621 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1625 * Verify that a texture format is valid with a particular target
1627 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1628 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1631 * \param ctx GL context
1632 * \param target Texture target
1633 * \param internalFormat Internal format of the texture image
1635 * \returns true if the combination is legal, false otherwise.
1638 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1639 GLenum target
, GLenum internalFormat
)
1641 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1642 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1643 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1644 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1645 * Profile spec says:
1647 * "Textures with a base internal format of DEPTH_COMPONENT or
1648 * DEPTH_STENCIL are supported by texture image specification
1649 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1650 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1651 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1652 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1653 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1654 * formats in conjunction with any other target will result in an
1655 * INVALID_OPERATION error."
1657 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1658 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1660 if (target
!= GL_TEXTURE_1D
&&
1661 target
!= GL_PROXY_TEXTURE_1D
&&
1662 target
!= GL_TEXTURE_2D
&&
1663 target
!= GL_PROXY_TEXTURE_2D
&&
1664 target
!= GL_TEXTURE_1D_ARRAY
&&
1665 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1666 target
!= GL_TEXTURE_2D_ARRAY
&&
1667 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1668 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1669 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1670 !((_mesa_is_cube_face(target
) ||
1671 target
== GL_TEXTURE_CUBE_MAP
||
1672 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1673 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1674 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1675 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1676 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1677 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
1686 texture_formats_agree(GLenum internalFormat
,
1689 GLboolean colorFormat
;
1690 GLboolean is_format_depth_or_depthstencil
;
1691 GLboolean is_internalFormat_depth_or_depthstencil
;
1693 /* Even though there are no color-index textures, we still have to support
1694 * uploading color-index data and remapping it to RGB via the
1695 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1697 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1699 is_internalFormat_depth_or_depthstencil
=
1700 _mesa_is_depth_format(internalFormat
) ||
1701 _mesa_is_depthstencil_format(internalFormat
);
1703 is_format_depth_or_depthstencil
=
1704 _mesa_is_depth_format(format
) ||
1705 _mesa_is_depthstencil_format(format
);
1707 colorFormat
= _mesa_is_color_format(format
);
1709 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1712 if (is_internalFormat_depth_or_depthstencil
!=
1713 is_format_depth_or_depthstencil
)
1716 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1723 * Test the combination of format, type and internal format arguments of
1724 * different texture operations on GLES.
1726 * \param ctx GL context.
1727 * \param format pixel data format given by the user.
1728 * \param type pixel data type given by the user.
1729 * \param internalFormat internal format given by the user.
1730 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1731 * \param callerName name of the caller function to print in the error message
1733 * \return true if a error is found, false otherwise
1735 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1738 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1739 GLenum type
, GLenum internalFormat
,
1740 GLuint dimensions
, const char *callerName
)
1744 if (_mesa_is_gles3(ctx
)) {
1745 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
1747 if (err
!= GL_NO_ERROR
) {
1748 _mesa_error(ctx
, err
,
1749 "%s(format = %s, type = %s, internalformat = %s)",
1750 callerName
, _mesa_enum_to_string(format
),
1751 _mesa_enum_to_string(type
),
1752 _mesa_enum_to_string(internalFormat
));
1757 err
= _mesa_es_error_check_format_and_type(ctx
, format
, type
, dimensions
);
1758 if (err
!= GL_NO_ERROR
) {
1759 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
1760 callerName
, _mesa_enum_to_string(format
),
1761 _mesa_enum_to_string(type
));
1770 * Test the glTexImage[123]D() parameters for errors.
1772 * \param ctx GL context.
1773 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1774 * \param target texture target given by the user (already validated).
1775 * \param level image level given by the user.
1776 * \param internalFormat internal format given by the user.
1777 * \param format pixel data format given by the user.
1778 * \param type pixel data type given by the user.
1779 * \param width image width given by the user.
1780 * \param height image height given by the user.
1781 * \param depth image depth given by the user.
1782 * \param border image border given by the user.
1784 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1786 * Verifies each of the parameters against the constants specified in
1787 * __struct gl_contextRec::Const and the supported extensions, and according
1788 * to the OpenGL specification.
1789 * Note that we don't fully error-check the width, height, depth values
1790 * here. That's done in _mesa_legal_texture_dimensions() which is used
1791 * by several other GL entrypoints. Plus, texture dims have a special
1792 * interaction with proxy textures.
1795 texture_error_check( struct gl_context
*ctx
,
1796 GLuint dimensions
, GLenum target
,
1797 GLint level
, GLint internalFormat
,
1798 GLenum format
, GLenum type
,
1799 GLint width
, GLint height
,
1800 GLint depth
, GLint border
,
1801 const GLvoid
*pixels
)
1805 /* Note: for proxy textures, some error conditions immediately generate
1806 * a GL error in the usual way. But others do not generate a GL error.
1807 * Instead, they cause the width, height, depth, format fields of the
1808 * texture image to be zeroed-out. The GL spec seems to indicate that the
1809 * zero-out behaviour is only used in cases related to memory allocation.
1813 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1814 _mesa_error(ctx
, GL_INVALID_VALUE
,
1815 "glTexImage%dD(level=%d)", dimensions
, level
);
1820 if (border
< 0 || border
> 1 ||
1821 ((ctx
->API
!= API_OPENGL_COMPAT
||
1822 target
== GL_TEXTURE_RECTANGLE_NV
||
1823 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
,
1825 "glTexImage%dD(border=%d)", dimensions
, border
);
1829 if (width
< 0 || height
< 0 || depth
< 0) {
1830 _mesa_error(ctx
, GL_INVALID_VALUE
,
1831 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1835 /* Check incoming image format and type */
1836 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1837 if (err
!= GL_NO_ERROR
) {
1838 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1839 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1841 * "Specifying a value for internalformat that is not one of the
1842 * above (acceptable) values generates the error INVALID VALUE."
1844 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1845 err
= GL_INVALID_VALUE
;
1847 _mesa_error(ctx
, err
,
1848 "glTexImage%dD(incompatible format = %s, type = %s)",
1849 dimensions
, _mesa_enum_to_string(format
),
1850 _mesa_enum_to_string(type
));
1854 /* Check internalFormat */
1855 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1856 _mesa_error(ctx
, GL_INVALID_VALUE
,
1857 "glTexImage%dD(internalFormat=%s)",
1858 dimensions
, _mesa_enum_to_string(internalFormat
));
1862 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1863 * combinations of format, internalFormat, and type that can be used.
1864 * Formats and types that require additional extensions (e.g., GL_FLOAT
1865 * requires GL_OES_texture_float) are filtered elsewhere.
1867 if (_mesa_is_gles(ctx
) &&
1868 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
1869 dimensions
, "glTexImage%dD")) {
1873 /* validate the bound PBO, if any */
1874 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1875 width
, height
, depth
, format
, type
,
1876 INT_MAX
, pixels
, "glTexImage")) {
1880 /* make sure internal format and format basically agree */
1881 if (!texture_formats_agree(internalFormat
, format
)) {
1882 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1883 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1884 dimensions
, _mesa_enum_to_string(internalFormat
),
1885 _mesa_enum_to_string(format
));
1889 /* additional checks for ycbcr textures */
1890 if (internalFormat
== GL_YCBCR_MESA
) {
1891 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1892 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1893 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1895 _mesa_snprintf(message
, sizeof(message
),
1896 "glTexImage%dD(format/type YCBCR mismatch)",
1898 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1899 return GL_TRUE
; /* error */
1901 if (target
!= GL_TEXTURE_2D
&&
1902 target
!= GL_PROXY_TEXTURE_2D
&&
1903 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1904 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1905 _mesa_error(ctx
, GL_INVALID_ENUM
,
1906 "glTexImage%dD(bad target for YCbCr texture)",
1912 _mesa_snprintf(message
, sizeof(message
),
1913 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1914 dimensions
, border
);
1915 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1920 /* additional checks for depth textures */
1921 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1922 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1923 "glTexImage%dD(bad target for texture)", dimensions
);
1927 /* additional checks for compressed textures */
1928 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1930 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1931 _mesa_error(ctx
, err
,
1932 "glTexImage%dD(target can't be compressed)", dimensions
);
1935 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
1936 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1937 "glTexImage%dD(no compression for format)", dimensions
);
1941 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1942 "glTexImage%dD(border!=0)", dimensions
);
1947 /* additional checks for integer textures */
1948 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1949 (_mesa_is_enum_format_integer(format
) !=
1950 _mesa_is_enum_format_integer(internalFormat
))) {
1951 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1952 "glTexImage%dD(integer/non-integer format mismatch)",
1957 if (!mutable_tex_object(ctx
, target
)) {
1958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1959 "glTexImage%dD(immutable texture)", dimensions
);
1963 /* if we get here, the parameters are OK */
1969 * Error checking for glCompressedTexImage[123]D().
1970 * Note that the width, height and depth values are not fully error checked
1972 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1975 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
1976 GLenum target
, GLint level
,
1977 GLenum internalFormat
, GLsizei width
,
1978 GLsizei height
, GLsizei depth
, GLint border
,
1979 GLsizei imageSize
, const GLvoid
*data
)
1981 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1983 GLenum error
= GL_NO_ERROR
;
1984 char *reason
= ""; /* no error */
1986 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
1991 /* This will detect any invalid internalFormat value */
1992 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
1993 _mesa_error(ctx
, GL_INVALID_ENUM
,
1994 "glCompressedTexImage%dD(internalFormat=%s)",
1995 dimensions
, _mesa_enum_to_string(internalFormat
));
1999 /* validate the bound PBO, if any */
2000 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2002 "glCompressedTexImage")) {
2006 switch (internalFormat
) {
2007 case GL_PALETTE4_RGB8_OES
:
2008 case GL_PALETTE4_RGBA8_OES
:
2009 case GL_PALETTE4_R5_G6_B5_OES
:
2010 case GL_PALETTE4_RGBA4_OES
:
2011 case GL_PALETTE4_RGB5_A1_OES
:
2012 case GL_PALETTE8_RGB8_OES
:
2013 case GL_PALETTE8_RGBA8_OES
:
2014 case GL_PALETTE8_R5_G6_B5_OES
:
2015 case GL_PALETTE8_RGBA4_OES
:
2016 case GL_PALETTE8_RGB5_A1_OES
:
2017 /* check level (note that level should be zero or less!) */
2018 if (level
> 0 || level
< -maxLevels
) {
2020 error
= GL_INVALID_VALUE
;
2024 if (dimensions
!= 2) {
2025 reason
= "compressed paletted textures must be 2D";
2026 error
= GL_INVALID_OPERATION
;
2030 /* Figure out the expected texture size (in bytes). This will be
2031 * checked against the actual size later.
2033 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2036 /* This is for the benefit of the TestProxyTexImage below. It expects
2037 * level to be non-negative. OES_compressed_paletted_texture uses a
2038 * weird mechanism where the level specified to glCompressedTexImage2D
2039 * is -(n-1) number of levels in the texture, and the data specifies the
2040 * complete mipmap stack. This is done to ensure the palette is the
2041 * same for all levels.
2048 if (level
< 0 || level
>= maxLevels
) {
2050 error
= GL_INVALID_VALUE
;
2054 /* Figure out the expected texture size (in bytes). This will be
2055 * checked against the actual size later.
2057 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2061 /* This should really never fail */
2062 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2063 reason
= "internalFormat";
2064 error
= GL_INVALID_ENUM
;
2068 /* No compressed formats support borders at this time */
2070 reason
= "border != 0";
2071 error
= GL_INVALID_VALUE
;
2075 /* Check for invalid pixel storage modes */
2076 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2078 "glCompressedTexImage")) {
2082 /* check image size in bytes */
2083 if (expectedSize
!= imageSize
) {
2084 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2085 * if <imageSize> is not consistent with the format, dimensions, and
2086 * contents of the specified image.
2088 reason
= "imageSize inconsistent with width/height/format";
2089 error
= GL_INVALID_VALUE
;
2093 if (!mutable_tex_object(ctx
, target
)) {
2094 reason
= "immutable texture";
2095 error
= GL_INVALID_OPERATION
;
2102 /* Note: not all error paths exit through here. */
2103 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2104 dimensions
, reason
);
2111 * Test glTexSubImage[123]D() parameters for errors.
2113 * \param ctx GL context.
2114 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2115 * \param target texture target given by the user (already validated)
2116 * \param level image level given by the user.
2117 * \param xoffset sub-image x offset given by the user.
2118 * \param yoffset sub-image y offset given by the user.
2119 * \param zoffset sub-image z offset given by the user.
2120 * \param format pixel data format given by the user.
2121 * \param type pixel data type given by the user.
2122 * \param width image width given by the user.
2123 * \param height image height given by the user.
2124 * \param depth image depth given by the user.
2126 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2128 * Verifies each of the parameters against the constants specified in
2129 * __struct gl_contextRec::Const and the supported extensions, and according
2130 * to the OpenGL specification.
2133 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2134 struct gl_texture_object
*texObj
,
2135 GLenum target
, GLint level
,
2136 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2137 GLint width
, GLint height
, GLint depth
,
2138 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2139 bool dsa
, const char *callerName
)
2141 struct gl_texture_image
*texImage
;
2145 /* must be out of memory */
2146 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2151 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2152 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2156 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2157 width
, height
, depth
,
2162 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2164 /* non-existant texture level */
2165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2170 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2171 if (err
!= GL_NO_ERROR
) {
2172 _mesa_error(ctx
, err
,
2173 "%s(incompatible format = %s, type = %s)",
2174 callerName
, _mesa_enum_to_string(format
),
2175 _mesa_enum_to_string(type
));
2179 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2180 * combinations of format, internalFormat, and type that can be used.
2181 * Formats and types that require additional extensions (e.g., GL_FLOAT
2182 * requires GL_OES_texture_float) are filtered elsewhere.
2184 if (_mesa_is_gles(ctx
) &&
2185 texture_format_error_check_gles(ctx
, format
, type
,
2186 texImage
->InternalFormat
,
2187 dimensions
, callerName
)) {
2191 /* validate the bound PBO, if any */
2192 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2193 width
, height
, depth
, format
, type
,
2194 INT_MAX
, pixels
, callerName
)) {
2198 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2199 texImage
, xoffset
, yoffset
, zoffset
,
2200 width
, height
, depth
, callerName
)) {
2204 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2205 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2206 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2207 "%s(no compression for format)", callerName
);
2212 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2213 /* both source and dest must be integer-valued, or neither */
2214 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2215 _mesa_is_enum_format_integer(format
)) {
2216 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2217 "%s(integer/non-integer format mismatch)", callerName
);
2227 * Test glCopyTexImage[12]D() parameters for errors.
2229 * \param ctx GL context.
2230 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2231 * \param target texture target given by the user.
2232 * \param level image level given by the user.
2233 * \param internalFormat internal format given by the user.
2234 * \param width image width given by the user.
2235 * \param height image height given by the user.
2236 * \param border texture border.
2238 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2240 * Verifies each of the parameters against the constants specified in
2241 * __struct gl_contextRec::Const and the supported extensions, and according
2242 * to the OpenGL specification.
2245 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2246 GLenum target
, GLint level
, GLint internalFormat
,
2247 GLint width
, GLint height
, GLint border
)
2250 GLint rb_base_format
;
2251 struct gl_renderbuffer
*rb
;
2252 GLenum rb_internal_format
;
2255 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2256 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2257 dimensions
, _mesa_enum_to_string(target
));
2262 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2263 _mesa_error(ctx
, GL_INVALID_VALUE
,
2264 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2268 /* Check that the source buffer is complete */
2269 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2270 if (ctx
->ReadBuffer
->_Status
== 0) {
2271 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2273 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2274 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2275 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2279 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2281 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2287 if (border
< 0 || border
> 1 ||
2288 ((ctx
->API
!= API_OPENGL_COMPAT
||
2289 target
== GL_TEXTURE_RECTANGLE_NV
||
2290 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2291 _mesa_error(ctx
, GL_INVALID_VALUE
,
2292 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2296 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2299 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2300 switch (internalFormat
) {
2305 case GL_LUMINANCE_ALPHA
:
2308 _mesa_error(ctx
, GL_INVALID_ENUM
,
2309 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2310 _mesa_enum_to_string(internalFormat
));
2315 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2316 * OpenGL 4.5 (Compatibility Profile) spec says:
2318 * "Parameters level, internalformat, and border are specified using
2319 * the same values, with the same meanings, as the corresponding
2320 * arguments of TexImage2D, except that internalformat may not be
2321 * specified as 1, 2, 3, or 4."
2323 if (internalFormat
>= 1 && internalFormat
<= 4) {
2324 _mesa_error(ctx
, GL_INVALID_ENUM
,
2325 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2331 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2332 if (baseFormat
< 0) {
2333 _mesa_error(ctx
, GL_INVALID_ENUM
,
2334 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2335 _mesa_enum_to_string(internalFormat
));
2339 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2342 "glCopyTexImage%dD(read buffer)", dimensions
);
2346 rb_internal_format
= rb
->InternalFormat
;
2347 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2348 if (_mesa_is_color_format(internalFormat
)) {
2349 if (rb_base_format
< 0) {
2350 _mesa_error(ctx
, GL_INVALID_VALUE
,
2351 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2352 _mesa_enum_to_string(internalFormat
));
2357 if (_mesa_is_gles(ctx
)) {
2359 if (_mesa_base_format_component_count(baseFormat
) >
2360 _mesa_base_format_component_count(rb_base_format
)) {
2363 if (baseFormat
== GL_DEPTH_COMPONENT
||
2364 baseFormat
== GL_DEPTH_STENCIL
||
2365 baseFormat
== GL_STENCIL_INDEX
||
2366 rb_base_format
== GL_DEPTH_COMPONENT
||
2367 rb_base_format
== GL_DEPTH_STENCIL
||
2368 rb_base_format
== GL_STENCIL_INDEX
||
2369 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2370 baseFormat
== GL_ALPHA
) &&
2371 rb_base_format
!= GL_RGBA
) ||
2372 internalFormat
== GL_RGB9_E5
) {
2375 if (internalFormat
== GL_RGB9_E5
) {
2379 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2380 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2381 _mesa_enum_to_string(internalFormat
));
2386 if (_mesa_is_gles3(ctx
)) {
2387 bool rb_is_srgb
= false;
2388 bool dst_is_srgb
= false;
2390 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2391 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2395 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2399 if (rb_is_srgb
!= dst_is_srgb
) {
2400 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2401 * OpenGLES 3.0.0 spec says:
2403 * "The error INVALID_OPERATION is also generated if the
2404 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2405 * framebuffer attachment corresponding to the read buffer
2406 * is LINEAR (see section 6.1.13) and internalformat is
2407 * one of the sRGB formats described in section 3.8.16, or
2408 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2409 * SRGB and internalformat is not one of the sRGB formats."
2411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2412 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2416 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2417 * types for SNORM formats. Also, conversion to SNORM formats is not
2418 * allowed by Table 3.2 on Page 110.
2420 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2421 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2422 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2423 _mesa_enum_to_string(internalFormat
));
2428 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2429 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2430 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2434 /* From the EXT_texture_integer spec:
2436 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2437 * if the texture internalformat is an integer format and the read color
2438 * buffer is not an integer format, or if the internalformat is not an
2439 * integer format and the read color buffer is an integer format."
2441 if (_mesa_is_color_format(internalFormat
)) {
2442 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2443 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2444 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2445 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2446 if (is_int
|| is_rbint
) {
2447 if (is_int
!= is_rbint
) {
2448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2449 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2451 } else if (_mesa_is_gles(ctx
) &&
2452 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2453 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2455 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2460 /* From page 138 of OpenGL ES 3.0 spec:
2461 * "The error INVALID_OPERATION is generated if floating-point RGBA
2462 * data is required; if signed integer RGBA data is required and the
2463 * format of the current color buffer is not signed integer; if
2464 * unsigned integer RGBA data is required and the format of the
2465 * current color buffer is not unsigned integer; or if fixed-point
2466 * RGBA data is required and the format of the current color buffer
2467 * is not fixed-point.
2469 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2471 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2474 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2476 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2477 _mesa_error(ctx
, err
,
2478 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2481 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2482 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2483 "glCopyTexImage%dD(no compression for format)", dimensions
);
2487 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2488 "glCopyTexImage%dD(border!=0)", dimensions
);
2493 if (!mutable_tex_object(ctx
, target
)) {
2494 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2495 "glCopyTexImage%dD(immutable texture)", dimensions
);
2499 /* if we get here, the parameters are OK */
2505 * Test glCopyTexSubImage[12]D() parameters for errors.
2506 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2509 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2510 const struct gl_texture_object
*texObj
,
2511 GLenum target
, GLint level
,
2512 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2513 GLint width
, GLint height
, const char *caller
)
2515 struct gl_texture_image
*texImage
;
2517 /* Check that the source buffer is complete */
2518 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2519 if (ctx
->ReadBuffer
->_Status
== 0) {
2520 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2522 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2523 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2524 "%s(invalid readbuffer)", caller
);
2528 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2530 "%s(multisample FBO)", caller
);
2536 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2537 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2541 /* Get dest image pointers */
2543 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2547 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2549 /* destination image does not exist */
2550 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2551 "%s(invalid texture image)", caller
);
2555 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2556 width
, height
, 1, caller
)) {
2560 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2561 xoffset
, yoffset
, zoffset
,
2562 width
, height
, 1, caller
)) {
2566 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2567 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2568 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2569 "%s(no compression for format)", caller
);
2574 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2575 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2579 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2581 "%s(missing readbuffer, format=%s)", caller
,
2582 _mesa_enum_to_string(texImage
->_BaseFormat
));
2586 /* From the EXT_texture_integer spec:
2588 * "INVALID_OPERATION is generated by CopyTexImage* and
2589 * CopyTexSubImage* if the texture internalformat is an integer format
2590 * and the read color buffer is not an integer format, or if the
2591 * internalformat is not an integer format and the read color buffer
2592 * is an integer format."
2594 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2595 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2597 if (_mesa_is_format_integer_color(rb
->Format
) !=
2598 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2600 "%s(integer vs non-integer)", caller
);
2605 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2606 * framebuffer/destination texture base internal format combinations),
2607 * all the entries for stencil are left blank (unsupported).
2609 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2610 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2614 /* if we get here, the parameters are OK */
2619 /** Callback info for walking over FBO hash table */
2622 struct gl_context
*ctx
;
2623 struct gl_texture_object
*texObj
;
2629 * Check render to texture callback. Called from _mesa_HashWalk().
2632 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2634 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2635 const struct cb_info
*info
= (struct cb_info
*) userData
;
2636 struct gl_context
*ctx
= info
->ctx
;
2637 const struct gl_texture_object
*texObj
= info
->texObj
;
2638 const GLuint level
= info
->level
, face
= info
->face
;
2640 /* If this is a user-created FBO */
2641 if (_mesa_is_user_fbo(fb
)) {
2643 /* check if any of the FBO's attachments point to 'texObj' */
2644 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2645 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2646 if (att
->Type
== GL_TEXTURE
&&
2647 att
->Texture
== texObj
&&
2648 att
->TextureLevel
== level
&&
2649 att
->CubeMapFace
== face
) {
2650 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2651 assert(att
->Renderbuffer
->TexImage
);
2652 /* Mark fb status as indeterminate to force re-validation */
2655 /* Make sure that the revalidation actually happens if this is
2656 * being done to currently-bound buffers.
2658 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2659 ctx
->NewState
|= _NEW_BUFFERS
;
2667 * When a texture image is specified we have to check if it's bound to
2668 * any framebuffer objects (render to texture) in order to detect changes
2669 * in size or format since that effects FBO completeness.
2670 * Any FBOs rendering into the texture must be re-validated.
2673 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2674 struct gl_texture_object
*texObj
,
2675 GLuint face
, GLuint level
)
2677 /* Only check this texture if it's been marked as RenderToTexture */
2678 if (texObj
->_RenderToTexture
) {
2679 struct cb_info info
;
2681 info
.texObj
= texObj
;
2684 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2690 * If the texture object's GenerateMipmap flag is set and we've
2691 * changed the texture base level image, regenerate the rest of the
2692 * mipmap levels now.
2695 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2696 struct gl_texture_object
*texObj
, GLint level
)
2698 if (texObj
->GenerateMipmap
&&
2699 level
== texObj
->BaseLevel
&&
2700 level
< texObj
->MaxLevel
) {
2701 assert(ctx
->Driver
.GenerateMipmap
);
2702 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2707 /** Debug helper: override the user-requested internal format */
2709 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2712 if (internalFormat
== GL_RGBA16F_ARB
||
2713 internalFormat
== GL_RGBA32F_ARB
) {
2714 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2717 else if (internalFormat
== GL_RGB16F_ARB
||
2718 internalFormat
== GL_RGB32F_ARB
) {
2719 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2722 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2723 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2724 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2725 return GL_LUMINANCE_ALPHA
;
2727 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2728 internalFormat
== GL_LUMINANCE32F_ARB
) {
2729 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2730 return GL_LUMINANCE
;
2732 else if (internalFormat
== GL_ALPHA16F_ARB
||
2733 internalFormat
== GL_ALPHA32F_ARB
) {
2734 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2738 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2739 internalFormat = GL_RGBA;
2743 return internalFormat
;
2746 return internalFormat
;
2752 * Choose the actual hardware format for a texture image.
2753 * Try to use the same format as the previous image level when possible.
2754 * Otherwise, ask the driver for the best format.
2755 * It's important to try to choose a consistant format for all levels
2756 * for efficient texture memory layout/allocation. In particular, this
2757 * comes up during automatic mipmap generation.
2760 _mesa_choose_texture_format(struct gl_context
*ctx
,
2761 struct gl_texture_object
*texObj
,
2762 GLenum target
, GLint level
,
2763 GLenum internalFormat
, GLenum format
, GLenum type
)
2767 /* see if we've already chosen a format for the previous level */
2769 struct gl_texture_image
*prevImage
=
2770 _mesa_select_tex_image(texObj
, target
, level
- 1);
2771 /* See if the prev level is defined and has an internal format which
2772 * matches the new internal format.
2775 prevImage
->Width
> 0 &&
2776 prevImage
->InternalFormat
== internalFormat
) {
2777 /* use the same format */
2778 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2779 return prevImage
->TexFormat
;
2783 /* If the application requested compression to an S3TC format but we don't
2784 * have the DXTn library, force a generic compressed format instead.
2786 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2787 const GLenum before
= internalFormat
;
2789 switch (internalFormat
) {
2790 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2791 if (!ctx
->Mesa_DXTn
)
2792 internalFormat
= GL_COMPRESSED_RGB
;
2794 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2795 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2796 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2797 if (!ctx
->Mesa_DXTn
)
2798 internalFormat
= GL_COMPRESSED_RGBA
;
2804 if (before
!= internalFormat
) {
2806 "DXT compression requested (%s), "
2807 "but libtxc_dxtn library not installed. Using %s "
2809 _mesa_enum_to_string(before
),
2810 _mesa_enum_to_string(internalFormat
));
2814 /* choose format from scratch */
2815 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2817 assert(f
!= MESA_FORMAT_NONE
);
2823 * Adjust pixel unpack params and image dimensions to strip off the
2824 * one-pixel texture border.
2826 * Gallium and intel don't support texture borders. They've seldem been used
2827 * and seldom been implemented correctly anyway.
2829 * \param unpackNew returns the new pixel unpack parameters
2832 strip_texture_border(GLenum target
,
2833 GLint
*width
, GLint
*height
, GLint
*depth
,
2834 const struct gl_pixelstore_attrib
*unpack
,
2835 struct gl_pixelstore_attrib
*unpackNew
)
2841 *unpackNew
= *unpack
;
2843 if (unpackNew
->RowLength
== 0)
2844 unpackNew
->RowLength
= *width
;
2846 if (unpackNew
->ImageHeight
== 0)
2847 unpackNew
->ImageHeight
= *height
;
2849 assert(*width
>= 3);
2850 unpackNew
->SkipPixels
++; /* skip the border */
2851 *width
= *width
- 2; /* reduce the width by two border pixels */
2853 /* The min height of a texture with a border is 3 */
2854 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2855 unpackNew
->SkipRows
++; /* skip the border */
2856 *height
= *height
- 2; /* reduce the height by two border pixels */
2860 target
!= GL_TEXTURE_2D_ARRAY
&&
2861 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2862 unpackNew
->SkipImages
++; /* skip the border */
2863 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2869 * Common code to implement all the glTexImage1D/2D/3D functions
2870 * as well as glCompressedTexImage1D/2D/3D.
2871 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2872 * \param format the user's image format (only used if !compressed)
2873 * \param type the user's image type (only used if !compressed)
2874 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2877 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2878 GLenum target
, GLint level
, GLint internalFormat
,
2879 GLsizei width
, GLsizei height
, GLsizei depth
,
2880 GLint border
, GLenum format
, GLenum type
,
2881 GLsizei imageSize
, const GLvoid
*pixels
)
2883 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2884 struct gl_pixelstore_attrib unpack_no_border
;
2885 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2886 struct gl_texture_object
*texObj
;
2887 mesa_format texFormat
;
2888 GLboolean dimensionsOK
, sizeOK
;
2890 FLUSH_VERTICES(ctx
, 0);
2892 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2895 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2897 _mesa_enum_to_string(target
), level
,
2898 _mesa_enum_to_string(internalFormat
),
2899 width
, height
, depth
, border
, pixels
);
2902 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2904 _mesa_enum_to_string(target
), level
,
2905 _mesa_enum_to_string(internalFormat
),
2906 width
, height
, depth
, border
,
2907 _mesa_enum_to_string(format
),
2908 _mesa_enum_to_string(type
), pixels
);
2911 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2913 /* target error checking */
2914 if (!legal_teximage_target(ctx
, dims
, target
)) {
2915 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2916 func
, dims
, _mesa_enum_to_string(target
));
2920 /* general error checking */
2922 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2924 width
, height
, depth
,
2925 border
, imageSize
, pixels
))
2929 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2930 format
, type
, width
, height
, depth
, border
,
2935 /* Here we convert a cpal compressed image into a regular glTexImage2D
2936 * call by decompressing the texture. If we really want to support cpal
2937 * textures in any driver this would have to be changed.
2939 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2940 switch (internalFormat
) {
2941 case GL_PALETTE4_RGB8_OES
:
2942 case GL_PALETTE4_RGBA8_OES
:
2943 case GL_PALETTE4_R5_G6_B5_OES
:
2944 case GL_PALETTE4_RGBA4_OES
:
2945 case GL_PALETTE4_RGB5_A1_OES
:
2946 case GL_PALETTE8_RGB8_OES
:
2947 case GL_PALETTE8_RGBA8_OES
:
2948 case GL_PALETTE8_R5_G6_B5_OES
:
2949 case GL_PALETTE8_RGBA4_OES
:
2950 case GL_PALETTE8_RGB5_A1_OES
:
2951 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2952 width
, height
, imageSize
, pixels
);
2957 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2961 /* For glCompressedTexImage() the driver has no choice about the
2962 * texture format since we'll never transcode the user's compressed
2963 * image data. The internalFormat was error checked earlier.
2965 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
2968 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
2969 * internal floating point format for the given base format.
2971 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
2972 if (type
== GL_FLOAT
) {
2973 texObj
->_IsFloat
= GL_TRUE
;
2974 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
2975 texObj
->_IsHalfFloat
= GL_TRUE
;
2978 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
2981 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2982 internalFormat
, format
, type
);
2985 assert(texFormat
!= MESA_FORMAT_NONE
);
2987 /* check that width, height, depth are legal for the mipmap level */
2988 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2989 height
, depth
, border
);
2991 /* check that the texture won't take too much memory, etc */
2992 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
2993 0, level
, texFormat
, 1,
2994 width
, height
, depth
);
2996 if (_mesa_is_proxy_texture(target
)) {
2997 /* Proxy texture: just clear or set state depending on error checking */
2998 struct gl_texture_image
*texImage
=
2999 get_proxy_tex_image(ctx
, target
, level
);
3002 return; /* GL_OUT_OF_MEMORY already recorded */
3004 if (dimensionsOK
&& sizeOK
) {
3005 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3006 border
, internalFormat
, texFormat
);
3009 clear_teximage_fields(texImage
);
3013 /* non-proxy target */
3014 const GLuint face
= _mesa_tex_target_to_face(target
);
3015 struct gl_texture_image
*texImage
;
3017 if (!dimensionsOK
) {
3018 _mesa_error(ctx
, GL_INVALID_VALUE
,
3019 "%s%uD(invalid width or height or depth)",
3025 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3026 "%s%uD(image too large: %d x %d x %d, %s format)",
3027 func
, dims
, width
, height
, depth
,
3028 _mesa_enum_to_string(internalFormat
));
3032 /* Allow a hardware driver to just strip out the border, to provide
3033 * reliable but slightly incorrect hardware rendering instead of
3034 * rarely-tested software fallback rendering.
3036 if (border
&& ctx
->Const
.StripTextureBorder
) {
3037 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3040 unpack
= &unpack_no_border
;
3043 if (ctx
->NewState
& _NEW_PIXEL
)
3044 _mesa_update_state(ctx
);
3046 _mesa_lock_texture(ctx
, texObj
);
3048 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3051 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3054 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3056 _mesa_init_teximage_fields(ctx
, texImage
,
3057 width
, height
, depth
,
3058 border
, internalFormat
, texFormat
);
3060 /* Give the texture to the driver. <pixels> may be null. */
3061 if (width
> 0 && height
> 0 && depth
> 0) {
3063 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3067 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3068 type
, pixels
, unpack
);
3072 check_gen_mipmap(ctx
, target
, texObj
, level
);
3074 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3076 _mesa_dirty_texobj(ctx
, texObj
);
3079 _mesa_unlock_texture(ctx
, texObj
);
3086 * Called from the API. Note that width includes the border.
3089 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3090 GLsizei width
, GLint border
, GLenum format
,
3091 GLenum type
, const GLvoid
*pixels
)
3093 GET_CURRENT_CONTEXT(ctx
);
3094 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3095 border
, format
, type
, 0, pixels
);
3100 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3101 GLsizei width
, GLsizei height
, GLint border
,
3102 GLenum format
, GLenum type
,
3103 const GLvoid
*pixels
)
3105 GET_CURRENT_CONTEXT(ctx
);
3106 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3107 border
, format
, type
, 0, pixels
);
3112 * Called by the API or display list executor.
3113 * Note that width and height include the border.
3116 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3117 GLsizei width
, GLsizei height
, GLsizei depth
,
3118 GLint border
, GLenum format
, GLenum type
,
3119 const GLvoid
*pixels
)
3121 GET_CURRENT_CONTEXT(ctx
);
3122 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3123 width
, height
, depth
,
3124 border
, format
, type
, 0, pixels
);
3129 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3130 GLsizei width
, GLsizei height
, GLsizei depth
,
3131 GLint border
, GLenum format
, GLenum type
,
3132 const GLvoid
*pixels
)
3134 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3135 depth
, border
, format
, type
, pixels
);
3140 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3142 struct gl_texture_object
*texObj
;
3143 struct gl_texture_image
*texImage
;
3145 GET_CURRENT_CONTEXT(ctx
);
3146 FLUSH_VERTICES(ctx
, 0);
3150 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3152 case GL_TEXTURE_EXTERNAL_OES
:
3154 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3157 valid_target
= false;
3161 if (!valid_target
) {
3162 _mesa_error(ctx
, GL_INVALID_ENUM
,
3163 "glEGLImageTargetTexture2D(target=%d)", target
);
3168 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3169 "glEGLImageTargetTexture2D(image=%p)", image
);
3173 if (ctx
->NewState
& _NEW_PIXEL
)
3174 _mesa_update_state(ctx
);
3176 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3180 _mesa_lock_texture(ctx
, texObj
);
3182 if (texObj
->Immutable
) {
3183 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3184 "glEGLImageTargetTexture2D(texture is immutable)");
3185 _mesa_unlock_texture(ctx
, texObj
);
3189 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3191 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3193 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3195 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3196 texObj
, texImage
, image
);
3198 _mesa_dirty_texobj(ctx
, texObj
);
3200 _mesa_unlock_texture(ctx
, texObj
);
3205 * Helper that implements the glTexSubImage1/2/3D()
3206 * and glTextureSubImage1/2/3D() functions.
3209 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3210 struct gl_texture_object
*texObj
,
3211 struct gl_texture_image
*texImage
,
3212 GLenum target
, GLint level
,
3213 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3214 GLsizei width
, GLsizei height
, GLsizei depth
,
3215 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3218 FLUSH_VERTICES(ctx
, 0);
3220 if (ctx
->NewState
& _NEW_PIXEL
)
3221 _mesa_update_state(ctx
);
3223 _mesa_lock_texture(ctx
, texObj
);
3225 if (width
> 0 && height
> 0 && depth
> 0) {
3226 /* If we have a border, offset=-1 is legal. Bias by border width. */
3229 if (target
!= GL_TEXTURE_2D_ARRAY
)
3230 zoffset
+= texImage
->Border
;
3233 if (target
!= GL_TEXTURE_1D_ARRAY
)
3234 yoffset
+= texImage
->Border
;
3237 xoffset
+= texImage
->Border
;
3240 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3241 xoffset
, yoffset
, zoffset
,
3242 width
, height
, depth
,
3243 format
, type
, pixels
, &ctx
->Unpack
);
3245 check_gen_mipmap(ctx
, target
, texObj
, level
);
3247 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3248 * the texel data, not the texture format, size, etc.
3252 _mesa_unlock_texture(ctx
, texObj
);
3256 * Implement all the glTexSubImage1/2/3D() functions.
3257 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3260 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3261 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3262 GLsizei width
, GLsizei height
, GLsizei depth
,
3263 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3264 const char *callerName
)
3266 struct gl_texture_object
*texObj
;
3267 struct gl_texture_image
*texImage
;
3269 /* check target (proxies not allowed) */
3270 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3271 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3272 dims
, _mesa_enum_to_string(target
));
3276 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3280 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3281 xoffset
, yoffset
, zoffset
,
3282 width
, height
, depth
, format
, type
,
3283 pixels
, false, callerName
)) {
3284 return; /* error was detected */
3287 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3288 /* texsubimage_error_check ensures that texImage is not NULL */
3290 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3291 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3293 _mesa_enum_to_string(target
), level
,
3294 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3295 _mesa_enum_to_string(format
),
3296 _mesa_enum_to_string(type
), pixels
);
3298 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3299 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3300 format
, type
, pixels
, false);
3305 * Implement all the glTextureSubImage1/2/3D() functions.
3306 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3309 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3310 GLuint texture
, GLint level
,
3311 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3312 GLsizei width
, GLsizei height
, GLsizei depth
,
3313 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3314 const char *callerName
)
3316 struct gl_texture_object
*texObj
;
3317 struct gl_texture_image
*texImage
;
3320 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3322 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3323 dims
, texture
, level
,
3324 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3325 _mesa_enum_to_string(format
),
3326 _mesa_enum_to_string(type
), pixels
);
3328 /* Get the texture object by Name. */
3329 texObj
= _mesa_lookup_texture(ctx
, texture
);
3331 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3336 /* check target (proxies not allowed) */
3337 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3338 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3339 callerName
, _mesa_enum_to_string(texObj
->Target
));
3343 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3344 xoffset
, yoffset
, zoffset
,
3345 width
, height
, depth
, format
, type
,
3346 pixels
, true, callerName
)) {
3347 return; /* error was detected */
3351 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3352 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3356 * What do we do if the user created a texture with the following code
3357 * and then called this function with its handle?
3360 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3361 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3362 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3363 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3364 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3365 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3366 * // wrong format, or given the wrong size, etc.
3367 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3368 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3370 * A bug has been filed against the spec for this case. In the
3371 * meantime, we will check for cube completeness.
3373 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3374 * Core Profile spec (30.10.2014):
3375 * "[A] cube map texture is cube complete if the
3376 * following conditions all hold true: The [base level] texture
3377 * images of each of the six cube map faces have identical, positive,
3378 * and square dimensions. The [base level] images were each specified
3379 * with the same internal format."
3381 * It seems reasonable to check for cube completeness of an arbitrary
3382 * level here so that the image data has a consistent format and size.
3384 if (!_mesa_cube_level_complete(texObj
, level
)) {
3385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3386 "glTextureSubImage%uD(cube map incomplete)",
3391 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3393 /* Copy in each face. */
3394 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3395 texImage
= texObj
->Image
[i
][level
];
3398 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3399 level
, xoffset
, yoffset
, 0,
3400 width
, height
, 1, format
,
3401 type
, pixels
, true);
3402 pixels
= (GLubyte
*) pixels
+ imageStride
;
3406 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3409 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3410 level
, xoffset
, yoffset
, zoffset
,
3411 width
, height
, depth
, format
,
3412 type
, pixels
, true);
3418 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3419 GLint xoffset
, GLsizei width
,
3420 GLenum format
, GLenum type
,
3421 const GLvoid
*pixels
)
3423 GET_CURRENT_CONTEXT(ctx
);
3424 texsubimage(ctx
, 1, target
, level
,
3427 format
, type
, pixels
, "glTexSubImage1D");
3432 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3433 GLint xoffset
, GLint yoffset
,
3434 GLsizei width
, GLsizei height
,
3435 GLenum format
, GLenum type
,
3436 const GLvoid
*pixels
)
3438 GET_CURRENT_CONTEXT(ctx
);
3439 texsubimage(ctx
, 2, target
, level
,
3440 xoffset
, yoffset
, 0,
3442 format
, type
, pixels
, "glTexSubImage2D");
3448 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3449 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3450 GLsizei width
, GLsizei height
, GLsizei depth
,
3451 GLenum format
, GLenum type
,
3452 const GLvoid
*pixels
)
3454 GET_CURRENT_CONTEXT(ctx
);
3455 texsubimage(ctx
, 3, target
, level
,
3456 xoffset
, yoffset
, zoffset
,
3457 width
, height
, depth
,
3458 format
, type
, pixels
, "glTexSubImage3D");
3462 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3463 GLint xoffset
, GLsizei width
,
3464 GLenum format
, GLenum type
,
3465 const GLvoid
*pixels
)
3467 GET_CURRENT_CONTEXT(ctx
);
3468 texturesubimage(ctx
, 1, texture
, level
,
3471 format
, type
, pixels
, "glTextureSubImage1D");
3476 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3477 GLint xoffset
, GLint yoffset
,
3478 GLsizei width
, GLsizei height
,
3479 GLenum format
, GLenum type
,
3480 const GLvoid
*pixels
)
3482 GET_CURRENT_CONTEXT(ctx
);
3483 texturesubimage(ctx
, 2, texture
, level
,
3484 xoffset
, yoffset
, 0,
3486 format
, type
, pixels
, "glTextureSubImage2D");
3491 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3492 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3493 GLsizei width
, GLsizei height
, GLsizei depth
,
3494 GLenum format
, GLenum type
,
3495 const GLvoid
*pixels
)
3497 GET_CURRENT_CONTEXT(ctx
);
3498 texturesubimage(ctx
, 3, texture
, level
,
3499 xoffset
, yoffset
, zoffset
,
3500 width
, height
, depth
,
3501 format
, type
, pixels
, "glTextureSubImage3D");
3506 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3507 * from. This depends on whether the texture contains color or depth values.
3509 static struct gl_renderbuffer
*
3510 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3512 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3513 /* reading from depth/stencil buffer */
3514 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3515 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3516 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3518 /* copying from color buffer */
3519 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3524 copytexsubimage_by_slice(struct gl_context
*ctx
,
3525 struct gl_texture_image
*texImage
,
3527 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3528 struct gl_renderbuffer
*rb
,
3530 GLsizei width
, GLsizei height
)
3532 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3535 /* For 1D arrays, we copy each scanline of the source rectangle into the
3538 assert(zoffset
== 0);
3540 for (slice
= 0; slice
< height
; slice
++) {
3541 assert(yoffset
+ slice
< texImage
->Height
);
3542 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3543 xoffset
, 0, yoffset
+ slice
,
3544 rb
, x
, y
+ slice
, width
, 1);
3547 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3548 xoffset
, yoffset
, zoffset
,
3549 rb
, x
, y
, width
, height
);
3554 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3556 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3557 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3558 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3559 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3561 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3562 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3563 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3564 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3566 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3567 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3568 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3569 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3576 can_avoid_reallocation(struct gl_texture_image
*texImage
, GLenum internalFormat
,
3577 mesa_format texFormat
, GLint x
, GLint y
, GLsizei width
,
3578 GLsizei height
, GLint border
)
3580 if (texImage
->InternalFormat
!= internalFormat
)
3582 if (texImage
->TexFormat
!= texFormat
)
3584 if (texImage
->Border
!= border
)
3586 if (texImage
->Width2
!= width
)
3588 if (texImage
->Height2
!= height
)
3594 * Implement the glCopyTexImage1/2D() functions.
3597 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3598 GLenum target
, GLint level
, GLenum internalFormat
,
3599 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3601 struct gl_texture_object
*texObj
;
3602 struct gl_texture_image
*texImage
;
3603 const GLuint face
= _mesa_tex_target_to_face(target
);
3604 mesa_format texFormat
;
3605 struct gl_renderbuffer
*rb
;
3607 FLUSH_VERTICES(ctx
, 0);
3609 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3610 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3612 _mesa_enum_to_string(target
), level
,
3613 _mesa_enum_to_string(internalFormat
),
3614 x
, y
, width
, height
, border
);
3616 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3617 _mesa_update_state(ctx
);
3619 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3620 width
, height
, border
))
3623 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3625 _mesa_error(ctx
, GL_INVALID_VALUE
,
3626 "glCopyTexImage%uD(invalid width or height)", dims
);
3630 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3633 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3634 internalFormat
, GL_NONE
, GL_NONE
);
3636 /* First check if reallocating the texture buffer can be avoided.
3637 * Without the realloc the copy can be 20x faster.
3639 _mesa_lock_texture(ctx
, texObj
);
3641 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3642 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3643 x
, y
, width
, height
, border
)) {
3644 _mesa_unlock_texture(ctx
, texObj
);
3645 return _mesa_copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
,
3646 0, 0, 0, x
, y
, width
, height
,
3650 _mesa_unlock_texture(ctx
, texObj
);
3651 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3652 "can't avoid reallocating texture storage\n");
3654 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3656 if (_mesa_is_gles3(ctx
)) {
3657 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3658 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3659 * OpenGL ES 3.0. Khronos bug# 9807.
3661 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3662 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3663 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3664 " and writing to unsized internal format)", dims
);
3668 /* From Page 139 of OpenGL ES 3.0 spec:
3669 * "If internalformat is sized, the internal format of the new texel
3670 * array is internalformat, and this is also the new texel array’s
3671 * effective internal format. If the component sizes of internalformat
3672 * do not exactly match the corresponding component sizes of the source
3673 * buffer’s effective internal format, described below, an
3674 * INVALID_OPERATION error is generated. If internalformat is unsized,
3675 * the internal format of the new texel array is the effective internal
3676 * format of the source buffer, and this is also the new texel array’s
3677 * effective internal format.
3679 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3680 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3681 "glCopyTexImage%uD(componenet size changed in"
3682 " internal format)", dims
);
3687 assert(texFormat
!= MESA_FORMAT_NONE
);
3689 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3690 0, level
, texFormat
, 1,
3691 width
, height
, 1)) {
3692 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3693 "glCopyTexImage%uD(image too large)", dims
);
3697 if (border
&& ctx
->Const
.StripTextureBorder
) {
3699 width
-= border
* 2;
3702 height
-= border
* 2;
3707 _mesa_lock_texture(ctx
, texObj
);
3709 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3712 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3715 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3717 /* Free old texture image */
3718 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3720 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3721 border
, internalFormat
, texFormat
);
3723 if (width
&& height
) {
3724 /* Allocate texture memory (no pixel data yet) */
3725 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3727 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3729 struct gl_renderbuffer
*srcRb
=
3730 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3732 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3734 srcRb
, srcX
, srcY
, width
, height
);
3737 check_gen_mipmap(ctx
, target
, texObj
, level
);
3740 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3742 _mesa_dirty_texobj(ctx
, texObj
);
3745 _mesa_unlock_texture(ctx
, texObj
);
3751 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3752 GLenum internalFormat
,
3754 GLsizei width
, GLint border
)
3756 GET_CURRENT_CONTEXT(ctx
);
3757 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3763 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3764 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3767 GET_CURRENT_CONTEXT(ctx
);
3768 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3769 x
, y
, width
, height
, border
);
3773 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3776 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3777 struct gl_texture_object
*texObj
,
3778 GLenum target
, GLint level
,
3779 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3781 GLsizei width
, GLsizei height
,
3784 struct gl_texture_image
*texImage
;
3786 FLUSH_VERTICES(ctx
, 0);
3788 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3789 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3790 _mesa_enum_to_string(target
),
3791 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3793 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3794 _mesa_update_state(ctx
);
3796 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3797 xoffset
, yoffset
, zoffset
,
3798 width
, height
, caller
)) {
3802 _mesa_lock_texture(ctx
, texObj
);
3804 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3806 /* If we have a border, offset=-1 is legal. Bias by border width. */
3809 if (target
!= GL_TEXTURE_2D_ARRAY
)
3810 zoffset
+= texImage
->Border
;
3813 if (target
!= GL_TEXTURE_1D_ARRAY
)
3814 yoffset
+= texImage
->Border
;
3817 xoffset
+= texImage
->Border
;
3820 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3822 struct gl_renderbuffer
*srcRb
=
3823 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3825 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3826 xoffset
, yoffset
, zoffset
,
3827 srcRb
, x
, y
, width
, height
);
3829 check_gen_mipmap(ctx
, target
, texObj
, level
);
3831 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3832 * the texel data, not the texture format, size, etc.
3836 _mesa_unlock_texture(ctx
, texObj
);
3840 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3841 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3843 struct gl_texture_object
* texObj
;
3844 const char *self
= "glCopyTexSubImage1D";
3845 GET_CURRENT_CONTEXT(ctx
);
3847 /* Check target (proxies not allowed). Target must be checked prior to
3848 * calling _mesa_get_current_tex_object.
3850 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
3851 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3852 _mesa_enum_to_string(target
));
3856 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3860 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
3861 x
, y
, width
, 1, self
);
3867 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3868 GLint xoffset
, GLint yoffset
,
3869 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3871 struct gl_texture_object
* texObj
;
3872 const char *self
= "glCopyTexSubImage2D";
3873 GET_CURRENT_CONTEXT(ctx
);
3875 /* Check target (proxies not allowed). Target must be checked prior to
3876 * calling _mesa_get_current_tex_object.
3878 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
3879 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3880 _mesa_enum_to_string(target
));
3884 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3888 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
3889 xoffset
, yoffset
, 0,
3890 x
, y
, width
, height
, self
);
3896 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3897 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3898 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3900 struct gl_texture_object
* texObj
;
3901 const char *self
= "glCopyTexSubImage3D";
3902 GET_CURRENT_CONTEXT(ctx
);
3904 /* Check target (proxies not allowed). Target must be checked prior to
3905 * calling _mesa_get_current_tex_object.
3907 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
3908 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3909 _mesa_enum_to_string(target
));
3913 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3917 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
3918 xoffset
, yoffset
, zoffset
,
3919 x
, y
, width
, height
, self
);
3923 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
3924 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3926 struct gl_texture_object
* texObj
;
3927 const char *self
= "glCopyTextureSubImage1D";
3928 GET_CURRENT_CONTEXT(ctx
);
3930 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3934 /* Check target (proxies not allowed). */
3935 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
3936 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3937 _mesa_enum_to_string(texObj
->Target
));
3941 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
3942 xoffset
, 0, 0, x
, y
, width
, 1, self
);
3946 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
3947 GLint xoffset
, GLint yoffset
,
3948 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3950 struct gl_texture_object
* texObj
;
3951 const char *self
= "glCopyTextureSubImage2D";
3952 GET_CURRENT_CONTEXT(ctx
);
3954 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3958 /* Check target (proxies not allowed). */
3959 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
3960 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3961 _mesa_enum_to_string(texObj
->Target
));
3965 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
3966 xoffset
, yoffset
, 0,
3967 x
, y
, width
, height
, self
);
3973 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
3974 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3975 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3977 struct gl_texture_object
* texObj
;
3978 const char *self
= "glCopyTextureSubImage3D";
3979 GET_CURRENT_CONTEXT(ctx
);
3981 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
3985 /* Check target (proxies not allowed). */
3986 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
3987 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
3988 _mesa_enum_to_string(texObj
->Target
));
3992 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3993 /* Act like CopyTexSubImage2D */
3994 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
3995 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
3996 level
, xoffset
, yoffset
, 0,
3997 x
, y
, width
, height
, self
);
4000 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4001 xoffset
, yoffset
, zoffset
,
4002 x
, y
, width
, height
, self
);
4006 check_clear_tex_image(struct gl_context
*ctx
,
4007 const char *function
,
4008 struct gl_texture_image
*texImage
,
4009 GLenum format
, GLenum type
,
4011 GLubyte
*clearValue
)
4013 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4014 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4015 GLenum internalFormat
= texImage
->InternalFormat
;
4018 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4019 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4020 "%s(buffer texture)", function
);
4024 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4026 "%s(compressed texture)", function
);
4030 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4031 if (err
!= GL_NO_ERROR
) {
4032 _mesa_error(ctx
, err
,
4033 "%s(incompatible format = %s, type = %s)",
4035 _mesa_enum_to_string(format
),
4036 _mesa_enum_to_string(type
));
4040 /* make sure internal format and format basically agree */
4041 if (!texture_formats_agree(internalFormat
, format
)) {
4042 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4043 "%s(incompatible internalFormat = %s, format = %s)",
4045 _mesa_enum_to_string(internalFormat
),
4046 _mesa_enum_to_string(format
));
4050 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4051 /* both source and dest must be integer-valued, or neither */
4052 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4053 _mesa_is_enum_format_integer(format
)) {
4054 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4055 "%s(integer/non-integer format mismatch)",
4061 if (!_mesa_texstore(ctx
,
4063 texImage
->_BaseFormat
,
4064 texImage
->TexFormat
,
4065 0, /* dstRowStride */
4067 1, 1, 1, /* srcWidth/Height/Depth */
4069 data
? data
: zeroData
,
4070 &ctx
->DefaultPacking
)) {
4071 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4078 static struct gl_texture_object
*
4079 get_tex_obj_for_clear(struct gl_context
*ctx
,
4080 const char *function
,
4083 struct gl_texture_object
*texObj
;
4086 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4090 texObj
= _mesa_lookup_texture(ctx
, texture
);
4092 if (texObj
== NULL
) {
4093 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4097 if (texObj
->Target
== 0) {
4098 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4106 get_tex_images_for_clear(struct gl_context
*ctx
,
4107 const char *function
,
4108 struct gl_texture_object
*texObj
,
4110 struct gl_texture_image
**texImages
)
4115 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4116 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4120 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4121 for (i
= 0; i
< MAX_FACES
; i
++) {
4122 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4124 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4125 if (texImages
[i
] == NULL
) {
4126 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4127 "%s(invalid level)", function
);
4135 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4137 if (texImages
[0] == NULL
) {
4138 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4146 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4147 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4148 GLsizei width
, GLsizei height
, GLsizei depth
,
4149 GLenum format
, GLenum type
, const void *data
)
4151 GET_CURRENT_CONTEXT(ctx
);
4152 struct gl_texture_object
*texObj
;
4153 struct gl_texture_image
*texImages
[MAX_FACES
];
4154 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4156 int minDepth
, maxDepth
;
4158 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4163 _mesa_lock_texture(ctx
, texObj
);
4165 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4166 texObj
, level
, texImages
);
4170 if (numImages
== 1) {
4171 minDepth
= -(int) texImages
[0]->Border
;
4172 maxDepth
= texImages
[0]->Depth
;
4175 maxDepth
= numImages
;
4178 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4179 yoffset
< -(GLint
) texImages
[0]->Border
||
4180 zoffset
< minDepth
||
4184 xoffset
+ width
> texImages
[0]->Width
||
4185 yoffset
+ height
> texImages
[0]->Height
||
4186 zoffset
+ depth
> maxDepth
) {
4187 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4188 "glClearSubTexImage(invalid dimensions)");
4192 if (numImages
== 1) {
4193 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4195 format
, type
, data
, clearValue
[0])) {
4196 ctx
->Driver
.ClearTexSubImage(ctx
,
4198 xoffset
, yoffset
, zoffset
,
4199 width
, height
, depth
,
4200 data
? clearValue
[0] : NULL
);
4203 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4204 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4206 format
, type
, data
, clearValue
[i
]))
4209 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4210 ctx
->Driver
.ClearTexSubImage(ctx
,
4212 xoffset
, yoffset
, 0,
4214 data
? clearValue
[i
] : NULL
);
4219 _mesa_unlock_texture(ctx
, texObj
);
4223 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4224 GLenum format
, GLenum type
, const void *data
)
4226 GET_CURRENT_CONTEXT(ctx
);
4227 struct gl_texture_object
*texObj
;
4228 struct gl_texture_image
*texImages
[MAX_FACES
];
4229 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4232 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4237 _mesa_lock_texture(ctx
, texObj
);
4239 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4240 texObj
, level
, texImages
);
4242 for (i
= 0; i
< numImages
; i
++) {
4243 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4250 for (i
= 0; i
< numImages
; i
++) {
4251 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4252 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4253 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4254 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4255 texImages
[i
]->Width
,
4256 texImages
[i
]->Height
,
4257 texImages
[i
]->Depth
,
4258 data
? clearValue
[i
] : NULL
);
4262 _mesa_unlock_texture(ctx
, texObj
);
4268 /**********************************************************************/
4269 /****** Compressed Textures ******/
4270 /**********************************************************************/
4274 * Target checking for glCompressedTexSubImage[123]D().
4275 * \return GL_TRUE if error, GL_FALSE if no error
4276 * Must come before other error checking so that the texture object can
4277 * be correctly retrieved using _mesa_get_current_tex_object.
4280 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4281 GLint dims
, GLenum format
, bool dsa
,
4286 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4287 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4288 _mesa_enum_to_string(target
));
4298 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4299 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4300 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4301 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4302 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4303 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4304 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4307 targetOK
= GL_FALSE
;
4313 case GL_TEXTURE_CUBE_MAP
:
4314 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4316 case GL_TEXTURE_2D_ARRAY
:
4317 targetOK
= _mesa_is_gles3(ctx
) ||
4318 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4320 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4321 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4326 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4328 * "An INVALID_OPERATION error is generated by
4329 * CompressedTex*SubImage3D if the internal format of the texture
4330 * is one of the EAC, ETC2, or RGTC formats and either border is
4331 * non-zero, or the effective target for the texture is not
4332 * TEXTURE_2D_ARRAY."
4334 * NOTE: that's probably a spec error. It should probably say
4335 * "... or the effective target for the texture is not
4336 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4337 * GL_TEXTURE_CUBE_MAP_ARRAY."
4338 * since those targets are 2D images and they support all compression
4341 * Instead of listing all these, just list those which are allowed,
4342 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4343 * more) are valid here, which they are not, but of course not
4344 * mentioned by core spec.
4347 /* These are the only 3D compression formats supported at this time */
4348 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4349 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4350 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4351 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4355 /* invalid format */
4356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4357 "%s(invalid target %s for format %s)", caller
,
4358 _mesa_enum_to_string(target
),
4359 _mesa_enum_to_string(format
));
4364 targetOK
= GL_FALSE
;
4370 /* no 1D compressed textures at this time */
4371 targetOK
= GL_FALSE
;
4376 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4377 _mesa_enum_to_string(target
));
4385 * Error checking for glCompressedTexSubImage[123]D().
4386 * \return GL_TRUE if error, GL_FALSE if no error
4389 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4390 const struct gl_texture_object
*texObj
,
4391 GLenum target
, GLint level
,
4392 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4393 GLsizei width
, GLsizei height
, GLsizei depth
,
4394 GLenum format
, GLsizei imageSize
,
4395 const GLvoid
*data
, const char *callerName
)
4397 struct gl_texture_image
*texImage
;
4400 /* this will catch any invalid compressed format token */
4401 if (!_mesa_is_compressed_format(ctx
, format
)) {
4402 _mesa_error(ctx
, GL_INVALID_ENUM
,
4403 "%s(format)", callerName
);
4407 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4408 _mesa_error(ctx
, GL_INVALID_VALUE
,
4414 /* validate the bound PBO, if any */
4415 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4416 imageSize
, data
, callerName
)) {
4420 /* Check for invalid pixel storage modes */
4421 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4422 &ctx
->Unpack
, callerName
)) {
4426 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4427 if (expectedSize
!= imageSize
) {
4428 _mesa_error(ctx
, GL_INVALID_VALUE
,
4430 callerName
, imageSize
);
4434 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4437 "%s(invalid texture image)",
4442 if ((GLint
) format
!= texImage
->InternalFormat
) {
4443 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4445 callerName
, _mesa_enum_to_string(format
));
4449 if (compressedteximage_only_format(ctx
, format
)) {
4450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4451 "%s(format=%s cannot be updated)",
4452 callerName
, _mesa_enum_to_string(format
));
4456 if (error_check_subtexture_negative_dimensions(ctx
, dims
,
4457 width
, height
, depth
,
4462 if (error_check_subtexture_dimensions(ctx
, dims
,
4463 texImage
, xoffset
, yoffset
, zoffset
,
4464 width
, height
, depth
,
4474 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4475 GLenum internalFormat
, GLsizei width
,
4476 GLint border
, GLsizei imageSize
,
4479 GET_CURRENT_CONTEXT(ctx
);
4480 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4481 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4486 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4487 GLenum internalFormat
, GLsizei width
,
4488 GLsizei height
, GLint border
, GLsizei imageSize
,
4491 GET_CURRENT_CONTEXT(ctx
);
4492 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4493 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4498 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4499 GLenum internalFormat
, GLsizei width
,
4500 GLsizei height
, GLsizei depth
, GLint border
,
4501 GLsizei imageSize
, const GLvoid
*data
)
4503 GET_CURRENT_CONTEXT(ctx
);
4504 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4505 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4510 * Common helper for glCompressedTexSubImage1/2/3D() and
4511 * glCompressedTextureSubImage1/2/3D().
4514 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4515 struct gl_texture_object
*texObj
,
4516 struct gl_texture_image
*texImage
,
4517 GLenum target
, GLint level
,
4518 GLint xoffset
, GLint yoffset
,
4520 GLsizei width
, GLsizei height
,
4522 GLenum format
, GLsizei imageSize
,
4525 FLUSH_VERTICES(ctx
, 0);
4527 _mesa_lock_texture(ctx
, texObj
);
4529 if (width
> 0 && height
> 0 && depth
> 0) {
4530 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4531 xoffset
, yoffset
, zoffset
,
4532 width
, height
, depth
,
4533 format
, imageSize
, data
);
4535 check_gen_mipmap(ctx
, target
, texObj
, level
);
4537 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4538 * the texel data, not the texture format, size, etc.
4542 _mesa_unlock_texture(ctx
, texObj
);
4547 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4548 GLsizei width
, GLenum format
,
4549 GLsizei imageSize
, const GLvoid
*data
)
4551 struct gl_texture_object
*texObj
;
4552 struct gl_texture_image
*texImage
;
4554 GET_CURRENT_CONTEXT(ctx
);
4556 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4557 "glCompressedTexSubImage1D")) {
4561 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4565 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4566 level
, xoffset
, 0, 0,
4568 format
, imageSize
, data
,
4569 "glCompressedTexSubImage1D")) {
4573 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4576 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4577 xoffset
, 0, 0, width
, 1, 1,
4578 format
, imageSize
, data
);
4582 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4583 GLsizei width
, GLenum format
,
4584 GLsizei imageSize
, const GLvoid
*data
)
4586 struct gl_texture_object
*texObj
;
4587 struct gl_texture_image
*texImage
;
4589 GET_CURRENT_CONTEXT(ctx
);
4591 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4592 "glCompressedTextureSubImage1D");
4596 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4597 "glCompressedTextureSubImage1D")) {
4601 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4602 level
, xoffset
, 0, 0,
4604 format
, imageSize
, data
,
4605 "glCompressedTextureSubImage1D")) {
4609 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4612 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4613 texObj
->Target
, level
,
4614 xoffset
, 0, 0, width
, 1, 1,
4615 format
, imageSize
, data
);
4620 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4621 GLint yoffset
, GLsizei width
, GLsizei height
,
4622 GLenum format
, GLsizei imageSize
,
4625 struct gl_texture_object
*texObj
;
4626 struct gl_texture_image
*texImage
;
4628 GET_CURRENT_CONTEXT(ctx
);
4630 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4631 "glCompressedTexSubImage2D")) {
4635 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4639 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4640 level
, xoffset
, yoffset
, 0,
4642 format
, imageSize
, data
,
4643 "glCompressedTexSubImage2D")) {
4648 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4651 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4652 xoffset
, yoffset
, 0, width
, height
, 1,
4653 format
, imageSize
, data
);
4657 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4659 GLsizei width
, GLsizei height
,
4660 GLenum format
, GLsizei imageSize
,
4663 struct gl_texture_object
*texObj
;
4664 struct gl_texture_image
*texImage
;
4666 GET_CURRENT_CONTEXT(ctx
);
4668 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4669 "glCompressedTextureSubImage2D");
4673 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
4674 "glCompressedTextureSubImage2D")) {
4678 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4679 level
, xoffset
, yoffset
, 0,
4681 format
, imageSize
, data
,
4682 "glCompressedTextureSubImage2D")) {
4686 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4689 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4690 texObj
->Target
, level
,
4691 xoffset
, yoffset
, 0, width
, height
, 1,
4692 format
, imageSize
, data
);
4696 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4697 GLint yoffset
, GLint zoffset
, GLsizei width
,
4698 GLsizei height
, GLsizei depth
, GLenum format
,
4699 GLsizei imageSize
, const GLvoid
*data
)
4701 struct gl_texture_object
*texObj
;
4702 struct gl_texture_image
*texImage
;
4704 GET_CURRENT_CONTEXT(ctx
);
4706 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4707 "glCompressedTexSubImage3D")) {
4711 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4715 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4716 level
, xoffset
, yoffset
, zoffset
,
4717 width
, height
, depth
,
4718 format
, imageSize
, data
,
4719 "glCompressedTexSubImage3D")) {
4724 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4727 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4728 xoffset
, yoffset
, zoffset
,
4729 width
, height
, depth
,
4730 format
, imageSize
, data
);
4734 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4735 GLint yoffset
, GLint zoffset
, GLsizei width
,
4736 GLsizei height
, GLsizei depth
,
4737 GLenum format
, GLsizei imageSize
,
4740 struct gl_texture_object
*texObj
;
4741 struct gl_texture_image
*texImage
;
4743 GET_CURRENT_CONTEXT(ctx
);
4745 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4746 "glCompressedTextureSubImage3D");
4750 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
4751 "glCompressedTextureSubImage3D")) {
4755 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4756 level
, xoffset
, yoffset
, zoffset
,
4757 width
, height
, depth
,
4758 format
, imageSize
, data
,
4759 "glCompressedTextureSubImage3D")) {
4763 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4764 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4765 const char *pixels
= data
;
4769 /* Make sure the texture object is a proper cube.
4770 * (See texturesubimage in teximage.c for details on why this check is
4773 if (!_mesa_cube_level_complete(texObj
, level
)) {
4774 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4775 "glCompressedTextureSubImage3D(cube map incomplete)");
4779 /* Copy in each face. */
4780 for (i
= 0; i
< 6; ++i
) {
4781 texImage
= texObj
->Image
[i
][level
];
4784 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
4785 texObj
->Target
, level
,
4786 xoffset
, yoffset
, zoffset
,
4788 format
, imageSize
, pixels
);
4790 /* Compressed images don't have a client format */
4791 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
4793 texImage
->Height
, 1);
4795 pixels
+= image_stride
;
4796 imageSize
-= image_stride
;
4800 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4803 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
4804 texObj
->Target
, level
,
4805 xoffset
, yoffset
, zoffset
,
4806 width
, height
, depth
,
4807 format
, imageSize
, data
);
4812 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4814 if (ctx
->API
== API_OPENGL_COMPAT
) {
4815 switch (internalFormat
) {
4817 return MESA_FORMAT_A_UNORM8
;
4819 return MESA_FORMAT_A_UNORM16
;
4820 case GL_ALPHA16F_ARB
:
4821 return MESA_FORMAT_A_FLOAT16
;
4822 case GL_ALPHA32F_ARB
:
4823 return MESA_FORMAT_A_FLOAT32
;
4824 case GL_ALPHA8I_EXT
:
4825 return MESA_FORMAT_A_SINT8
;
4826 case GL_ALPHA16I_EXT
:
4827 return MESA_FORMAT_A_SINT16
;
4828 case GL_ALPHA32I_EXT
:
4829 return MESA_FORMAT_A_SINT32
;
4830 case GL_ALPHA8UI_EXT
:
4831 return MESA_FORMAT_A_UINT8
;
4832 case GL_ALPHA16UI_EXT
:
4833 return MESA_FORMAT_A_UINT16
;
4834 case GL_ALPHA32UI_EXT
:
4835 return MESA_FORMAT_A_UINT32
;
4837 return MESA_FORMAT_L_UNORM8
;
4838 case GL_LUMINANCE16
:
4839 return MESA_FORMAT_L_UNORM16
;
4840 case GL_LUMINANCE16F_ARB
:
4841 return MESA_FORMAT_L_FLOAT16
;
4842 case GL_LUMINANCE32F_ARB
:
4843 return MESA_FORMAT_L_FLOAT32
;
4844 case GL_LUMINANCE8I_EXT
:
4845 return MESA_FORMAT_L_SINT8
;
4846 case GL_LUMINANCE16I_EXT
:
4847 return MESA_FORMAT_L_SINT16
;
4848 case GL_LUMINANCE32I_EXT
:
4849 return MESA_FORMAT_L_SINT32
;
4850 case GL_LUMINANCE8UI_EXT
:
4851 return MESA_FORMAT_L_UINT8
;
4852 case GL_LUMINANCE16UI_EXT
:
4853 return MESA_FORMAT_L_UINT16
;
4854 case GL_LUMINANCE32UI_EXT
:
4855 return MESA_FORMAT_L_UINT32
;
4856 case GL_LUMINANCE8_ALPHA8
:
4857 return MESA_FORMAT_L8A8_UNORM
;
4858 case GL_LUMINANCE16_ALPHA16
:
4859 return MESA_FORMAT_L16A16_UNORM
;
4860 case GL_LUMINANCE_ALPHA16F_ARB
:
4861 return MESA_FORMAT_LA_FLOAT16
;
4862 case GL_LUMINANCE_ALPHA32F_ARB
:
4863 return MESA_FORMAT_LA_FLOAT32
;
4864 case GL_LUMINANCE_ALPHA8I_EXT
:
4865 return MESA_FORMAT_LA_SINT8
;
4866 case GL_LUMINANCE_ALPHA16I_EXT
:
4867 return MESA_FORMAT_LA_SINT16
;
4868 case GL_LUMINANCE_ALPHA32I_EXT
:
4869 return MESA_FORMAT_LA_SINT32
;
4870 case GL_LUMINANCE_ALPHA8UI_EXT
:
4871 return MESA_FORMAT_LA_UINT8
;
4872 case GL_LUMINANCE_ALPHA16UI_EXT
:
4873 return MESA_FORMAT_LA_UINT16
;
4874 case GL_LUMINANCE_ALPHA32UI_EXT
:
4875 return MESA_FORMAT_LA_UINT32
;
4877 return MESA_FORMAT_I_UNORM8
;
4878 case GL_INTENSITY16
:
4879 return MESA_FORMAT_I_UNORM16
;
4880 case GL_INTENSITY16F_ARB
:
4881 return MESA_FORMAT_I_FLOAT16
;
4882 case GL_INTENSITY32F_ARB
:
4883 return MESA_FORMAT_I_FLOAT32
;
4884 case GL_INTENSITY8I_EXT
:
4885 return MESA_FORMAT_I_SINT8
;
4886 case GL_INTENSITY16I_EXT
:
4887 return MESA_FORMAT_I_SINT16
;
4888 case GL_INTENSITY32I_EXT
:
4889 return MESA_FORMAT_I_SINT32
;
4890 case GL_INTENSITY8UI_EXT
:
4891 return MESA_FORMAT_I_UINT8
;
4892 case GL_INTENSITY16UI_EXT
:
4893 return MESA_FORMAT_I_UINT16
;
4894 case GL_INTENSITY32UI_EXT
:
4895 return MESA_FORMAT_I_UINT32
;
4901 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
4902 _mesa_has_OES_texture_buffer(ctx
)) {
4903 switch (internalFormat
) {
4905 return MESA_FORMAT_RGB_FLOAT32
;
4907 return MESA_FORMAT_RGB_UINT32
;
4909 return MESA_FORMAT_RGB_SINT32
;
4915 switch (internalFormat
) {
4917 return MESA_FORMAT_R8G8B8A8_UNORM
;
4919 if (_mesa_is_gles(ctx
))
4920 return MESA_FORMAT_NONE
;
4921 return MESA_FORMAT_RGBA_UNORM16
;
4922 case GL_RGBA16F_ARB
:
4923 return MESA_FORMAT_RGBA_FLOAT16
;
4924 case GL_RGBA32F_ARB
:
4925 return MESA_FORMAT_RGBA_FLOAT32
;
4927 return MESA_FORMAT_RGBA_SINT8
;
4928 case GL_RGBA16I_EXT
:
4929 return MESA_FORMAT_RGBA_SINT16
;
4930 case GL_RGBA32I_EXT
:
4931 return MESA_FORMAT_RGBA_SINT32
;
4932 case GL_RGBA8UI_EXT
:
4933 return MESA_FORMAT_RGBA_UINT8
;
4934 case GL_RGBA16UI_EXT
:
4935 return MESA_FORMAT_RGBA_UINT16
;
4936 case GL_RGBA32UI_EXT
:
4937 return MESA_FORMAT_RGBA_UINT32
;
4940 return MESA_FORMAT_R8G8_UNORM
;
4942 if (_mesa_is_gles(ctx
))
4943 return MESA_FORMAT_NONE
;
4944 return MESA_FORMAT_R16G16_UNORM
;
4946 return MESA_FORMAT_RG_FLOAT16
;
4948 return MESA_FORMAT_RG_FLOAT32
;
4950 return MESA_FORMAT_RG_SINT8
;
4952 return MESA_FORMAT_RG_SINT16
;
4954 return MESA_FORMAT_RG_SINT32
;
4956 return MESA_FORMAT_RG_UINT8
;
4958 return MESA_FORMAT_RG_UINT16
;
4960 return MESA_FORMAT_RG_UINT32
;
4963 return MESA_FORMAT_R_UNORM8
;
4965 if (_mesa_is_gles(ctx
))
4966 return MESA_FORMAT_NONE
;
4967 return MESA_FORMAT_R_UNORM16
;
4969 return MESA_FORMAT_R_FLOAT16
;
4971 return MESA_FORMAT_R_FLOAT32
;
4973 return MESA_FORMAT_R_SINT8
;
4975 return MESA_FORMAT_R_SINT16
;
4977 return MESA_FORMAT_R_SINT32
;
4979 return MESA_FORMAT_R_UINT8
;
4981 return MESA_FORMAT_R_UINT16
;
4983 return MESA_FORMAT_R_UINT32
;
4986 return MESA_FORMAT_NONE
;
4992 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4993 GLenum internalFormat
)
4995 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4998 if (format
== MESA_FORMAT_NONE
)
4999 return MESA_FORMAT_NONE
;
5001 datatype
= _mesa_get_format_datatype(format
);
5003 /* The GL_ARB_texture_buffer_object spec says:
5005 * "If ARB_texture_float is not supported, references to the
5006 * floating-point internal formats provided by that extension should be
5007 * removed, and such formats may not be passed to TexBufferARB."
5009 * As a result, GL_HALF_FLOAT internal format depends on both
5010 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5012 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5013 !ctx
->Extensions
.ARB_texture_float
)
5014 return MESA_FORMAT_NONE
;
5016 if (!ctx
->Extensions
.ARB_texture_rg
) {
5017 GLenum base_format
= _mesa_get_format_base_format(format
);
5018 if (base_format
== GL_R
|| base_format
== GL_RG
)
5019 return MESA_FORMAT_NONE
;
5022 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5023 GLenum base_format
= _mesa_get_format_base_format(format
);
5024 if (base_format
== GL_RGB
)
5025 return MESA_FORMAT_NONE
;
5032 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5033 struct gl_texture_object
*texObj
,
5034 GLenum internalFormat
,
5035 struct gl_buffer_object
*bufObj
,
5036 GLintptr offset
, GLsizeiptr size
,
5041 /* NOTE: ARB_texture_buffer_object has interactions with
5042 * the compatibility profile that are not implemented.
5044 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5045 !_mesa_has_OES_texture_buffer(ctx
)) {
5046 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5047 "%s(ARB_texture_buffer_object is not"
5048 " implemented for the compatibility profile)", caller
);
5052 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5053 if (format
== MESA_FORMAT_NONE
) {
5054 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5055 caller
, _mesa_enum_to_string(internalFormat
));
5059 FLUSH_VERTICES(ctx
, 0);
5061 _mesa_lock_texture(ctx
, texObj
);
5063 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5064 texObj
->BufferObjectFormat
= internalFormat
;
5065 texObj
->_BufferObjectFormat
= format
;
5066 texObj
->BufferOffset
= offset
;
5067 texObj
->BufferSize
= size
;
5069 _mesa_unlock_texture(ctx
, texObj
);
5071 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5074 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5080 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5081 * Return true if it is, and return false if it is not
5082 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5083 * core spec, 02.02.2015, PDF page 245).
5086 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5089 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5090 _mesa_error(ctx
, GL_INVALID_ENUM
,
5091 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5099 * Check for errors related to the texture buffer range.
5100 * Return false if errors are found, true if none are found.
5103 check_texture_buffer_range(struct gl_context
*ctx
,
5104 struct gl_buffer_object
*bufObj
,
5105 GLintptr offset
, GLsizeiptr size
,
5108 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5109 * Textures (PDF page 245):
5110 * "An INVALID_VALUE error is generated if offset is negative, if
5111 * size is less than or equal to zero, or if offset + size is greater
5112 * than the value of BUFFER_SIZE for the buffer bound to target."
5115 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5121 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5126 if (offset
+ size
> bufObj
->Size
) {
5127 _mesa_error(ctx
, GL_INVALID_VALUE
,
5128 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5129 (int) offset
, (int) size
, (int) bufObj
->Size
);
5133 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5134 * Textures (PDF page 245):
5135 * "An INVALID_VALUE error is generated if offset is not an integer
5136 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5138 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5139 _mesa_error(ctx
, GL_INVALID_VALUE
,
5140 "%s(invalid offset alignment)", caller
);
5148 /** GL_ARB_texture_buffer_object */
5150 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5152 struct gl_texture_object
*texObj
;
5153 struct gl_buffer_object
*bufObj
;
5155 GET_CURRENT_CONTEXT(ctx
);
5157 /* Need to catch a bad target before it gets to
5158 * _mesa_get_current_tex_object.
5160 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5164 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5170 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5174 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5175 buffer
? -1 : 0, "glTexBuffer");
5179 /** GL_ARB_texture_buffer_range */
5181 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5182 GLintptr offset
, GLsizeiptr size
)
5184 struct gl_texture_object
*texObj
;
5185 struct gl_buffer_object
*bufObj
;
5187 GET_CURRENT_CONTEXT(ctx
);
5189 /* Need to catch a bad target before it gets to
5190 * _mesa_get_current_tex_object.
5192 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5196 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5200 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5201 "glTexBufferRange"))
5205 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5206 * Textures (PDF page 254):
5207 * "If buffer is zero, then any buffer object attached to the buffer
5208 * texture is detached, the values offset and size are ignored and
5209 * the state for offset and size for the buffer texture are reset to
5217 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5221 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5222 offset
, size
, "glTexBufferRange");
5226 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5228 struct gl_texture_object
*texObj
;
5229 struct gl_buffer_object
*bufObj
;
5231 GET_CURRENT_CONTEXT(ctx
);
5234 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5240 /* Get the texture object by Name. */
5241 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5245 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5248 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5249 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5253 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5254 GLintptr offset
, GLsizeiptr size
)
5256 struct gl_texture_object
*texObj
;
5257 struct gl_buffer_object
*bufObj
;
5259 GET_CURRENT_CONTEXT(ctx
);
5262 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5263 "glTextureBufferRange");
5267 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5268 "glTextureBufferRange"))
5272 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5273 * Textures (PDF page 254):
5274 * "If buffer is zero, then any buffer object attached to the buffer
5275 * texture is detached, the values offset and size are ignored and
5276 * the state for offset and size for the buffer texture are reset to
5284 /* Get the texture object by Name. */
5285 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5289 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5290 "glTextureBufferRange"))
5293 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5294 bufObj
, offset
, size
, "glTextureBufferRange");
5298 _mesa_is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5300 /* Everything that is allowed for renderbuffers,
5301 * except for a base format of GL_STENCIL_INDEX, unless supported.
5303 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5304 if (ctx
->Extensions
.ARB_texture_stencil8
)
5305 return baseFormat
!= 0;
5307 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5311 /** GL_ARB_texture_multisample */
5313 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5316 case GL_TEXTURE_2D_MULTISAMPLE
:
5318 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5319 return dims
== 2 && !dsa
;
5320 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5322 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5323 return dims
== 3 && !dsa
;
5331 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5332 struct gl_texture_object
*texObj
,
5333 GLenum target
, GLsizei samples
,
5334 GLint internalformat
, GLsizei width
,
5335 GLsizei height
, GLsizei depth
,
5336 GLboolean fixedsamplelocations
,
5337 GLboolean immutable
, const char *func
)
5339 struct gl_texture_image
*texImage
;
5340 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5341 mesa_format texFormat
;
5342 GLenum sample_count_error
;
5343 bool dsa
= strstr(func
, "ture") ? true : false;
5345 if (!((ctx
->Extensions
.ARB_texture_multisample
5346 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5352 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5356 if (!check_multisample_target(dims
, target
, dsa
)) {
5358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5362 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5367 /* check that the specified internalformat is color/depth/stencil-renderable;
5368 * refer GL3.1 spec 4.4.4
5371 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5372 _mesa_error(ctx
, GL_INVALID_ENUM
,
5373 "%s(internalformat=%s not legal for immutable-format)",
5374 func
, _mesa_enum_to_string(internalformat
));
5378 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5379 /* Page 172 of OpenGL ES 3.1 spec says:
5380 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5381 * color-renderable, depth-renderable, or stencil-renderable (as
5382 * defined in section 9.4).
5384 * (Same error is also defined for desktop OpenGL for multisample
5385 * teximage/texstorage functions.)
5387 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5388 _mesa_enum_to_string(internalformat
));
5392 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5393 internalformat
, samples
);
5394 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5396 /* Page 254 of OpenGL 4.4 spec says:
5397 * "Proxy arrays for two-dimensional multisample and two-dimensional
5398 * multisample array textures are operated on in the same way when
5399 * TexImage2DMultisample is called with target specified as
5400 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5401 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5402 * However, if samples is not supported, then no error is generated.
5404 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5405 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5409 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5411 "%s(texture object 0)",
5416 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5418 if (texImage
== NULL
) {
5419 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5423 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5424 internalformat
, GL_NONE
, GL_NONE
);
5425 assert(texFormat
!= MESA_FORMAT_NONE
);
5427 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5428 width
, height
, depth
, 0);
5430 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5431 samples
, width
, height
, depth
);
5433 if (_mesa_is_proxy_texture(target
)) {
5434 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5435 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5436 internalformat
, texFormat
,
5437 samples
, fixedsamplelocations
);
5440 /* clear all image fields */
5441 clear_teximage_fields(texImage
);
5445 if (!dimensionsOK
) {
5446 _mesa_error(ctx
, GL_INVALID_VALUE
,
5447 "%s(invalid width or height)", func
);
5452 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5456 /* Check if texObj->Immutable is set */
5457 if (texObj
->Immutable
) {
5458 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5462 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5464 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5465 internalformat
, texFormat
,
5466 samples
, fixedsamplelocations
);
5468 if (width
> 0 && height
> 0 && depth
> 0) {
5469 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5470 width
, height
, depth
)) {
5471 /* tidy up the texture image state. strictly speaking,
5472 * we're allowed to just leave this in whatever state we
5473 * like, but being tidy is good.
5475 _mesa_init_teximage_fields(ctx
, texImage
,
5476 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5480 texObj
->Immutable
|= immutable
;
5483 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5486 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5492 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5493 GLenum internalformat
, GLsizei width
,
5494 GLsizei height
, GLboolean fixedsamplelocations
)
5496 struct gl_texture_object
*texObj
;
5497 GET_CURRENT_CONTEXT(ctx
);
5499 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5503 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5504 internalformat
, width
, height
, 1,
5505 fixedsamplelocations
, GL_FALSE
,
5506 "glTexImage2DMultisample");
5511 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5512 GLenum internalformat
, GLsizei width
,
5513 GLsizei height
, GLsizei depth
,
5514 GLboolean fixedsamplelocations
)
5516 struct gl_texture_object
*texObj
;
5517 GET_CURRENT_CONTEXT(ctx
);
5519 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5523 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5524 internalformat
, width
, height
, depth
,
5525 fixedsamplelocations
, GL_FALSE
,
5526 "glTexImage3DMultisample");
5530 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5531 GLsizei samples
, unsigned dims
)
5533 GET_CURRENT_CONTEXT(ctx
);
5535 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5536 _mesa_error(ctx
, GL_INVALID_VALUE
,
5537 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5538 dims
, width
, height
, depth
);
5545 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5546 GLenum internalformat
, GLsizei width
,
5547 GLsizei height
, GLboolean fixedsamplelocations
)
5549 struct gl_texture_object
*texObj
;
5550 GET_CURRENT_CONTEXT(ctx
);
5552 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5556 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5559 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5560 internalformat
, width
, height
, 1,
5561 fixedsamplelocations
, GL_TRUE
,
5562 "glTexStorage2DMultisample");
5566 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5567 GLenum internalformat
, GLsizei width
,
5568 GLsizei height
, GLsizei depth
,
5569 GLboolean fixedsamplelocations
)
5571 struct gl_texture_object
*texObj
;
5572 GET_CURRENT_CONTEXT(ctx
);
5574 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5578 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5581 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5582 internalformat
, width
, height
, depth
,
5583 fixedsamplelocations
, GL_TRUE
,
5584 "glTexStorage3DMultisample");
5588 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5589 GLenum internalformat
, GLsizei width
,
5591 GLboolean fixedsamplelocations
)
5593 struct gl_texture_object
*texObj
;
5594 GET_CURRENT_CONTEXT(ctx
);
5596 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5597 "glTextureStorage2DMultisample");
5601 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5604 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5605 internalformat
, width
, height
, 1,
5606 fixedsamplelocations
, GL_TRUE
,
5607 "glTextureStorage2DMultisample");
5611 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5612 GLenum internalformat
, GLsizei width
,
5613 GLsizei height
, GLsizei depth
,
5614 GLboolean fixedsamplelocations
)
5616 struct gl_texture_object
*texObj
;
5617 GET_CURRENT_CONTEXT(ctx
);
5619 /* Get the texture object by Name. */
5620 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5621 "glTextureStorage3DMultisample");
5625 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5628 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5629 internalformat
, width
, height
, depth
,
5630 fixedsamplelocations
, GL_TRUE
,
5631 "glTextureStorage3DMultisample");