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
;
126 * Returns a corresponding base format for a given internal floating point
127 * format as specifed by OES_texture_float.
130 oes_float_internal_format(const struct gl_context
*ctx
,
131 GLenum format
, GLenum type
)
135 if (ctx
->Extensions
.OES_texture_float
) {
141 case GL_ALPHA32F_ARB
:
143 case GL_LUMINANCE32F_ARB
:
145 case GL_LUMINANCE_ALPHA32F_ARB
:
146 return GL_LUMINANCE_ALPHA
;
153 case GL_HALF_FLOAT_OES
:
154 if (ctx
->Extensions
.OES_texture_half_float
) {
160 case GL_ALPHA16F_ARB
:
162 case GL_LUMINANCE16F_ARB
:
164 case GL_LUMINANCE_ALPHA16F_ARB
:
165 return GL_LUMINANCE_ALPHA
;
177 * Install gl_texture_image in a gl_texture_object according to the target
178 * and level parameters.
180 * \param tObj texture object.
181 * \param target texture target.
182 * \param level image level.
183 * \param texImage texture image.
186 set_tex_image(struct gl_texture_object
*tObj
,
187 GLenum target
, GLint level
,
188 struct gl_texture_image
*texImage
)
190 const GLuint face
= _mesa_tex_target_to_face(target
);
194 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
197 tObj
->Image
[face
][level
] = texImage
;
199 /* Set the 'back' pointer */
200 texImage
->TexObject
= tObj
;
201 texImage
->Level
= level
;
202 texImage
->Face
= face
;
207 * Free a gl_texture_image and associated data.
208 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
210 * \param texImage texture image.
212 * Free the texture image structure and the associated image data.
215 _mesa_delete_texture_image(struct gl_context
*ctx
,
216 struct gl_texture_image
*texImage
)
218 /* Free texImage->Data and/or any other driver-specific texture
221 assert(ctx
->Driver
.FreeTextureImageBuffer
);
222 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
228 * Test if a target is a proxy target.
230 * \param target texture target.
232 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
235 _mesa_is_proxy_texture(GLenum target
)
238 static const GLenum targets
[] = {
242 GL_PROXY_TEXTURE_CUBE_MAP
,
243 GL_PROXY_TEXTURE_RECTANGLE
,
244 GL_PROXY_TEXTURE_1D_ARRAY
,
245 GL_PROXY_TEXTURE_2D_ARRAY
,
246 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
247 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
248 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
251 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
252 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
254 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
256 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
257 if (target
== targets
[i
])
264 * Test if a target is an array target.
266 * \param target texture target.
268 * \return true if the target is an array target, false otherwise.
271 _mesa_is_array_texture(GLenum target
)
274 case GL_TEXTURE_1D_ARRAY
:
275 case GL_TEXTURE_2D_ARRAY
:
276 case GL_TEXTURE_CUBE_MAP_ARRAY
:
277 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
285 * Test if a target is a cube map.
287 * \param target texture target.
289 * \return true if the target is a cube map, false otherwise.
292 _mesa_is_cube_map_texture(GLenum target
)
295 case GL_TEXTURE_CUBE_MAP
:
296 case GL_TEXTURE_CUBE_MAP_ARRAY
:
304 * Return the proxy target which corresponds to the given texture target
307 proxy_target(GLenum target
)
311 case GL_PROXY_TEXTURE_1D
:
312 return GL_PROXY_TEXTURE_1D
;
314 case GL_PROXY_TEXTURE_2D
:
315 return GL_PROXY_TEXTURE_2D
;
317 case GL_PROXY_TEXTURE_3D
:
318 return GL_PROXY_TEXTURE_3D
;
319 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
320 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
321 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
322 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
323 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
324 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
325 case GL_TEXTURE_CUBE_MAP
:
326 case GL_PROXY_TEXTURE_CUBE_MAP
:
327 return GL_PROXY_TEXTURE_CUBE_MAP
;
328 case GL_TEXTURE_RECTANGLE_NV
:
329 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
330 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
331 case GL_TEXTURE_1D_ARRAY_EXT
:
332 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
333 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
334 case GL_TEXTURE_2D_ARRAY_EXT
:
335 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
336 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
337 case GL_TEXTURE_CUBE_MAP_ARRAY
:
338 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
339 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
340 case GL_TEXTURE_2D_MULTISAMPLE
:
341 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
342 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
344 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
345 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
347 _mesa_problem(NULL
, "unexpected target in proxy_target()");
356 * Get a texture image pointer from a texture object, given a texture
357 * target and mipmap level. The target and level parameters should
358 * have already been error-checked.
360 * \param texObj texture unit.
361 * \param target texture target.
362 * \param level image level.
364 * \return pointer to the texture image structure, or NULL on failure.
366 struct gl_texture_image
*
367 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
368 GLenum target
, GLint level
)
370 const GLuint face
= _mesa_tex_target_to_face(target
);
374 assert(level
< MAX_TEXTURE_LEVELS
);
376 return texObj
->Image
[face
][level
];
381 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
382 * it and install it. Only return NULL if passed a bad parameter or run
385 struct gl_texture_image
*
386 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
387 GLenum target
, GLint level
)
389 struct gl_texture_image
*texImage
;
394 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
396 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
398 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
402 set_tex_image(texObj
, target
, level
, texImage
);
410 * Return pointer to the specified proxy texture image.
411 * Note that proxy textures are per-context, not per-texture unit.
412 * \return pointer to texture image or NULL if invalid target, invalid
413 * level, or out of memory.
415 static struct gl_texture_image
*
416 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
418 struct gl_texture_image
*texImage
;
425 case GL_PROXY_TEXTURE_1D
:
426 texIndex
= TEXTURE_1D_INDEX
;
428 case GL_PROXY_TEXTURE_2D
:
429 texIndex
= TEXTURE_2D_INDEX
;
431 case GL_PROXY_TEXTURE_3D
:
432 texIndex
= TEXTURE_3D_INDEX
;
434 case GL_PROXY_TEXTURE_CUBE_MAP
:
435 texIndex
= TEXTURE_CUBE_INDEX
;
437 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
440 texIndex
= TEXTURE_RECT_INDEX
;
442 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
443 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
445 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
446 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
448 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
449 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
451 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
452 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
454 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
455 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
461 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
463 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
465 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
468 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
469 /* Set the 'back' pointer */
470 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
477 * Get the maximum number of allowed mipmap levels.
479 * \param ctx GL context.
480 * \param target texture target.
482 * \return the maximum number of allowed mipmap levels for the given
483 * texture target, or zero if passed a bad target.
488 _mesa_max_texture_levels(const struct gl_context
*ctx
, GLenum target
)
492 case GL_PROXY_TEXTURE_1D
:
494 case GL_PROXY_TEXTURE_2D
:
495 return ffs(util_next_power_of_two(ctx
->Const
.MaxTextureSize
));
497 case GL_PROXY_TEXTURE_3D
:
498 return ctx
->Const
.Max3DTextureLevels
;
499 case GL_TEXTURE_CUBE_MAP
:
500 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
501 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
502 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
503 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
504 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
505 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
506 case GL_PROXY_TEXTURE_CUBE_MAP
:
507 return ctx
->Extensions
.ARB_texture_cube_map
508 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
509 case GL_TEXTURE_RECTANGLE_NV
:
510 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
511 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
512 case GL_TEXTURE_1D_ARRAY_EXT
:
513 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
514 case GL_TEXTURE_2D_ARRAY_EXT
:
515 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
516 return ctx
->Extensions
.EXT_texture_array
517 ? ffs(util_next_power_of_two(ctx
->Const
.MaxTextureSize
)) : 0;
518 case GL_TEXTURE_CUBE_MAP_ARRAY
:
519 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
520 return _mesa_has_texture_cube_map_array(ctx
)
521 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
522 case GL_TEXTURE_BUFFER
:
523 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
524 _mesa_has_OES_texture_buffer(ctx
)) ? 1 : 0;
525 case GL_TEXTURE_2D_MULTISAMPLE
:
526 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
527 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
528 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
529 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
530 && ctx
->Extensions
.ARB_texture_multisample
532 case GL_TEXTURE_EXTERNAL_OES
:
533 return _mesa_has_OES_EGL_image_external(ctx
) ? 1 : 0;
535 return 0; /* bad target */
541 * Return number of dimensions per mipmap level for the given texture target.
544 _mesa_get_texture_dimensions(GLenum target
)
548 case GL_PROXY_TEXTURE_1D
:
551 case GL_TEXTURE_RECTANGLE
:
552 case GL_TEXTURE_CUBE_MAP
:
553 case GL_PROXY_TEXTURE_2D
:
554 case GL_PROXY_TEXTURE_RECTANGLE
:
555 case GL_PROXY_TEXTURE_CUBE_MAP
:
556 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
557 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
558 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
559 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
560 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
561 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
562 case GL_TEXTURE_1D_ARRAY
:
563 case GL_PROXY_TEXTURE_1D_ARRAY
:
564 case GL_TEXTURE_EXTERNAL_OES
:
565 case GL_TEXTURE_2D_MULTISAMPLE
:
566 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
569 case GL_PROXY_TEXTURE_3D
:
570 case GL_TEXTURE_2D_ARRAY
:
571 case GL_PROXY_TEXTURE_2D_ARRAY
:
572 case GL_TEXTURE_CUBE_MAP_ARRAY
:
573 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
574 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
575 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
577 case GL_TEXTURE_BUFFER
:
580 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
588 * Check if a texture target can have more than one layer.
591 _mesa_tex_target_is_layered(GLenum target
)
595 case GL_PROXY_TEXTURE_1D
:
597 case GL_PROXY_TEXTURE_2D
:
598 case GL_TEXTURE_RECTANGLE
:
599 case GL_PROXY_TEXTURE_RECTANGLE
:
600 case GL_TEXTURE_2D_MULTISAMPLE
:
601 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
602 case GL_TEXTURE_BUFFER
:
603 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
604 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
605 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
609 case GL_TEXTURE_EXTERNAL_OES
:
613 case GL_PROXY_TEXTURE_3D
:
614 case GL_TEXTURE_CUBE_MAP
:
615 case GL_PROXY_TEXTURE_CUBE_MAP
:
616 case GL_TEXTURE_1D_ARRAY
:
617 case GL_PROXY_TEXTURE_1D_ARRAY
:
618 case GL_TEXTURE_2D_ARRAY
:
619 case GL_PROXY_TEXTURE_2D_ARRAY
:
620 case GL_TEXTURE_CUBE_MAP_ARRAY
:
621 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
622 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
623 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
627 assert(!"Invalid texture target.");
634 * Return the number of layers present in the given level of an array,
635 * cubemap or 3D texture. If the texture is not layered return zero.
638 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
640 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
642 switch (texObj
->Target
) {
645 case GL_TEXTURE_RECTANGLE
:
646 case GL_TEXTURE_2D_MULTISAMPLE
:
647 case GL_TEXTURE_BUFFER
:
648 case GL_TEXTURE_EXTERNAL_OES
:
651 case GL_TEXTURE_CUBE_MAP
:
654 case GL_TEXTURE_1D_ARRAY
: {
655 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
656 return img
? img
->Height
: 0;
660 case GL_TEXTURE_2D_ARRAY
:
661 case GL_TEXTURE_CUBE_MAP_ARRAY
:
662 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
663 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
664 return img
? img
->Depth
: 0;
668 assert(!"Invalid texture target.");
675 * Return the maximum number of mipmap levels for the given target
676 * and the dimensions.
677 * The dimensions are expected not to include the border.
680 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
687 case GL_TEXTURE_1D_ARRAY
:
688 case GL_PROXY_TEXTURE_1D
:
689 case GL_PROXY_TEXTURE_1D_ARRAY
:
692 case GL_TEXTURE_CUBE_MAP
:
693 case GL_TEXTURE_CUBE_MAP_ARRAY
:
694 case GL_PROXY_TEXTURE_CUBE_MAP
:
695 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
699 case GL_TEXTURE_2D_ARRAY
:
700 case GL_PROXY_TEXTURE_2D
:
701 case GL_PROXY_TEXTURE_2D_ARRAY
:
702 size
= MAX2(width
, height
);
705 case GL_PROXY_TEXTURE_3D
:
706 size
= MAX3(width
, height
, depth
);
708 case GL_TEXTURE_RECTANGLE
:
709 case GL_TEXTURE_EXTERNAL_OES
:
710 case GL_TEXTURE_2D_MULTISAMPLE
:
711 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
712 case GL_PROXY_TEXTURE_RECTANGLE
:
713 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
714 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 return _mesa_logbase2(size
) + 1;
725 #if 000 /* not used anymore */
727 * glTexImage[123]D can accept a NULL image pointer. In this case we
728 * create a texture image with unspecified image contents per the OpenGL
732 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
734 const GLint components
= _mesa_components_in_format(format
);
735 const GLint numPixels
= width
* height
* depth
;
736 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
740 * Let's see if anyone finds this. If glTexImage2D() is called with
741 * a NULL image pointer then load the texture image with something
742 * interesting instead of leaving it indeterminate.
745 static const char message
[8][32] = {
749 " X X XXXX XXX XXXXX ",
752 " X X XXXXX XXX X X ",
756 GLubyte
*imgPtr
= data
;
758 for (h
= 0; h
< depth
; h
++) {
759 for (i
= 0; i
< height
; i
++) {
760 GLint srcRow
= 7 - (i
% 8);
761 for (j
= 0; j
< width
; j
++) {
762 GLint srcCol
= j
% 32;
763 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
764 for (k
= 0; k
< components
; k
++) {
780 * Set the size and format-related fields of a gl_texture_image struct
781 * to zero. This is used when a proxy texture test fails.
784 clear_teximage_fields(struct gl_texture_image
*img
)
787 img
->_BaseFormat
= 0;
788 img
->InternalFormat
= 0;
799 img
->TexFormat
= MESA_FORMAT_NONE
;
801 img
->FixedSampleLocations
= GL_TRUE
;
806 * Initialize basic fields of the gl_texture_image struct.
808 * \param ctx GL context.
809 * \param img texture image structure to be initialized.
810 * \param width image width.
811 * \param height image height.
812 * \param depth image depth.
813 * \param border image border.
814 * \param internalFormat internal format.
815 * \param format the actual hardware format (one of MESA_FORMAT_*)
816 * \param numSamples number of samples per texel, or zero for non-MS.
817 * \param fixedSampleLocations are sample locations fixed?
819 * Fills in the fields of \p img with the given information.
820 * Note: width, height and depth include the border.
823 _mesa_init_teximage_fields_ms(struct gl_context
*ctx
,
824 struct gl_texture_image
*img
,
825 GLsizei width
, GLsizei height
, GLsizei depth
,
826 GLint border
, GLenum internalFormat
,
828 GLuint numSamples
, GLboolean fixedSampleLocations
)
830 const GLint base_format
=_mesa_base_tex_format(ctx
, internalFormat
);
837 target
= img
->TexObject
->Target
;
838 assert(base_format
!= -1);
839 img
->_BaseFormat
= (GLenum16
)base_format
;
840 img
->InternalFormat
= internalFormat
;
841 img
->Border
= border
;
843 img
->Height
= height
;
846 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
847 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
851 case GL_TEXTURE_BUFFER
:
852 case GL_PROXY_TEXTURE_1D
:
864 case GL_TEXTURE_1D_ARRAY
:
865 case GL_PROXY_TEXTURE_1D_ARRAY
:
866 img
->Height2
= height
; /* no border */
867 img
->HeightLog2
= 0; /* not used */
875 case GL_TEXTURE_RECTANGLE
:
876 case GL_TEXTURE_CUBE_MAP
:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
879 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
880 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
881 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
882 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
883 case GL_TEXTURE_EXTERNAL_OES
:
884 case GL_PROXY_TEXTURE_2D
:
885 case GL_PROXY_TEXTURE_RECTANGLE
:
886 case GL_PROXY_TEXTURE_CUBE_MAP
:
887 case GL_TEXTURE_2D_MULTISAMPLE
:
888 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
889 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
890 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
897 case GL_TEXTURE_2D_ARRAY
:
898 case GL_PROXY_TEXTURE_2D_ARRAY
:
899 case GL_TEXTURE_CUBE_MAP_ARRAY
:
900 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
901 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
902 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
903 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
904 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
905 img
->Depth2
= depth
; /* no border */
906 img
->DepthLog2
= 0; /* not used */
909 case GL_PROXY_TEXTURE_3D
:
910 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
911 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
912 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
913 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
916 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
921 _mesa_get_tex_max_num_levels(target
,
922 img
->Width2
, img
->Height2
, img
->Depth2
);
923 img
->TexFormat
= format
;
924 img
->NumSamples
= numSamples
;
925 img
->FixedSampleLocations
= fixedSampleLocations
;
930 _mesa_init_teximage_fields(struct gl_context
*ctx
,
931 struct gl_texture_image
*img
,
932 GLsizei width
, GLsizei height
, GLsizei depth
,
933 GLint border
, GLenum internalFormat
,
936 _mesa_init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
937 internalFormat
, format
, 0, GL_TRUE
);
942 * Free and clear fields of the gl_texture_image struct.
944 * \param ctx GL context.
945 * \param texImage texture image structure to be cleared.
947 * After the call, \p texImage will have no data associated with it. Its
948 * fields are cleared so that its parent object will test incomplete.
951 _mesa_clear_texture_image(struct gl_context
*ctx
,
952 struct gl_texture_image
*texImage
)
954 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
955 clear_teximage_fields(texImage
);
960 * Check the width, height, depth and border of a texture image are legal.
961 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
963 * The target and level parameters will have already been validated.
964 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
967 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
968 GLint level
, GLint width
, GLint height
,
969 GLint depth
, GLint border
)
975 case GL_PROXY_TEXTURE_1D
:
976 maxSize
= ctx
->Const
.MaxTextureSize
>> level
;
977 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
979 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
980 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
986 case GL_PROXY_TEXTURE_2D
:
987 case GL_TEXTURE_2D_MULTISAMPLE
:
988 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
989 maxSize
= ctx
->Const
.MaxTextureSize
>> level
;
990 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
992 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
994 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
995 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
997 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1003 case GL_PROXY_TEXTURE_3D
:
1004 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1006 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1008 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1010 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1012 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1013 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1015 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1017 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1022 case GL_TEXTURE_RECTANGLE_NV
:
1023 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1026 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1027 if (width
< 0 || width
> maxSize
)
1029 if (height
< 0 || height
> maxSize
)
1033 case GL_TEXTURE_CUBE_MAP
:
1034 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1035 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1036 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1037 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1040 case GL_PROXY_TEXTURE_CUBE_MAP
:
1041 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1043 if (width
!= height
)
1045 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1047 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1049 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1050 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1052 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1057 case GL_TEXTURE_1D_ARRAY_EXT
:
1058 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1059 maxSize
= ctx
->Const
.MaxTextureSize
>> level
;
1060 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1062 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1064 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1065 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1070 case GL_TEXTURE_2D_ARRAY_EXT
:
1071 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1072 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1073 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1074 maxSize
= ctx
->Const
.MaxTextureSize
>> level
;
1075 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1077 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1079 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1081 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1082 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1084 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1089 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1090 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1091 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1092 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1094 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1096 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1098 if (width
!= height
)
1100 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1102 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1103 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1105 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1110 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1116 error_check_subtexture_negative_dimensions(struct gl_context
*ctx
,
1125 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width=%d)", func
, subWidth
);
1129 if (dims
> 1 && subHeight
< 0) {
1130 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height=%d)", func
, subHeight
);
1134 if (dims
> 2 && subDepth
< 0) {
1135 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(depth=%d)", func
, subDepth
);
1143 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1144 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1145 * \param destImage the destination texture image.
1146 * \return GL_TRUE if error found, GL_FALSE otherwise.
1149 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1150 const struct gl_texture_image
*destImage
,
1151 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1152 GLsizei subWidth
, GLsizei subHeight
,
1153 GLsizei subDepth
, const char *func
)
1155 const GLenum target
= destImage
->TexObject
->Target
;
1158 /* check xoffset and width */
1159 if (xoffset
< - (GLint
) destImage
->Border
) {
1160 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1164 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1165 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset %d + width %d > %u)", func
,
1166 xoffset
, subWidth
, destImage
->Width
);
1170 /* check yoffset and height */
1172 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1173 if (yoffset
< -yBorder
) {
1174 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1177 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1178 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset %d + height %d > %u)",
1179 func
, yoffset
, subHeight
, destImage
->Height
);
1184 /* check zoffset and depth */
1187 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1188 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1189 0 : destImage
->Border
;
1191 if (zoffset
< -zBorder
) {
1192 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1196 depth
= (GLint
) destImage
->Depth
;
1197 if (target
== GL_TEXTURE_CUBE_MAP
)
1199 if (zoffset
+ subDepth
> depth
) {
1200 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset %d + depth %d > %u)",
1201 func
, zoffset
, subDepth
, depth
);
1207 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1208 * compressed texture images can be updated. But, that restriction may be
1209 * relaxed for particular compressed formats. At this time, all the
1210 * compressed formats supported by Mesa allow sub-textures to be updated
1211 * along compressed block boundaries.
1213 _mesa_get_format_block_size_3d(destImage
->TexFormat
, &bw
, &bh
, &bd
);
1215 if (bw
!= 1 || bh
!= 1 || bd
!= 1) {
1216 /* offset must be multiple of block size */
1217 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0) || (zoffset
% bd
!= 0)) {
1218 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1219 "%s(xoffset = %d, yoffset = %d, zoffset = %d)",
1220 func
, xoffset
, yoffset
, zoffset
);
1224 /* The size must be a multiple of bw x bh, or we must be using a
1225 * offset+size that exactly hits the edge of the image. This
1226 * is important for small mipmap levels (1x1, 2x1, etc) and for
1229 if ((subWidth
% bw
!= 0) &&
1230 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1232 "%s(width = %d)", func
, subWidth
);
1236 if ((subHeight
% bh
!= 0) &&
1237 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1239 "%s(height = %d)", func
, subHeight
);
1243 if ((subDepth
% bd
!= 0) &&
1244 (zoffset
+ subDepth
!= (GLint
) destImage
->Depth
)) {
1245 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1246 "%s(depth = %d)", func
, subDepth
);
1258 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1259 * specific texture image size checks.
1261 * A hardware driver might override this function if, for example, the
1262 * max 3D texture size is 512x512x64 (i.e. not a cube).
1264 * Note that width, height, depth == 0 is not an error. However, a
1265 * texture with zero width/height/depth will be considered "incomplete"
1266 * and texturing will effectively be disabled.
1268 * \param target any texture target/type
1269 * \param numLevels number of mipmap levels in the texture or 0 if not known
1270 * \param level as passed to glTexImage
1271 * \param format the MESA_FORMAT_x for the tex image
1272 * \param numSamples number of samples per texel
1273 * \param width as passed to glTexImage
1274 * \param height as passed to glTexImage
1275 * \param depth as passed to glTexImage
1276 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1279 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
1280 GLuint numLevels
, ASSERTED GLint level
,
1281 mesa_format format
, GLuint numSamples
,
1282 GLint width
, GLint height
, GLint depth
)
1284 uint64_t bytes
, mbytes
;
1286 if (numLevels
> 0) {
1287 /* Compute total memory for a whole mipmap. This is the path
1288 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1296 for (l
= 0; l
< numLevels
; l
++) {
1297 GLint nextWidth
, nextHeight
, nextDepth
;
1299 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1301 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1302 &nextWidth
, &nextHeight
,
1305 height
= nextHeight
;
1312 /* We just compute the size of one mipmap level. This is the path
1313 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1315 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1318 bytes
*= _mesa_num_tex_faces(target
);
1319 bytes
*= MAX2(1, numSamples
);
1321 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1323 /* We just check if the image size is less than MaxTextureMbytes.
1324 * Some drivers may do more specific checks.
1326 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1331 * Return true if the format is only valid for glCompressedTexImage.
1334 compressedteximage_only_format(GLenum format
)
1337 case GL_PALETTE4_RGB8_OES
:
1338 case GL_PALETTE4_RGBA8_OES
:
1339 case GL_PALETTE4_R5_G6_B5_OES
:
1340 case GL_PALETTE4_RGBA4_OES
:
1341 case GL_PALETTE4_RGB5_A1_OES
:
1342 case GL_PALETTE8_RGB8_OES
:
1343 case GL_PALETTE8_RGBA8_OES
:
1344 case GL_PALETTE8_R5_G6_B5_OES
:
1345 case GL_PALETTE8_RGBA4_OES
:
1346 case GL_PALETTE8_RGB5_A1_OES
:
1347 case GL_ATC_RGB_AMD
:
1348 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
:
1349 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
:
1357 * Return true if the format doesn't support online compression.
1360 _mesa_format_no_online_compression(GLenum format
)
1362 return _mesa_is_astc_format(format
) ||
1363 _mesa_is_etc2_format(format
) ||
1364 compressedteximage_only_format(format
);
1367 /* Writes to an GL error pointer if non-null and returns whether or not the
1368 * error is GL_NO_ERROR */
1370 write_error(GLenum
*err_ptr
, GLenum error
)
1375 return error
== GL_NO_ERROR
;
1379 * Helper function to determine whether a target and specific compression
1380 * format are supported. The error parameter returns GL_NO_ERROR if the
1381 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1382 * or GL_INVALID_ENUM, whichever is more appropriate.
1385 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1386 GLenum intFormat
, GLenum
*error
)
1388 GLboolean target_can_be_compresed
= GL_FALSE
;
1389 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1390 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1394 case GL_PROXY_TEXTURE_2D
:
1395 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1397 case GL_PROXY_TEXTURE_CUBE_MAP
:
1398 case GL_TEXTURE_CUBE_MAP
:
1399 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1400 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1403 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1404 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1405 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1407 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1408 case GL_TEXTURE_2D_ARRAY_EXT
:
1409 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1411 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1412 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1413 /* From the KHR_texture_compression_astc_hdr spec:
1415 * Add a second new column "3D Tex." which is empty for all non-ASTC
1416 * formats. If only the LDR profile is supported by the
1417 * implementation, this column is also empty for all ASTC formats. If
1418 * both the LDR and HDR profiles are supported only, this column is
1419 * checked for all ASTC formats.
1421 * Add a third new column "Cube Map Array Tex." which is empty for all
1422 * non-ASTC formats, and checked for all ASTC formats.
1426 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1427 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1428 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1429 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1430 * 8.19 is *not* checked'
1432 * The instances of <internalformat> above should say <target>.
1434 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1435 * have already been handled by normal ETC2/EAC behavior.
1438 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1440 * "The ETC2/EAC texture compression algorithm supports only
1441 * two-dimensional images. If internalformat is an ETC2/EAC format,
1442 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1443 * target is not TEXTURE_2D_ARRAY."
1445 * This should also be applicable for glTexStorage3D(). Other available
1446 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1448 * Section 8.7, page 179 of OpenGL ES 3.2 adds:
1450 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1451 * if internalformat is one of the the formats in table 8.17 and target is
1452 * not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY or TEXTURE_3D.
1454 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1455 * if internalformat is TEXTURE_CUBE_MAP_ARRAY and the “Cube Map
1456 * Array” column of table 8.17 is not checked, or if internalformat
1457 * is TEXTURE_- 3D and the “3D Tex.” column of table 8.17 is not
1460 * The instances of <internalformat> above should say <target>.
1462 * Such table 8.17 has checked "Cube Map Array" column for all the
1463 * cases. So in practice, TEXTURE_CUBE_MAP_ARRAY is now valid for OpenGL ES 3.2
1465 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
) &&
1466 !_mesa_is_gles32(ctx
))
1467 return write_error(error
, GL_INVALID_OPERATION
);
1468 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1472 case MESA_FORMAT_LAYOUT_ETC2
:
1473 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1474 if (_mesa_is_gles3(ctx
))
1475 return write_error(error
, GL_INVALID_OPERATION
);
1477 case MESA_FORMAT_LAYOUT_BPTC
:
1478 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1480 case MESA_FORMAT_LAYOUT_ASTC
:
1481 target_can_be_compresed
=
1482 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1483 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1485 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1486 * neither of the above extensions are supported. See comment in
1487 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1489 if (!target_can_be_compresed
)
1490 return write_error(error
, GL_INVALID_OPERATION
);
1498 return write_error(error
,
1499 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1504 * Check if the given texture target value is legal for a
1505 * glTexImage1/2/3D call.
1508 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1514 case GL_PROXY_TEXTURE_1D
:
1515 return _mesa_is_desktop_gl(ctx
);
1523 case GL_PROXY_TEXTURE_2D
:
1524 return _mesa_is_desktop_gl(ctx
);
1525 case GL_PROXY_TEXTURE_CUBE_MAP
:
1526 return _mesa_is_desktop_gl(ctx
)
1527 && ctx
->Extensions
.ARB_texture_cube_map
;
1528 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1530 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1531 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1532 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1533 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1534 return ctx
->Extensions
.ARB_texture_cube_map
;
1535 case GL_TEXTURE_RECTANGLE_NV
:
1536 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1537 return _mesa_is_desktop_gl(ctx
)
1538 && ctx
->Extensions
.NV_texture_rectangle
;
1539 case GL_TEXTURE_1D_ARRAY_EXT
:
1540 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1541 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1549 case GL_PROXY_TEXTURE_3D
:
1550 return _mesa_is_desktop_gl(ctx
);
1551 case GL_TEXTURE_2D_ARRAY_EXT
:
1552 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1553 || _mesa_is_gles3(ctx
);
1554 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1555 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1556 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1557 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1558 return _mesa_has_texture_cube_map_array(ctx
);
1563 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1570 * Check if the given texture target value is legal for a
1571 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1572 * The difference compared to legal_teximage_target() above is that
1573 * proxy targets are not supported.
1576 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1581 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1586 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1587 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1588 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1589 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1590 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1591 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1592 return ctx
->Extensions
.ARB_texture_cube_map
;
1593 case GL_TEXTURE_RECTANGLE_NV
:
1594 return _mesa_is_desktop_gl(ctx
)
1595 && ctx
->Extensions
.NV_texture_rectangle
;
1596 case GL_TEXTURE_1D_ARRAY_EXT
:
1597 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1605 case GL_TEXTURE_2D_ARRAY_EXT
:
1606 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1607 || _mesa_is_gles3(ctx
);
1608 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1609 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1610 return _mesa_has_texture_cube_map_array(ctx
);
1612 /* Table 8.15 of the OpenGL 4.5 core profile spec
1613 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1614 * and CopyTextureSubImage3D.
1616 case GL_TEXTURE_CUBE_MAP
:
1622 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1630 * Helper function to determine if a texture object is mutable (in terms
1631 * of GL_ARB_texture_storage/GL_ARB_bindless_texture).
1634 mutable_tex_object(struct gl_texture_object
*texObj
)
1639 if (texObj
->HandleAllocated
) {
1640 /* The ARB_bindless_texture spec says:
1642 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
1643 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
1644 * functions defined in terms of these, if the texture object to be
1645 * modified is referenced by one or more texture or image handles."
1650 return !texObj
->Immutable
;
1655 * Return expected size of a compressed texture.
1658 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1661 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1662 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1666 * Verify that a texture format is valid with a particular target
1668 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1669 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1672 * \param ctx GL context
1673 * \param target Texture target
1674 * \param internalFormat Internal format of the texture image
1676 * \returns true if the combination is legal, false otherwise.
1679 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1680 GLenum target
, GLenum internalFormat
)
1682 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1683 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1684 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1685 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1686 * Profile spec says:
1688 * "Textures with a base internal format of DEPTH_COMPONENT or
1689 * DEPTH_STENCIL are supported by texture image specification
1690 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1691 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1692 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1693 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1694 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1695 * formats in conjunction with any other target will result in an
1696 * INVALID_OPERATION error."
1698 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1699 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1701 if (target
!= GL_TEXTURE_1D
&&
1702 target
!= GL_PROXY_TEXTURE_1D
&&
1703 target
!= GL_TEXTURE_2D
&&
1704 target
!= GL_PROXY_TEXTURE_2D
&&
1705 target
!= GL_TEXTURE_1D_ARRAY
&&
1706 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1707 target
!= GL_TEXTURE_2D_ARRAY
&&
1708 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1709 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1710 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1711 !((_mesa_is_cube_face(target
) ||
1712 target
== GL_TEXTURE_CUBE_MAP
||
1713 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1714 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1715 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1716 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1717 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1718 _mesa_has_texture_cube_map_array(ctx
))) {
1727 texture_formats_agree(GLenum internalFormat
,
1730 GLboolean colorFormat
;
1731 GLboolean is_format_depth_or_depthstencil
;
1732 GLboolean is_internalFormat_depth_or_depthstencil
;
1734 /* Even though there are no color-index textures, we still have to support
1735 * uploading color-index data and remapping it to RGB via the
1736 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1738 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1740 is_internalFormat_depth_or_depthstencil
=
1741 _mesa_is_depth_format(internalFormat
) ||
1742 _mesa_is_depthstencil_format(internalFormat
);
1744 is_format_depth_or_depthstencil
=
1745 _mesa_is_depth_format(format
) ||
1746 _mesa_is_depthstencil_format(format
);
1748 colorFormat
= _mesa_is_color_format(format
);
1750 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1753 if (is_internalFormat_depth_or_depthstencil
!=
1754 is_format_depth_or_depthstencil
)
1757 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1764 * Test the combination of format, type and internal format arguments of
1765 * different texture operations on GLES.
1767 * \param ctx GL context.
1768 * \param format pixel data format given by the user.
1769 * \param type pixel data type given by the user.
1770 * \param internalFormat internal format given by the user.
1771 * \param callerName name of the caller function to print in the error message
1773 * \return true if a error is found, false otherwise
1775 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1778 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1779 GLenum type
, GLenum internalFormat
, const char *callerName
)
1781 GLenum err
= _mesa_gles_error_check_format_and_type(ctx
, format
, type
,
1783 if (err
!= GL_NO_ERROR
) {
1784 _mesa_error(ctx
, err
,
1785 "%s(format = %s, type = %s, internalformat = %s)",
1786 callerName
, _mesa_enum_to_string(format
),
1787 _mesa_enum_to_string(type
),
1788 _mesa_enum_to_string(internalFormat
));
1796 * Test the glTexImage[123]D() parameters for errors.
1798 * \param ctx GL context.
1799 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1800 * \param target texture target given by the user (already validated).
1801 * \param level image level given by the user.
1802 * \param internalFormat internal format given by the user.
1803 * \param format pixel data format given by the user.
1804 * \param type pixel data type given by the user.
1805 * \param width image width given by the user.
1806 * \param height image height given by the user.
1807 * \param depth image depth given by the user.
1808 * \param border image border given by the user.
1810 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1812 * Verifies each of the parameters against the constants specified in
1813 * __struct gl_contextRec::Const and the supported extensions, and according
1814 * to the OpenGL specification.
1815 * Note that we don't fully error-check the width, height, depth values
1816 * here. That's done in _mesa_legal_texture_dimensions() which is used
1817 * by several other GL entrypoints. Plus, texture dims have a special
1818 * interaction with proxy textures.
1821 texture_error_check( struct gl_context
*ctx
,
1822 GLuint dimensions
, GLenum target
,
1823 struct gl_texture_object
* texObj
,
1824 GLint level
, GLint internalFormat
,
1825 GLenum format
, GLenum type
,
1826 GLint width
, GLint height
,
1827 GLint depth
, GLint border
,
1828 const GLvoid
*pixels
)
1832 /* Note: for proxy textures, some error conditions immediately generate
1833 * a GL error in the usual way. But others do not generate a GL error.
1834 * Instead, they cause the width, height, depth, format fields of the
1835 * texture image to be zeroed-out. The GL spec seems to indicate that the
1836 * zero-out behaviour is only used in cases related to memory allocation.
1840 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1841 _mesa_error(ctx
, GL_INVALID_VALUE
,
1842 "glTexImage%dD(level=%d)", dimensions
, level
);
1847 if (border
< 0 || border
> 1 ||
1848 ((ctx
->API
!= API_OPENGL_COMPAT
||
1849 target
== GL_TEXTURE_RECTANGLE_NV
||
1850 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1851 _mesa_error(ctx
, GL_INVALID_VALUE
,
1852 "glTexImage%dD(border=%d)", dimensions
, border
);
1856 if (width
< 0 || height
< 0 || depth
< 0) {
1857 _mesa_error(ctx
, GL_INVALID_VALUE
,
1858 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1862 /* Check incoming image format and type */
1863 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1864 if (err
!= GL_NO_ERROR
) {
1865 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1866 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1868 * "Specifying a value for internalformat that is not one of the
1869 * above (acceptable) values generates the error INVALID VALUE."
1871 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1872 err
= GL_INVALID_VALUE
;
1874 _mesa_error(ctx
, err
,
1875 "glTexImage%dD(incompatible format = %s, type = %s)",
1876 dimensions
, _mesa_enum_to_string(format
),
1877 _mesa_enum_to_string(type
));
1881 /* Check internalFormat */
1882 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1883 _mesa_error(ctx
, GL_INVALID_VALUE
,
1884 "glTexImage%dD(internalFormat=%s)",
1885 dimensions
, _mesa_enum_to_string(internalFormat
));
1889 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1890 * combinations of format, internalFormat, and type that can be used.
1891 * Formats and types that require additional extensions (e.g., GL_FLOAT
1892 * requires GL_OES_texture_float) are filtered elsewhere.
1894 char bufCallerName
[20];
1895 _mesa_snprintf(bufCallerName
, 20, "glTexImage%dD", dimensions
);
1896 if (_mesa_is_gles(ctx
) &&
1897 texture_format_error_check_gles(ctx
, format
, type
,
1898 internalFormat
, bufCallerName
)) {
1902 /* validate the bound PBO, if any */
1903 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1904 width
, height
, depth
, format
, type
,
1905 INT_MAX
, pixels
, "glTexImage")) {
1909 /* make sure internal format and format basically agree */
1910 if (!texture_formats_agree(internalFormat
, format
)) {
1911 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1912 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1913 dimensions
, _mesa_enum_to_string(internalFormat
),
1914 _mesa_enum_to_string(format
));
1918 /* additional checks for ycbcr textures */
1919 if (internalFormat
== GL_YCBCR_MESA
) {
1920 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1921 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1922 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1924 _mesa_snprintf(message
, sizeof(message
),
1925 "glTexImage%dD(format/type YCBCR mismatch)",
1927 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1928 return GL_TRUE
; /* error */
1930 if (target
!= GL_TEXTURE_2D
&&
1931 target
!= GL_PROXY_TEXTURE_2D
&&
1932 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1933 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1934 _mesa_error(ctx
, GL_INVALID_ENUM
,
1935 "glTexImage%dD(bad target for YCbCr texture)",
1941 _mesa_snprintf(message
, sizeof(message
),
1942 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1943 dimensions
, border
);
1944 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1949 /* additional checks for depth textures */
1950 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1951 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1952 "glTexImage%dD(bad target for texture)", dimensions
);
1956 /* additional checks for compressed textures */
1957 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1959 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1960 _mesa_error(ctx
, err
,
1961 "glTexImage%dD(target can't be compressed)", dimensions
);
1964 if (_mesa_format_no_online_compression(internalFormat
)) {
1965 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1966 "glTexImage%dD(no compression for format)", dimensions
);
1970 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1971 "glTexImage%dD(border!=0)", dimensions
);
1976 /* additional checks for integer textures */
1977 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1978 (_mesa_is_enum_format_integer(format
) !=
1979 _mesa_is_enum_format_integer(internalFormat
))) {
1980 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1981 "glTexImage%dD(integer/non-integer format mismatch)",
1986 if (!mutable_tex_object(texObj
)) {
1987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1988 "glTexImage%dD(immutable texture)", dimensions
);
1992 /* if we get here, the parameters are OK */
1998 * Error checking for glCompressedTexImage[123]D().
1999 * Note that the width, height and depth values are not fully error checked
2001 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2004 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2005 GLenum target
, struct gl_texture_object
* texObj
,
2006 GLint level
, GLenum internalFormat
, GLsizei width
,
2007 GLsizei height
, GLsizei depth
, GLint border
,
2008 GLsizei imageSize
, const GLvoid
*data
)
2010 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2012 GLenum error
= GL_NO_ERROR
;
2013 char *reason
= ""; /* no error */
2015 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2020 /* This will detect any invalid internalFormat value */
2021 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2022 _mesa_error(ctx
, GL_INVALID_ENUM
,
2023 "glCompressedTexImage%dD(internalFormat=%s)",
2024 dimensions
, _mesa_enum_to_string(internalFormat
));
2028 /* validate the bound PBO, if any */
2029 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2031 "glCompressedTexImage")) {
2035 switch (internalFormat
) {
2036 case GL_PALETTE4_RGB8_OES
:
2037 case GL_PALETTE4_RGBA8_OES
:
2038 case GL_PALETTE4_R5_G6_B5_OES
:
2039 case GL_PALETTE4_RGBA4_OES
:
2040 case GL_PALETTE4_RGB5_A1_OES
:
2041 case GL_PALETTE8_RGB8_OES
:
2042 case GL_PALETTE8_RGBA8_OES
:
2043 case GL_PALETTE8_R5_G6_B5_OES
:
2044 case GL_PALETTE8_RGBA4_OES
:
2045 case GL_PALETTE8_RGB5_A1_OES
:
2046 /* check level (note that level should be zero or less!) */
2047 if (level
> 0 || level
< -maxLevels
) {
2049 error
= GL_INVALID_VALUE
;
2053 if (dimensions
!= 2) {
2054 reason
= "compressed paletted textures must be 2D";
2055 error
= GL_INVALID_OPERATION
;
2059 /* Figure out the expected texture size (in bytes). This will be
2060 * checked against the actual size later.
2062 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2065 /* This is for the benefit of the TestProxyTexImage below. It expects
2066 * level to be non-negative. OES_compressed_paletted_texture uses a
2067 * weird mechanism where the level specified to glCompressedTexImage2D
2068 * is -(n-1) number of levels in the texture, and the data specifies the
2069 * complete mipmap stack. This is done to ensure the palette is the
2070 * same for all levels.
2077 if (level
< 0 || level
>= maxLevels
) {
2079 error
= GL_INVALID_VALUE
;
2083 /* Figure out the expected texture size (in bytes). This will be
2084 * checked against the actual size later.
2086 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2090 /* This should really never fail */
2091 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2092 reason
= "internalFormat";
2093 error
= GL_INVALID_ENUM
;
2097 /* No compressed formats support borders at this time */
2099 reason
= "border != 0";
2100 error
= GL_INVALID_VALUE
;
2104 /* Check for invalid pixel storage modes */
2105 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2107 "glCompressedTexImage")) {
2111 /* check image size in bytes */
2112 if (expectedSize
!= imageSize
) {
2113 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2114 * if <imageSize> is not consistent with the format, dimensions, and
2115 * contents of the specified image.
2117 reason
= "imageSize inconsistent with width/height/format";
2118 error
= GL_INVALID_VALUE
;
2122 if (!mutable_tex_object(texObj
)) {
2123 reason
= "immutable texture";
2124 error
= GL_INVALID_OPERATION
;
2131 /* Note: not all error paths exit through here. */
2132 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2133 dimensions
, reason
);
2140 * Test glTexSubImage[123]D() parameters for errors.
2142 * \param ctx GL context.
2143 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2144 * \param target texture target given by the user (already validated)
2145 * \param level image level given by the user.
2146 * \param xoffset sub-image x offset given by the user.
2147 * \param yoffset sub-image y offset given by the user.
2148 * \param zoffset sub-image z offset given by the user.
2149 * \param format pixel data format given by the user.
2150 * \param type pixel data type given by the user.
2151 * \param width image width given by the user.
2152 * \param height image height given by the user.
2153 * \param depth image depth given by the user.
2155 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2157 * Verifies each of the parameters against the constants specified in
2158 * __struct gl_contextRec::Const and the supported extensions, and according
2159 * to the OpenGL specification.
2162 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2163 struct gl_texture_object
*texObj
,
2164 GLenum target
, GLint level
,
2165 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2166 GLint width
, GLint height
, GLint depth
,
2167 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2168 const char *callerName
)
2170 struct gl_texture_image
*texImage
;
2174 /* must be out of memory */
2175 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2180 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2181 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2185 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2186 width
, height
, depth
,
2191 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2193 /* non-existant texture level */
2194 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
2199 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2200 if (err
!= GL_NO_ERROR
) {
2201 _mesa_error(ctx
, err
,
2202 "%s(incompatible format = %s, type = %s)",
2203 callerName
, _mesa_enum_to_string(format
),
2204 _mesa_enum_to_string(type
));
2208 GLenum internalFormat
= _mesa_is_gles(ctx
) ?
2209 oes_float_internal_format(ctx
, texImage
->InternalFormat
, type
) :
2210 texImage
->InternalFormat
;
2212 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2213 * combinations of format, internalFormat, and type that can be used.
2214 * Formats and types that require additional extensions (e.g., GL_FLOAT
2215 * requires GL_OES_texture_float) are filtered elsewhere.
2217 if (_mesa_is_gles(ctx
) &&
2218 texture_format_error_check_gles(ctx
, format
, type
,
2219 internalFormat
, callerName
)) {
2223 /* validate the bound PBO, if any */
2224 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2225 width
, height
, depth
, format
, type
,
2226 INT_MAX
, pixels
, callerName
)) {
2230 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2231 texImage
, xoffset
, yoffset
, zoffset
,
2232 width
, height
, depth
, callerName
)) {
2236 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2237 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2239 "%s(no compression for format)", callerName
);
2244 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2245 /* both source and dest must be integer-valued, or neither */
2246 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2247 _mesa_is_enum_format_integer(format
)) {
2248 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2249 "%s(integer/non-integer format mismatch)", callerName
);
2259 * Test glCopyTexImage[12]D() parameters for errors.
2261 * \param ctx GL context.
2262 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2263 * \param target texture target given by the user.
2264 * \param level image level given by the user.
2265 * \param internalFormat internal format given by the user.
2266 * \param width image width given by the user.
2267 * \param height image height given by the user.
2268 * \param border texture border.
2270 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2272 * Verifies each of the parameters against the constants specified in
2273 * __struct gl_contextRec::Const and the supported extensions, and according
2274 * to the OpenGL specification.
2277 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2278 GLenum target
, struct gl_texture_object
* texObj
,
2279 GLint level
, GLint internalFormat
, GLint border
)
2282 GLint rb_base_format
;
2283 struct gl_renderbuffer
*rb
;
2284 GLenum rb_internal_format
;
2287 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2288 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2289 dimensions
, _mesa_enum_to_string(target
));
2294 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2295 _mesa_error(ctx
, GL_INVALID_VALUE
,
2296 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2300 /* Check that the source buffer is complete */
2301 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2302 if (ctx
->ReadBuffer
->_Status
== 0) {
2303 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2305 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2306 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2307 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2311 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2312 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2313 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2319 if (border
< 0 || border
> 1 ||
2320 ((ctx
->API
!= API_OPENGL_COMPAT
||
2321 target
== GL_TEXTURE_RECTANGLE_NV
||
2322 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2323 _mesa_error(ctx
, GL_INVALID_VALUE
,
2324 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2328 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2331 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2332 switch (internalFormat
) {
2337 case GL_LUMINANCE_ALPHA
:
2340 _mesa_error(ctx
, GL_INVALID_ENUM
,
2341 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2342 _mesa_enum_to_string(internalFormat
));
2347 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2348 * OpenGL 4.5 (Compatibility Profile) spec says:
2350 * "Parameters level, internalformat, and border are specified using
2351 * the same values, with the same meanings, as the corresponding
2352 * arguments of TexImage2D, except that internalformat may not be
2353 * specified as 1, 2, 3, or 4."
2355 if (internalFormat
>= 1 && internalFormat
<= 4) {
2356 _mesa_error(ctx
, GL_INVALID_ENUM
,
2357 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2363 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2364 if (baseFormat
< 0) {
2365 _mesa_error(ctx
, GL_INVALID_ENUM
,
2366 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2367 _mesa_enum_to_string(internalFormat
));
2371 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2373 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2374 "glCopyTexImage%dD(read buffer)", dimensions
);
2378 rb_internal_format
= rb
->InternalFormat
;
2379 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2380 if (_mesa_is_color_format(internalFormat
)) {
2381 if (rb_base_format
< 0) {
2382 _mesa_error(ctx
, GL_INVALID_VALUE
,
2383 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2384 _mesa_enum_to_string(internalFormat
));
2389 if (_mesa_is_gles(ctx
)) {
2391 if (_mesa_components_in_format(baseFormat
) >
2392 _mesa_components_in_format(rb_base_format
)) {
2395 if (baseFormat
== GL_DEPTH_COMPONENT
||
2396 baseFormat
== GL_DEPTH_STENCIL
||
2397 baseFormat
== GL_STENCIL_INDEX
||
2398 rb_base_format
== GL_DEPTH_COMPONENT
||
2399 rb_base_format
== GL_DEPTH_STENCIL
||
2400 rb_base_format
== GL_STENCIL_INDEX
||
2401 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2402 baseFormat
== GL_ALPHA
) &&
2403 rb_base_format
!= GL_RGBA
) ||
2404 internalFormat
== GL_RGB9_E5
) {
2407 if (internalFormat
== GL_RGB9_E5
) {
2411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2412 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2413 _mesa_enum_to_string(internalFormat
));
2418 if (_mesa_is_gles3(ctx
)) {
2419 bool rb_is_srgb
= (ctx
->Extensions
.EXT_sRGB
&&
2420 _mesa_is_format_srgb(rb
->Format
));
2421 bool dst_is_srgb
= false;
2423 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2427 if (rb_is_srgb
!= dst_is_srgb
) {
2428 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2429 * OpenGLES 3.0.0 spec says:
2431 * "The error INVALID_OPERATION is also generated if the
2432 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2433 * framebuffer attachment corresponding to the read buffer
2434 * is LINEAR (see section 6.1.13) and internalformat is
2435 * one of the sRGB formats described in section 3.8.16, or
2436 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2437 * SRGB and internalformat is not one of the sRGB formats."
2439 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2440 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2444 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2445 * types for SNORM formats. Also, conversion to SNORM formats is not
2446 * allowed by Table 3.2 on Page 110.
2448 if (!_mesa_has_EXT_render_snorm(ctx
) &&
2449 _mesa_is_enum_format_snorm(internalFormat
)) {
2450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2451 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2452 _mesa_enum_to_string(internalFormat
));
2457 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2459 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2463 /* From the EXT_texture_integer spec:
2465 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2466 * if the texture internalformat is an integer format and the read color
2467 * buffer is not an integer format, or if the internalformat is not an
2468 * integer format and the read color buffer is an integer format."
2470 if (_mesa_is_color_format(internalFormat
)) {
2471 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2472 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2473 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2474 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2475 if (is_int
|| is_rbint
) {
2476 if (is_int
!= is_rbint
) {
2477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2478 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2480 } else if (_mesa_is_gles(ctx
) &&
2481 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2482 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2483 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2484 "glCopyTexImage%dD(signed vs unsigned integer)",
2490 /* From page 138 of OpenGL ES 3.0 spec:
2491 * "The error INVALID_OPERATION is generated if floating-point RGBA
2492 * data is required; if signed integer RGBA data is required and the
2493 * format of the current color buffer is not signed integer; if
2494 * unsigned integer RGBA data is required and the format of the
2495 * current color buffer is not unsigned integer; or if fixed-point
2496 * RGBA data is required and the format of the current color buffer
2497 * is not fixed-point.
2499 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2500 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2501 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2504 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2506 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2507 _mesa_error(ctx
, err
,
2508 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2511 if (_mesa_format_no_online_compression(internalFormat
)) {
2512 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2513 "glCopyTexImage%dD(no compression for format)", dimensions
);
2517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2518 "glCopyTexImage%dD(border!=0)", dimensions
);
2523 if (!mutable_tex_object(texObj
)) {
2524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2525 "glCopyTexImage%dD(immutable texture)", dimensions
);
2529 /* if we get here, the parameters are OK */
2535 * Test glCopyTexSubImage[12]D() parameters for errors.
2536 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2539 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2540 const struct gl_texture_object
*texObj
,
2541 GLenum target
, GLint level
,
2542 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2543 GLint width
, GLint height
, const char *caller
)
2547 struct gl_texture_image
*texImage
;
2549 /* Check that the source buffer is complete */
2550 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2551 if (ctx
->ReadBuffer
->_Status
== 0) {
2552 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2554 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2555 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2556 "%s(invalid readbuffer)", caller
);
2560 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2561 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2562 "%s(multisample FBO)", caller
);
2568 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2569 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2573 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2575 /* destination image does not exist */
2576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2577 "%s(invalid texture level %d)", caller
, level
);
2581 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2582 width
, height
, 1, caller
)) {
2586 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2587 xoffset
, yoffset
, zoffset
,
2588 width
, height
, 1, caller
)) {
2592 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2593 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2595 "%s(no compression for format)", caller
);
2600 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2605 /* From OpenGL ES 3.2 spec, section 8.6:
2607 * "An INVALID_OPERATION error is generated by CopyTexSubImage3D,
2608 * CopyTexImage2D, or CopyTexSubImage2D if the internalformat of the
2609 * texture image being (re)specified is RGB9_E5"
2611 if (texImage
->InternalFormat
== GL_RGB9_E5
&&
2612 !_mesa_is_desktop_gl(ctx
)) {
2613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2614 "%s(invalid internal format %s)", caller
,
2615 _mesa_enum_to_string(texImage
->InternalFormat
));
2619 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2620 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2621 "%s(missing readbuffer, format=%s)", caller
,
2622 _mesa_enum_to_string(texImage
->_BaseFormat
));
2626 /* From the EXT_texture_integer spec:
2628 * "INVALID_OPERATION is generated by CopyTexImage* and
2629 * CopyTexSubImage* if the texture internalformat is an integer format
2630 * and the read color buffer is not an integer format, or if the
2631 * internalformat is not an integer format and the read color buffer
2632 * is an integer format."
2634 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2635 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2637 if (_mesa_is_format_integer_color(rb
->Format
) !=
2638 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2640 "%s(integer vs non-integer)", caller
);
2645 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2646 * framebuffer/destination texture base internal format combinations),
2647 * all the entries for stencil are left blank (unsupported).
2649 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2650 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2654 /* if we get here, the parameters are OK */
2659 /** Callback info for walking over FBO hash table */
2662 struct gl_context
*ctx
;
2663 struct gl_texture_object
*texObj
;
2669 * Check render to texture callback. Called from _mesa_HashWalk().
2672 check_rtt_cb(UNUSED GLuint key
, void *data
, void *userData
)
2674 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2675 const struct cb_info
*info
= (struct cb_info
*) userData
;
2676 struct gl_context
*ctx
= info
->ctx
;
2677 const struct gl_texture_object
*texObj
= info
->texObj
;
2678 const GLuint level
= info
->level
, face
= info
->face
;
2680 /* If this is a user-created FBO */
2681 if (_mesa_is_user_fbo(fb
)) {
2683 /* check if any of the FBO's attachments point to 'texObj' */
2684 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2685 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2686 if (att
->Type
== GL_TEXTURE
&&
2687 att
->Texture
== texObj
&&
2688 att
->TextureLevel
== level
&&
2689 att
->CubeMapFace
== face
) {
2690 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2691 assert(att
->Renderbuffer
->TexImage
);
2692 /* Mark fb status as indeterminate to force re-validation */
2695 /* Make sure that the revalidation actually happens if this is
2696 * being done to currently-bound buffers.
2698 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2699 ctx
->NewState
|= _NEW_BUFFERS
;
2707 * When a texture image is specified we have to check if it's bound to
2708 * any framebuffer objects (render to texture) in order to detect changes
2709 * in size or format since that effects FBO completeness.
2710 * Any FBOs rendering into the texture must be re-validated.
2713 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2714 struct gl_texture_object
*texObj
,
2715 GLuint face
, GLuint level
)
2717 /* Only check this texture if it's been marked as RenderToTexture */
2718 if (texObj
->_RenderToTexture
) {
2719 struct cb_info info
;
2721 info
.texObj
= texObj
;
2724 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2730 * If the texture object's GenerateMipmap flag is set and we've
2731 * changed the texture base level image, regenerate the rest of the
2732 * mipmap levels now.
2735 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2736 struct gl_texture_object
*texObj
, GLint level
)
2738 if (texObj
->GenerateMipmap
&&
2739 level
== texObj
->BaseLevel
&&
2740 level
< texObj
->MaxLevel
) {
2741 assert(ctx
->Driver
.GenerateMipmap
);
2742 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2747 /** Debug helper: override the user-requested internal format */
2749 override_internal_format(GLenum internalFormat
, UNUSED GLint width
,
2750 UNUSED GLint height
)
2753 if (internalFormat
== GL_RGBA16F_ARB
||
2754 internalFormat
== GL_RGBA32F_ARB
) {
2755 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2758 else if (internalFormat
== GL_RGB16F_ARB
||
2759 internalFormat
== GL_RGB32F_ARB
) {
2760 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2763 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2764 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2765 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2766 return GL_LUMINANCE_ALPHA
;
2768 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2769 internalFormat
== GL_LUMINANCE32F_ARB
) {
2770 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2771 return GL_LUMINANCE
;
2773 else if (internalFormat
== GL_ALPHA16F_ARB
||
2774 internalFormat
== GL_ALPHA32F_ARB
) {
2775 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2779 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2780 internalFormat = GL_RGBA;
2784 return internalFormat
;
2787 return internalFormat
;
2793 * Choose the actual hardware format for a texture image.
2794 * Try to use the same format as the previous image level when possible.
2795 * Otherwise, ask the driver for the best format.
2796 * It's important to try to choose a consistant format for all levels
2797 * for efficient texture memory layout/allocation. In particular, this
2798 * comes up during automatic mipmap generation.
2801 _mesa_choose_texture_format(struct gl_context
*ctx
,
2802 struct gl_texture_object
*texObj
,
2803 GLenum target
, GLint level
,
2804 GLenum internalFormat
, GLenum format
, GLenum type
)
2808 /* see if we've already chosen a format for the previous level */
2810 struct gl_texture_image
*prevImage
=
2811 _mesa_select_tex_image(texObj
, target
, level
- 1);
2812 /* See if the prev level is defined and has an internal format which
2813 * matches the new internal format.
2816 prevImage
->Width
> 0 &&
2817 prevImage
->InternalFormat
== internalFormat
) {
2818 /* use the same format */
2819 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2820 return prevImage
->TexFormat
;
2824 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2826 assert(f
!= MESA_FORMAT_NONE
);
2832 * Adjust pixel unpack params and image dimensions to strip off the
2833 * one-pixel texture border.
2835 * Gallium and intel don't support texture borders. They've seldem been used
2836 * and seldom been implemented correctly anyway.
2838 * \param unpackNew returns the new pixel unpack parameters
2841 strip_texture_border(GLenum target
,
2842 GLint
*width
, GLint
*height
, GLint
*depth
,
2843 const struct gl_pixelstore_attrib
*unpack
,
2844 struct gl_pixelstore_attrib
*unpackNew
)
2850 *unpackNew
= *unpack
;
2852 if (unpackNew
->RowLength
== 0)
2853 unpackNew
->RowLength
= *width
;
2855 if (unpackNew
->ImageHeight
== 0)
2856 unpackNew
->ImageHeight
= *height
;
2858 assert(*width
>= 3);
2859 unpackNew
->SkipPixels
++; /* skip the border */
2860 *width
= *width
- 2; /* reduce the width by two border pixels */
2862 /* The min height of a texture with a border is 3 */
2863 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2864 unpackNew
->SkipRows
++; /* skip the border */
2865 *height
= *height
- 2; /* reduce the height by two border pixels */
2869 target
!= GL_TEXTURE_2D_ARRAY
&&
2870 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2871 unpackNew
->SkipImages
++; /* skip the border */
2872 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2876 static struct gl_texture_object
*
2877 lookup_texture_ext_dsa(struct gl_context
*ctx
, GLenum target
, GLuint texture
,
2882 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2883 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2884 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2885 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2886 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2888 boundTarget
= GL_TEXTURE_CUBE_MAP
;
2891 boundTarget
= target
;
2895 int targetIndex
= _mesa_tex_target_to_index(ctx
, boundTarget
);
2896 if (targetIndex
< 0) {
2897 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target = %s)", caller
,
2898 _mesa_enum_to_string(target
));
2901 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
2903 struct gl_texture_object
*texObj
;
2905 /* Use a default texture object */
2906 texObj
= ctx
->Shared
->DefaultTex
[targetIndex
];
2909 texObj
= _mesa_lookup_texture(ctx
, texture
);
2910 if (!texObj
&& ctx
->API
== API_OPENGL_CORE
) {
2911 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
2916 texObj
= ctx
->Driver
.NewTextureObject(ctx
, texture
, boundTarget
);
2918 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
2922 /* insert into hash table */
2923 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texObj
->Name
, texObj
);
2926 if (texObj
->Target
!= boundTarget
) {
2927 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s != %s)",
2928 caller
, _mesa_enum_to_string(texObj
->Target
),
2929 _mesa_enum_to_string(target
));
2938 * Common code to implement all the glTexImage1D/2D/3D functions,
2939 * glCompressedTexImage1D/2D/3D and glTextureImage1D/2D/3DEXT
2940 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2941 * \param format the user's image format (only used if !compressed)
2942 * \param type the user's image type (only used if !compressed)
2943 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2945 static ALWAYS_INLINE
void
2946 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2947 struct gl_texture_object
*texObj
,
2948 GLenum target
, GLint level
, GLint internalFormat
,
2949 GLsizei width
, GLsizei height
, GLsizei depth
,
2950 GLint border
, GLenum format
, GLenum type
,
2951 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2953 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2954 struct gl_pixelstore_attrib unpack_no_border
;
2955 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2956 mesa_format texFormat
;
2957 bool dimensionsOK
= true, sizeOK
= true;
2959 FLUSH_VERTICES(ctx
, 0);
2961 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2964 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2966 _mesa_enum_to_string(target
), level
,
2967 _mesa_enum_to_string(internalFormat
),
2968 width
, height
, depth
, border
, pixels
);
2971 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2973 _mesa_enum_to_string(target
), level
,
2974 _mesa_enum_to_string(internalFormat
),
2975 width
, height
, depth
, border
,
2976 _mesa_enum_to_string(format
),
2977 _mesa_enum_to_string(type
), pixels
);
2980 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2983 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2986 /* target error checking */
2987 if (!legal_teximage_target(ctx
, dims
, target
)) {
2988 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2989 func
, dims
, _mesa_enum_to_string(target
));
2993 /* general error checking */
2995 if (compressed_texture_error_check(ctx
, dims
, target
, texObj
,
2996 level
, internalFormat
,
2997 width
, height
, depth
,
2998 border
, imageSize
, pixels
))
3001 if (texture_error_check(ctx
, dims
, target
, texObj
, level
, internalFormat
,
3002 format
, type
, width
, height
, depth
, border
,
3009 /* Here we convert a cpal compressed image into a regular glTexImage2D
3010 * call by decompressing the texture. If we really want to support cpal
3011 * textures in any driver this would have to be changed.
3013 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3014 switch (internalFormat
) {
3015 case GL_PALETTE4_RGB8_OES
:
3016 case GL_PALETTE4_RGBA8_OES
:
3017 case GL_PALETTE4_R5_G6_B5_OES
:
3018 case GL_PALETTE4_RGBA4_OES
:
3019 case GL_PALETTE4_RGB5_A1_OES
:
3020 case GL_PALETTE8_RGB8_OES
:
3021 case GL_PALETTE8_RGBA8_OES
:
3022 case GL_PALETTE8_R5_G6_B5_OES
:
3023 case GL_PALETTE8_RGBA4_OES
:
3024 case GL_PALETTE8_RGB5_A1_OES
:
3025 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3026 width
, height
, imageSize
, pixels
);
3032 /* For glCompressedTexImage() the driver has no choice about the
3033 * texture format since we'll never transcode the user's compressed
3034 * image data. The internalFormat was error checked earlier.
3036 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3039 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3040 * internal floating point format for the given base format.
3042 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3043 if (type
== GL_FLOAT
) {
3044 texObj
->_IsFloat
= GL_TRUE
;
3045 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3046 texObj
->_IsHalfFloat
= GL_TRUE
;
3049 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
3052 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3053 internalFormat
, format
, type
);
3056 assert(texFormat
!= MESA_FORMAT_NONE
);
3059 /* check that width, height, depth are legal for the mipmap level */
3060 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3061 height
, depth
, border
);
3063 /* check that the texture won't take too much memory, etc */
3064 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3065 0, level
, texFormat
, 1,
3066 width
, height
, depth
);
3069 if (_mesa_is_proxy_texture(target
)) {
3070 /* Proxy texture: just clear or set state depending on error checking */
3071 struct gl_texture_image
*texImage
=
3072 get_proxy_tex_image(ctx
, target
, level
);
3075 return; /* GL_OUT_OF_MEMORY already recorded */
3077 if (dimensionsOK
&& sizeOK
) {
3078 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3079 border
, internalFormat
, texFormat
);
3082 clear_teximage_fields(texImage
);
3086 /* non-proxy target */
3087 const GLuint face
= _mesa_tex_target_to_face(target
);
3088 struct gl_texture_image
*texImage
;
3090 if (!dimensionsOK
) {
3091 _mesa_error(ctx
, GL_INVALID_VALUE
,
3092 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3093 func
, dims
, width
, height
, depth
);
3098 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3099 "%s%uD(image too large: %d x %d x %d, %s format)",
3100 func
, dims
, width
, height
, depth
,
3101 _mesa_enum_to_string(internalFormat
));
3105 /* Allow a hardware driver to just strip out the border, to provide
3106 * reliable but slightly incorrect hardware rendering instead of
3107 * rarely-tested software fallback rendering.
3109 if (border
&& ctx
->Const
.StripTextureBorder
) {
3110 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3113 unpack
= &unpack_no_border
;
3116 if (ctx
->NewState
& _NEW_PIXEL
)
3117 _mesa_update_state(ctx
);
3119 _mesa_lock_texture(ctx
, texObj
);
3121 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3124 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3127 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3129 _mesa_init_teximage_fields(ctx
, texImage
,
3130 width
, height
, depth
,
3131 border
, internalFormat
, texFormat
);
3133 /* Give the texture to the driver. <pixels> may be null. */
3134 if (width
> 0 && height
> 0 && depth
> 0) {
3136 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3140 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3141 type
, pixels
, unpack
);
3145 check_gen_mipmap(ctx
, target
, texObj
, level
);
3147 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3149 _mesa_dirty_texobj(ctx
, texObj
);
3152 _mesa_unlock_texture(ctx
, texObj
);
3157 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3158 * logic to be inlined without inlining the function into all the callers.
3161 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3162 GLenum target
, GLint level
, GLint internalFormat
,
3163 GLsizei width
, GLsizei height
, GLsizei depth
,
3164 GLint border
, GLenum format
, GLenum type
,
3165 GLsizei imageSize
, const GLvoid
*pixels
)
3167 teximage(ctx
, compressed
, dims
, NULL
, target
, level
, internalFormat
, width
, height
,
3168 depth
, border
, format
, type
, imageSize
, pixels
, false);
3173 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3174 GLenum target
, GLint level
, GLint internalFormat
,
3175 GLsizei width
, GLsizei height
, GLsizei depth
,
3176 GLint border
, GLenum format
, GLenum type
,
3177 GLsizei imageSize
, const GLvoid
*pixels
)
3179 teximage(ctx
, compressed
, dims
, NULL
, target
, level
, internalFormat
, width
, height
,
3180 depth
, border
, format
, type
, imageSize
, pixels
, true);
3185 * Called from the API. Note that width includes the border.
3188 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3189 GLsizei width
, GLint border
, GLenum format
,
3190 GLenum type
, const GLvoid
*pixels
)
3192 GET_CURRENT_CONTEXT(ctx
);
3193 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3194 border
, format
, type
, 0, pixels
);
3198 _mesa_TextureImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
3199 GLint internalFormat
, GLsizei width
, GLint border
,
3200 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3202 struct gl_texture_object
* texObj
;
3203 GET_CURRENT_CONTEXT(ctx
);
3205 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3206 "glTextureImage1DEXT");
3209 teximage(ctx
, GL_FALSE
, 1, texObj
, target
, level
, internalFormat
,
3210 width
, 1, 1, border
, format
, type
, 0, pixels
, false);
3214 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3215 GLsizei width
, GLsizei height
, GLint border
,
3216 GLenum format
, GLenum type
,
3217 const GLvoid
*pixels
)
3219 GET_CURRENT_CONTEXT(ctx
);
3220 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3221 border
, format
, type
, 0, pixels
);
3225 _mesa_TextureImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
3226 GLint internalFormat
, GLsizei width
, GLsizei height
,
3228 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3230 struct gl_texture_object
* texObj
;
3231 GET_CURRENT_CONTEXT(ctx
);
3233 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3234 "glTextureImage2DEXT");
3237 teximage(ctx
, GL_FALSE
, 2, texObj
, target
, level
, internalFormat
,
3238 width
, height
, 1, border
, format
, type
, 0, pixels
, false);
3242 * Called by the API or display list executor.
3243 * Note that width and height include the border.
3246 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3247 GLsizei width
, GLsizei height
, GLsizei depth
,
3248 GLint border
, GLenum format
, GLenum type
,
3249 const GLvoid
*pixels
)
3251 GET_CURRENT_CONTEXT(ctx
);
3252 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3253 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3257 _mesa_TextureImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
3258 GLint internalFormat
, GLsizei width
, GLsizei height
,
3259 GLsizei depth
, GLint border
,
3260 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3262 struct gl_texture_object
* texObj
;
3263 GET_CURRENT_CONTEXT(ctx
);
3265 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3266 "glTextureImage3DEXT");
3269 teximage(ctx
, GL_FALSE
, 3, texObj
, target
, level
, internalFormat
,
3270 width
, height
, depth
, border
, format
, type
, 0, pixels
, false);
3275 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3276 GLsizei width
, GLsizei height
, GLsizei depth
,
3277 GLint border
, GLenum format
, GLenum type
,
3278 const GLvoid
*pixels
)
3280 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3281 depth
, border
, format
, type
, pixels
);
3286 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3287 GLsizei width
, GLint border
, GLenum format
,
3288 GLenum type
, const GLvoid
*pixels
)
3290 GET_CURRENT_CONTEXT(ctx
);
3291 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3292 1, border
, format
, type
, 0, pixels
);
3297 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3298 GLsizei width
, GLsizei height
, GLint border
,
3299 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3301 GET_CURRENT_CONTEXT(ctx
);
3302 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3303 height
, 1, border
, format
, type
, 0, pixels
);
3308 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3309 GLsizei width
, GLsizei height
, GLsizei depth
,
3310 GLint border
, GLenum format
, GLenum type
,
3311 const GLvoid
*pixels
)
3313 GET_CURRENT_CONTEXT(ctx
);
3314 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3315 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3320 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3322 struct gl_texture_object
*texObj
;
3323 struct gl_texture_image
*texImage
;
3325 GET_CURRENT_CONTEXT(ctx
);
3326 FLUSH_VERTICES(ctx
, 0);
3330 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3332 case GL_TEXTURE_EXTERNAL_OES
:
3334 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3337 valid_target
= false;
3341 if (!valid_target
) {
3342 _mesa_error(ctx
, GL_INVALID_ENUM
,
3343 "glEGLImageTargetTexture2D(target=%d)", target
);
3348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3349 "glEGLImageTargetTexture2D(image=%p)", image
);
3353 if (ctx
->NewState
& _NEW_PIXEL
)
3354 _mesa_update_state(ctx
);
3356 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3360 _mesa_lock_texture(ctx
, texObj
);
3362 if (texObj
->Immutable
) {
3363 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3364 "glEGLImageTargetTexture2D(texture is immutable)");
3365 _mesa_unlock_texture(ctx
, texObj
);
3369 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3371 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3373 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3375 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3376 texObj
, texImage
, image
);
3378 _mesa_dirty_texobj(ctx
, texObj
);
3380 _mesa_unlock_texture(ctx
, texObj
);
3384 * Helper that implements the glTexSubImage1/2/3D()
3385 * and glTextureSubImage1/2/3D() functions.
3388 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3389 struct gl_texture_object
*texObj
,
3390 struct gl_texture_image
*texImage
,
3391 GLenum target
, GLint level
,
3392 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3393 GLsizei width
, GLsizei height
, GLsizei depth
,
3394 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3396 FLUSH_VERTICES(ctx
, 0);
3398 if (ctx
->NewState
& _NEW_PIXEL
)
3399 _mesa_update_state(ctx
);
3401 _mesa_lock_texture(ctx
, texObj
);
3403 if (width
> 0 && height
> 0 && depth
> 0) {
3404 /* If we have a border, offset=-1 is legal. Bias by border width. */
3407 if (target
!= GL_TEXTURE_2D_ARRAY
)
3408 zoffset
+= texImage
->Border
;
3411 if (target
!= GL_TEXTURE_1D_ARRAY
)
3412 yoffset
+= texImage
->Border
;
3415 xoffset
+= texImage
->Border
;
3418 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3419 xoffset
, yoffset
, zoffset
,
3420 width
, height
, depth
,
3421 format
, type
, pixels
, &ctx
->Unpack
);
3423 check_gen_mipmap(ctx
, target
, texObj
, level
);
3425 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3426 * the texel data, not the texture format, size, etc.
3430 _mesa_unlock_texture(ctx
, texObj
);
3434 * Implement all the glTexSubImage1/2/3D() functions.
3435 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3438 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3439 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3440 GLsizei width
, GLsizei height
, GLsizei depth
,
3441 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3442 const char *callerName
)
3444 struct gl_texture_object
*texObj
;
3445 struct gl_texture_image
*texImage
;
3447 /* check target (proxies not allowed) */
3448 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3449 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3450 dims
, _mesa_enum_to_string(target
));
3454 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3458 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3459 xoffset
, yoffset
, zoffset
,
3460 width
, height
, depth
, format
, type
,
3461 pixels
, callerName
)) {
3462 return; /* error was detected */
3465 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3466 /* texsubimage_error_check ensures that texImage is not NULL */
3468 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3469 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3471 _mesa_enum_to_string(target
), level
,
3472 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3473 _mesa_enum_to_string(format
),
3474 _mesa_enum_to_string(type
), pixels
);
3476 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3477 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3478 format
, type
, pixels
);
3483 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3484 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3485 GLsizei width
, GLsizei height
, GLsizei depth
,
3486 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3488 struct gl_texture_object
*texObj
;
3489 struct gl_texture_image
*texImage
;
3491 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3492 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3494 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3495 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3496 format
, type
, pixels
);
3501 * Implement all the glTextureSubImage1/2/3D() functions.
3502 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3504 static ALWAYS_INLINE
void
3505 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3506 GLuint texture
, GLenum target
, GLint level
,
3507 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3508 GLsizei width
, GLsizei height
, GLsizei depth
,
3509 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3510 const char *callerName
, bool no_error
, bool ext_dsa
)
3512 struct gl_texture_object
*texObj
;
3513 struct gl_texture_image
*texImage
;
3516 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3518 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3519 dims
, texture
, level
,
3520 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3521 _mesa_enum_to_string(format
),
3522 _mesa_enum_to_string(type
), pixels
);
3524 /* Get the texture object by Name. */
3527 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3529 texObj
= lookup_texture_ext_dsa(ctx
, target
, texture
, callerName
);
3534 texObj
= _mesa_lookup_texture(ctx
, texture
);
3538 /* check target (proxies not allowed) */
3539 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3540 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3541 callerName
, _mesa_enum_to_string(texObj
->Target
));
3545 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3546 xoffset
, yoffset
, zoffset
,
3547 width
, height
, depth
, format
, type
,
3548 pixels
, callerName
)) {
3549 return; /* error was detected */
3553 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3554 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3558 * What do we do if the user created a texture with the following code
3559 * and then called this function with its handle?
3562 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3563 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3564 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3565 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3566 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3567 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3568 * // wrong format, or given the wrong size, etc.
3569 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3570 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3572 * A bug has been filed against the spec for this case. In the
3573 * meantime, we will check for cube completeness.
3575 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3576 * Core Profile spec (30.10.2014):
3577 * "[A] cube map texture is cube complete if the
3578 * following conditions all hold true: The [base level] texture
3579 * images of each of the six cube map faces have identical, positive,
3580 * and square dimensions. The [base level] images were each specified
3581 * with the same internal format."
3583 * It seems reasonable to check for cube completeness of an arbitrary
3584 * level here so that the image data has a consistent format and size.
3586 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3588 "glTextureSubImage%uD(cube map incomplete)",
3593 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3595 /* Copy in each face. */
3596 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3597 texImage
= texObj
->Image
[i
][level
];
3600 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3601 level
, xoffset
, yoffset
, 0,
3602 width
, height
, 1, format
,
3604 pixels
= (GLubyte
*) pixels
+ imageStride
;
3608 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3611 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3612 level
, xoffset
, yoffset
, zoffset
,
3613 width
, height
, depth
, format
,
3620 texturesubimage_error(struct gl_context
*ctx
, GLuint dims
,
3621 GLuint texture
, GLenum target
, GLint level
,
3622 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3623 GLsizei width
, GLsizei height
, GLsizei depth
,
3624 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3625 const char *callerName
, bool ext_dsa
)
3627 texturesubimage(ctx
, dims
, texture
, target
, level
, xoffset
, yoffset
,
3628 zoffset
, width
, height
, depth
, format
, type
, pixels
,
3629 callerName
, false, ext_dsa
);
3634 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3635 GLuint texture
, GLenum target
, GLint level
,
3636 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3637 GLsizei width
, GLsizei height
, GLsizei depth
,
3638 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3639 const char *callerName
, bool ext_dsa
)
3641 texturesubimage(ctx
, dims
, texture
, target
, level
, xoffset
, yoffset
,
3642 zoffset
, width
, height
, depth
, format
, type
, pixels
,
3643 callerName
, true, ext_dsa
);
3648 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
,
3649 GLint xoffset
, GLsizei width
,
3650 GLenum format
, GLenum type
,
3651 const GLvoid
*pixels
)
3653 GET_CURRENT_CONTEXT(ctx
);
3654 texsubimage(ctx
, 1, target
, level
,
3657 format
, type
, pixels
);
3662 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3663 GLint xoffset
, GLsizei width
,
3664 GLenum format
, GLenum type
,
3665 const GLvoid
*pixels
)
3667 GET_CURRENT_CONTEXT(ctx
);
3668 texsubimage_err(ctx
, 1, target
, level
,
3671 format
, type
, pixels
, "glTexSubImage1D");
3676 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3677 GLint xoffset
, GLint yoffset
,
3678 GLsizei width
, GLsizei height
,
3679 GLenum format
, GLenum type
,
3680 const GLvoid
*pixels
)
3682 GET_CURRENT_CONTEXT(ctx
);
3683 texsubimage(ctx
, 2, target
, level
,
3684 xoffset
, yoffset
, 0,
3686 format
, type
, pixels
);
3691 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3692 GLint xoffset
, GLint yoffset
,
3693 GLsizei width
, GLsizei height
,
3694 GLenum format
, GLenum type
,
3695 const GLvoid
*pixels
)
3697 GET_CURRENT_CONTEXT(ctx
);
3698 texsubimage_err(ctx
, 2, target
, level
,
3699 xoffset
, yoffset
, 0,
3701 format
, type
, pixels
, "glTexSubImage2D");
3706 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3707 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3708 GLsizei width
, GLsizei height
, GLsizei depth
,
3709 GLenum format
, GLenum type
,
3710 const GLvoid
*pixels
)
3712 GET_CURRENT_CONTEXT(ctx
);
3713 texsubimage(ctx
, 3, target
, level
,
3714 xoffset
, yoffset
, zoffset
,
3715 width
, height
, depth
,
3716 format
, type
, pixels
);
3721 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3722 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3723 GLsizei width
, GLsizei height
, GLsizei depth
,
3724 GLenum format
, GLenum type
,
3725 const GLvoid
*pixels
)
3727 GET_CURRENT_CONTEXT(ctx
);
3728 texsubimage_err(ctx
, 3, target
, level
,
3729 xoffset
, yoffset
, zoffset
,
3730 width
, height
, depth
,
3731 format
, type
, pixels
, "glTexSubImage3D");
3736 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3737 GLsizei width
, GLenum format
, GLenum type
,
3738 const GLvoid
*pixels
)
3740 GET_CURRENT_CONTEXT(ctx
);
3741 texturesubimage_no_error(ctx
, 1, texture
, 0, level
, xoffset
, 0, 0, width
,
3742 1, 1, format
, type
, pixels
, "glTextureSubImage1D",
3748 _mesa_TextureSubImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
3749 GLint xoffset
, GLsizei width
,
3750 GLenum format
, GLenum type
,
3751 const GLvoid
*pixels
)
3753 GET_CURRENT_CONTEXT(ctx
);
3754 texturesubimage_error(ctx
, 1, texture
, target
, level
, xoffset
, 0, 0, width
, 1,
3755 1, format
, type
, pixels
, "glTextureSubImage1DEXT",
3761 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3762 GLint xoffset
, GLsizei width
,
3763 GLenum format
, GLenum type
,
3764 const GLvoid
*pixels
)
3766 GET_CURRENT_CONTEXT(ctx
);
3767 texturesubimage_error(ctx
, 1, texture
, 0, level
, xoffset
, 0, 0, width
, 1,
3768 1, format
, type
, pixels
, "glTextureSubImage1D",
3774 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3775 GLint yoffset
, GLsizei width
, GLsizei height
,
3776 GLenum format
, GLenum type
,
3777 const GLvoid
*pixels
)
3779 GET_CURRENT_CONTEXT(ctx
);
3780 texturesubimage_no_error(ctx
, 2, texture
, 0, level
, xoffset
, yoffset
, 0,
3781 width
, height
, 1, format
, type
, pixels
,
3782 "glTextureSubImage2D", false);
3787 _mesa_TextureSubImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
3788 GLint xoffset
, GLint yoffset
, GLsizei width
,
3789 GLsizei height
, GLenum format
, GLenum type
,
3790 const GLvoid
*pixels
)
3792 GET_CURRENT_CONTEXT(ctx
);
3793 texturesubimage_error(ctx
, 2, texture
, target
, level
, xoffset
, yoffset
, 0,
3794 width
, height
, 1, format
, type
, pixels
,
3795 "glTextureSubImage2DEXT", true);
3800 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3801 GLint xoffset
, GLint yoffset
,
3802 GLsizei width
, GLsizei height
,
3803 GLenum format
, GLenum type
,
3804 const GLvoid
*pixels
)
3806 GET_CURRENT_CONTEXT(ctx
);
3807 texturesubimage_error(ctx
, 2, texture
, 0, level
, xoffset
, yoffset
, 0,
3808 width
, height
, 1, format
, type
, pixels
,
3809 "glTextureSubImage2D", false);
3814 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3815 GLint yoffset
, GLint zoffset
, GLsizei width
,
3816 GLsizei height
, GLsizei depth
, GLenum format
,
3817 GLenum type
, const GLvoid
*pixels
)
3819 GET_CURRENT_CONTEXT(ctx
);
3820 texturesubimage_no_error(ctx
, 3, texture
, 0, level
, xoffset
, yoffset
,
3821 zoffset
, width
, height
, depth
, format
, type
,
3822 pixels
, "glTextureSubImage3D", false);
3826 _mesa_TextureSubImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
3827 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3828 GLsizei width
, GLsizei height
, GLsizei depth
,
3829 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3831 GET_CURRENT_CONTEXT(ctx
);
3832 texturesubimage_error(ctx
, 3, texture
, target
, level
, xoffset
, yoffset
,
3833 zoffset
, width
, height
, depth
, format
, type
,
3834 pixels
, "glTextureSubImage3DEXT", true);
3838 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3839 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3840 GLsizei width
, GLsizei height
, GLsizei depth
,
3841 GLenum format
, GLenum type
,
3842 const GLvoid
*pixels
)
3844 GET_CURRENT_CONTEXT(ctx
);
3845 texturesubimage_error(ctx
, 3, texture
, 0, level
, xoffset
, yoffset
, zoffset
,
3846 width
, height
, depth
, format
, type
, pixels
,
3847 "glTextureSubImage3D", false);
3852 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3853 * from. This depends on whether the texture contains color or depth values.
3855 static struct gl_renderbuffer
*
3856 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3858 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3859 /* reading from depth/stencil buffer */
3860 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3861 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3862 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3864 /* copying from color buffer */
3865 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3871 copytexsubimage_by_slice(struct gl_context
*ctx
,
3872 struct gl_texture_image
*texImage
,
3874 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3875 struct gl_renderbuffer
*rb
,
3877 GLsizei width
, GLsizei height
)
3879 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3882 /* For 1D arrays, we copy each scanline of the source rectangle into the
3885 assert(zoffset
== 0);
3887 for (slice
= 0; slice
< height
; slice
++) {
3888 assert(yoffset
+ slice
< texImage
->Height
);
3889 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3890 xoffset
, 0, yoffset
+ slice
,
3891 rb
, x
, y
+ slice
, width
, 1);
3894 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3895 xoffset
, yoffset
, zoffset
,
3896 rb
, x
, y
, width
, height
);
3902 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3904 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3905 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3906 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3907 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3909 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3910 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3911 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3912 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3914 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3915 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3916 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3917 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3925 * Check if the given texture format and size arguments match those
3926 * of the texture image.
3927 * \param return true if arguments match, false otherwise.
3930 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3931 GLenum internalFormat
,
3932 mesa_format texFormat
, GLsizei width
,
3933 GLsizei height
, GLint border
)
3935 if (texImage
->InternalFormat
!= internalFormat
)
3937 if (texImage
->TexFormat
!= texFormat
)
3939 if (texImage
->Border
!= border
)
3941 if (texImage
->Width2
!= width
)
3943 if (texImage
->Height2
!= height
)
3950 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3953 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3954 struct gl_texture_object
*texObj
,
3955 GLenum target
, GLint level
,
3956 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3957 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3959 struct gl_texture_image
*texImage
;
3961 _mesa_lock_texture(ctx
, texObj
);
3963 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3965 /* If we have a border, offset=-1 is legal. Bias by border width. */
3968 if (target
!= GL_TEXTURE_2D_ARRAY
)
3969 zoffset
+= texImage
->Border
;
3972 if (target
!= GL_TEXTURE_1D_ARRAY
)
3973 yoffset
+= texImage
->Border
;
3976 xoffset
+= texImage
->Border
;
3979 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3981 struct gl_renderbuffer
*srcRb
=
3982 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3984 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
3985 srcRb
, x
, y
, width
, height
);
3987 check_gen_mipmap(ctx
, target
, texObj
, level
);
3989 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3990 * the texel data, not the texture format, size, etc.
3994 _mesa_unlock_texture(ctx
, texObj
);
3999 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
4000 struct gl_texture_object
*texObj
,
4001 GLenum target
, GLint level
,
4002 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4003 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4006 FLUSH_VERTICES(ctx
, 0);
4008 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4009 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4010 _mesa_enum_to_string(target
),
4011 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4013 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4014 _mesa_update_state(ctx
);
4016 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4017 xoffset
, yoffset
, zoffset
,
4018 width
, height
, caller
)) {
4022 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
4023 zoffset
, x
, y
, width
, height
);
4028 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
4029 struct gl_texture_object
*texObj
,
4030 GLenum target
, GLint level
,
4031 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4032 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4034 FLUSH_VERTICES(ctx
, 0);
4036 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4037 _mesa_update_state(ctx
);
4039 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
4040 zoffset
, x
, y
, width
, height
);
4045 * Implement the glCopyTexImage1/2D() functions.
4047 static ALWAYS_INLINE
void
4048 copyteximage(struct gl_context
*ctx
, GLuint dims
, struct gl_texture_object
*texObj
,
4049 GLenum target
, GLint level
, GLenum internalFormat
,
4050 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
4053 struct gl_texture_image
*texImage
;
4054 mesa_format texFormat
;
4056 FLUSH_VERTICES(ctx
, 0);
4058 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4059 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4061 _mesa_enum_to_string(target
), level
,
4062 _mesa_enum_to_string(internalFormat
),
4063 x
, y
, width
, height
, border
);
4065 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4066 _mesa_update_state(ctx
);
4069 if (copytexture_error_check(ctx
, dims
, target
, texObj
, level
,
4070 internalFormat
, border
))
4073 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4075 _mesa_error(ctx
, GL_INVALID_VALUE
,
4076 "glCopyTexImage%uD(invalid width=%d or height=%d)",
4077 dims
, width
, height
);
4084 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4085 internalFormat
, GL_NONE
, GL_NONE
);
4087 /* First check if reallocating the texture buffer can be avoided.
4088 * Without the realloc the copy can be 20x faster.
4090 _mesa_lock_texture(ctx
, texObj
);
4092 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4093 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
4094 width
, height
, border
)) {
4095 _mesa_unlock_texture(ctx
, texObj
);
4097 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
4098 0, 0, x
, y
, width
, height
);
4100 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
4101 0, x
, y
, width
, height
,"CopyTexImage");
4106 _mesa_unlock_texture(ctx
, texObj
);
4107 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
4108 "can't avoid reallocating texture storage\n");
4110 if (!no_error
&& _mesa_is_gles3(ctx
)) {
4111 struct gl_renderbuffer
*rb
=
4112 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4114 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4115 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4116 * OpenGL ES 3.0. Khronos bug# 9807.
4118 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4119 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4120 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4121 " and writing to unsized internal format)", dims
);
4125 /* From Page 139 of OpenGL ES 3.0 spec:
4126 * "If internalformat is sized, the internal format of the new texel
4127 * array is internalformat, and this is also the new texel array’s
4128 * effective internal format. If the component sizes of internalformat
4129 * do not exactly match the corresponding component sizes of the source
4130 * buffer’s effective internal format, described below, an
4131 * INVALID_OPERATION error is generated. If internalformat is unsized,
4132 * the internal format of the new texel array is the effective internal
4133 * format of the source buffer, and this is also the new texel array’s
4134 * effective internal format.
4136 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4138 "glCopyTexImage%uD(component size changed in"
4139 " internal format)", dims
);
4144 assert(texFormat
!= MESA_FORMAT_NONE
);
4146 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4147 0, level
, texFormat
, 1,
4148 width
, height
, 1)) {
4149 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4150 "glCopyTexImage%uD(image too large)", dims
);
4154 if (border
&& ctx
->Const
.StripTextureBorder
) {
4156 width
-= border
* 2;
4159 height
-= border
* 2;
4164 _mesa_lock_texture(ctx
, texObj
);
4166 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4169 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4172 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4173 const GLuint face
= _mesa_tex_target_to_face(target
);
4175 /* Free old texture image */
4176 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4178 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4179 border
, internalFormat
, texFormat
);
4181 if (width
&& height
) {
4182 /* Allocate texture memory (no pixel data yet) */
4183 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4185 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4187 struct gl_renderbuffer
*srcRb
=
4188 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4190 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4192 srcRb
, srcX
, srcY
, width
, height
);
4195 check_gen_mipmap(ctx
, target
, texObj
, level
);
4198 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4200 _mesa_dirty_texobj(ctx
, texObj
);
4203 _mesa_unlock_texture(ctx
, texObj
);
4208 copyteximage_err(struct gl_context
*ctx
, GLuint dims
,
4210 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4211 GLsizei width
, GLsizei height
, GLint border
)
4213 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4214 copyteximage(ctx
, dims
, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4220 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4221 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4222 GLsizei width
, GLsizei height
, GLint border
)
4224 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4225 copyteximage(ctx
, dims
, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4231 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4232 GLenum internalFormat
,
4234 GLsizei width
, GLint border
)
4236 GET_CURRENT_CONTEXT(ctx
);
4237 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4243 _mesa_CopyTextureImage1DEXT( GLuint texture
, GLenum target
, GLint level
,
4244 GLenum internalFormat
,
4246 GLsizei width
, GLint border
)
4248 GET_CURRENT_CONTEXT(ctx
);
4249 struct gl_texture_object
* texObj
=
4250 _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4251 "glCopyTextureImage1DEXT");
4254 copyteximage(ctx
, 1, texObj
, target
, level
, internalFormat
, x
, y
, width
, 1,
4260 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4261 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4264 GET_CURRENT_CONTEXT(ctx
);
4265 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4266 x
, y
, width
, height
, border
);
4271 _mesa_CopyTextureImage2DEXT( GLuint texture
, GLenum target
, GLint level
,
4272 GLenum internalFormat
,
4274 GLsizei width
, GLsizei height
,
4277 GET_CURRENT_CONTEXT(ctx
);
4278 struct gl_texture_object
* texObj
=
4279 _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4280 "glCopyTextureImage2DEXT");
4283 copyteximage(ctx
, 2, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4289 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4290 GLint x
, GLint y
, GLsizei width
, GLint border
)
4292 GET_CURRENT_CONTEXT(ctx
);
4293 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4299 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4300 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4303 GET_CURRENT_CONTEXT(ctx
);
4304 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4305 x
, y
, width
, height
, border
);
4310 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4311 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4313 struct gl_texture_object
* texObj
;
4314 const char *self
= "glCopyTexSubImage1D";
4315 GET_CURRENT_CONTEXT(ctx
);
4317 /* Check target (proxies not allowed). Target must be checked prior to
4318 * calling _mesa_get_current_tex_object.
4320 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4321 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4322 _mesa_enum_to_string(target
));
4326 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4330 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4331 x
, y
, width
, 1, self
);
4336 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4337 GLint xoffset
, GLint yoffset
,
4338 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4340 struct gl_texture_object
* texObj
;
4341 const char *self
= "glCopyTexSubImage2D";
4342 GET_CURRENT_CONTEXT(ctx
);
4344 /* Check target (proxies not allowed). Target must be checked prior to
4345 * calling _mesa_get_current_tex_object.
4347 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4348 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4349 _mesa_enum_to_string(target
));
4353 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4357 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4358 0, x
, y
, width
, height
, self
);
4363 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4364 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4365 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4367 struct gl_texture_object
* texObj
;
4368 const char *self
= "glCopyTexSubImage3D";
4369 GET_CURRENT_CONTEXT(ctx
);
4371 /* Check target (proxies not allowed). Target must be checked prior to
4372 * calling _mesa_get_current_tex_object.
4374 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4375 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4376 _mesa_enum_to_string(target
));
4380 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4384 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4385 zoffset
, x
, y
, width
, height
, self
);
4390 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4391 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4393 struct gl_texture_object
* texObj
;
4394 const char *self
= "glCopyTextureSubImage1D";
4395 GET_CURRENT_CONTEXT(ctx
);
4397 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4401 /* Check target (proxies not allowed). */
4402 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4403 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4404 _mesa_enum_to_string(texObj
->Target
));
4408 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4409 0, x
, y
, width
, 1, self
);
4414 _mesa_CopyTextureSubImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
4415 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4417 struct gl_texture_object
* texObj
;
4418 const char *self
= "glCopyTextureSubImage1DEXT";
4419 GET_CURRENT_CONTEXT(ctx
);
4421 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4426 /* Check target (proxies not allowed). */
4427 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4428 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4429 _mesa_enum_to_string(texObj
->Target
));
4433 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4434 0, x
, y
, width
, 1, self
);
4439 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4440 GLint xoffset
, GLint yoffset
,
4441 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4443 struct gl_texture_object
* texObj
;
4444 const char *self
= "glCopyTextureSubImage2D";
4445 GET_CURRENT_CONTEXT(ctx
);
4447 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4451 /* Check target (proxies not allowed). */
4452 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4453 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4454 _mesa_enum_to_string(texObj
->Target
));
4458 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4459 yoffset
, 0, x
, y
, width
, height
, self
);
4464 _mesa_CopyTextureSubImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
4465 GLint xoffset
, GLint yoffset
,
4466 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4468 struct gl_texture_object
* texObj
;
4469 const char *self
= "glCopyTextureSubImage2DEXT";
4470 GET_CURRENT_CONTEXT(ctx
);
4472 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true, self
);
4476 /* Check target (proxies not allowed). */
4477 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4478 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4479 _mesa_enum_to_string(texObj
->Target
));
4483 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4484 yoffset
, 0, x
, y
, width
, height
, self
);
4489 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4490 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4491 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4493 struct gl_texture_object
* texObj
;
4494 const char *self
= "glCopyTextureSubImage3D";
4495 GET_CURRENT_CONTEXT(ctx
);
4497 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4501 /* Check target (proxies not allowed). */
4502 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4503 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4504 _mesa_enum_to_string(texObj
->Target
));
4508 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4509 /* Act like CopyTexSubImage2D */
4510 copy_texture_sub_image_err(ctx
, 2, texObj
,
4511 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4512 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4516 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4517 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4522 _mesa_CopyTextureSubImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
4523 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4524 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4526 struct gl_texture_object
* texObj
;
4527 const char *self
= "glCopyTextureSubImage3D";
4528 GET_CURRENT_CONTEXT(ctx
);
4530 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true, self
);
4534 /* Check target (proxies not allowed). */
4535 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4536 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4537 _mesa_enum_to_string(texObj
->Target
));
4541 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4542 /* Act like CopyTexSubImage2D */
4543 copy_texture_sub_image_err(ctx
, 2, texObj
,
4544 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4545 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4549 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4550 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4555 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4556 GLint x
, GLint y
, GLsizei width
)
4558 GET_CURRENT_CONTEXT(ctx
);
4560 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4561 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4567 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4568 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4571 GET_CURRENT_CONTEXT(ctx
);
4573 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4574 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4575 yoffset
, 0, x
, y
, width
, height
);
4580 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4581 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4582 GLsizei width
, GLsizei height
)
4584 GET_CURRENT_CONTEXT(ctx
);
4586 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4587 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4588 yoffset
, zoffset
, x
, y
, width
, height
);
4593 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4594 GLint x
, GLint y
, GLsizei width
)
4596 GET_CURRENT_CONTEXT(ctx
);
4598 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4599 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4600 xoffset
, 0, 0, x
, y
, width
, 1);
4605 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4606 GLint yoffset
, GLint x
, GLint y
,
4607 GLsizei width
, GLsizei height
)
4609 GET_CURRENT_CONTEXT(ctx
);
4611 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4612 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4613 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4618 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4619 GLint yoffset
, GLint zoffset
, GLint x
,
4620 GLint y
, GLsizei width
, GLsizei height
)
4622 GET_CURRENT_CONTEXT(ctx
);
4624 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4625 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4626 /* Act like CopyTexSubImage2D */
4627 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4628 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4629 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4633 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4634 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4640 check_clear_tex_image(struct gl_context
*ctx
,
4641 const char *function
,
4642 struct gl_texture_image
*texImage
,
4643 GLenum format
, GLenum type
,
4645 GLubyte
*clearValue
)
4647 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4648 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4649 GLenum internalFormat
= texImage
->InternalFormat
;
4652 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4653 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4654 "%s(buffer texture)", function
);
4658 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4659 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4660 "%s(compressed texture)", function
);
4664 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4665 if (err
!= GL_NO_ERROR
) {
4666 _mesa_error(ctx
, err
,
4667 "%s(incompatible format = %s, type = %s)",
4669 _mesa_enum_to_string(format
),
4670 _mesa_enum_to_string(type
));
4674 /* make sure internal format and format basically agree */
4675 if (!texture_formats_agree(internalFormat
, format
)) {
4676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4677 "%s(incompatible internalFormat = %s, format = %s)",
4679 _mesa_enum_to_string(internalFormat
),
4680 _mesa_enum_to_string(format
));
4684 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4685 /* both source and dest must be integer-valued, or neither */
4686 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4687 _mesa_is_enum_format_integer(format
)) {
4688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4689 "%s(integer/non-integer format mismatch)",
4695 if (!_mesa_texstore(ctx
,
4697 texImage
->_BaseFormat
,
4698 texImage
->TexFormat
,
4699 0, /* dstRowStride */
4701 1, 1, 1, /* srcWidth/Height/Depth */
4703 data
? data
: zeroData
,
4704 &ctx
->DefaultPacking
)) {
4705 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4713 static struct gl_texture_object
*
4714 get_tex_obj_for_clear(struct gl_context
*ctx
,
4715 const char *function
,
4718 struct gl_texture_object
*texObj
;
4720 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
4724 if (texObj
->Target
== 0) {
4725 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4734 * For clearing cube textures, the zoffset and depth parameters indicate
4735 * which cube map faces are to be cleared. This is the one case where we
4736 * need to be concerned with multiple gl_texture_images. This function
4737 * returns the array of texture images to clear for cube maps, or one
4738 * texture image otherwise.
4739 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
4742 get_tex_images_for_clear(struct gl_context
*ctx
,
4743 const char *function
,
4744 struct gl_texture_object
*texObj
,
4746 struct gl_texture_image
**texImages
)
4751 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4752 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4756 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4757 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
4758 numFaces
= MAX_FACES
;
4761 target
= texObj
->Target
;
4765 for (i
= 0; i
< numFaces
; i
++) {
4766 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
4767 if (texImages
[i
] == NULL
) {
4768 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4778 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
4779 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4780 GLsizei width
, GLsizei height
, GLsizei depth
,
4781 GLenum format
, GLenum type
, const void *data
)
4783 GET_CURRENT_CONTEXT(ctx
);
4784 struct gl_texture_object
*texObj
;
4785 struct gl_texture_image
*texImages
[MAX_FACES
];
4786 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4788 int minDepth
, maxDepth
;
4790 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4795 _mesa_lock_texture(ctx
, texObj
);
4797 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4798 texObj
, level
, texImages
);
4802 if (numImages
== 1) {
4803 minDepth
= -(int) texImages
[0]->Border
;
4804 maxDepth
= texImages
[0]->Depth
;
4806 assert(numImages
== MAX_FACES
);
4808 maxDepth
= numImages
;
4811 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4812 yoffset
< -(GLint
) texImages
[0]->Border
||
4813 zoffset
< minDepth
||
4817 xoffset
+ width
> texImages
[0]->Width
||
4818 yoffset
+ height
> texImages
[0]->Height
||
4819 zoffset
+ depth
> maxDepth
) {
4820 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4821 "glClearSubTexImage(invalid dimensions)");
4825 if (numImages
== 1) {
4826 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
4827 format
, type
, data
, clearValue
[0])) {
4828 ctx
->Driver
.ClearTexSubImage(ctx
,
4830 xoffset
, yoffset
, zoffset
,
4831 width
, height
, depth
,
4832 data
? clearValue
[0] : NULL
);
4835 /* loop over cube face images */
4836 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4837 assert(i
< MAX_FACES
);
4838 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
4839 format
, type
, data
, clearValue
[i
]))
4842 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4843 ctx
->Driver
.ClearTexSubImage(ctx
,
4845 xoffset
, yoffset
, 0,
4847 data
? clearValue
[i
] : NULL
);
4852 _mesa_unlock_texture(ctx
, texObj
);
4857 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4858 GLenum format
, GLenum type
, const void *data
)
4860 GET_CURRENT_CONTEXT(ctx
);
4861 struct gl_texture_object
*texObj
;
4862 struct gl_texture_image
*texImages
[MAX_FACES
];
4863 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4866 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4871 _mesa_lock_texture(ctx
, texObj
);
4873 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4874 texObj
, level
, texImages
);
4876 for (i
= 0; i
< numImages
; i
++) {
4877 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
4878 type
, data
, clearValue
[i
]))
4882 for (i
= 0; i
< numImages
; i
++) {
4883 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4884 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4885 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4886 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4887 texImages
[i
]->Width
,
4888 texImages
[i
]->Height
,
4889 texImages
[i
]->Depth
,
4890 data
? clearValue
[i
] : NULL
);
4894 _mesa_unlock_texture(ctx
, texObj
);
4900 /**********************************************************************/
4901 /****** Compressed Textures ******/
4902 /**********************************************************************/
4906 * Target checking for glCompressedTexSubImage[123]D().
4907 * \return GL_TRUE if error, GL_FALSE if no error
4908 * Must come before other error checking so that the texture object can
4909 * be correctly retrieved using _mesa_get_current_tex_object.
4912 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4913 GLint dims
, GLenum intFormat
, bool dsa
,
4918 enum mesa_format_layout layout
;
4920 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4921 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4922 _mesa_enum_to_string(target
));
4932 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4933 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4934 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4935 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4936 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4937 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4938 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4941 targetOK
= GL_FALSE
;
4947 case GL_TEXTURE_CUBE_MAP
:
4948 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4950 case GL_TEXTURE_2D_ARRAY
:
4951 targetOK
= _mesa_is_gles3(ctx
) ||
4952 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4954 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4955 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4960 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4962 * "An INVALID_OPERATION error is generated by
4963 * CompressedTex*SubImage3D if the internal format of the texture
4964 * is one of the EAC, ETC2, or RGTC formats and either border is
4965 * non-zero, or the effective target for the texture is not
4966 * TEXTURE_2D_ARRAY."
4968 * NOTE: that's probably a spec error. It should probably say
4969 * "... or the effective target for the texture is not
4970 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4971 * GL_TEXTURE_CUBE_MAP_ARRAY."
4972 * since those targets are 2D images and they support all compression
4975 * Instead of listing all these, just list those which are allowed,
4976 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4977 * more) are valid here, which they are not, but of course not
4978 * mentioned by core spec.
4980 * Also, from GL_KHR_texture_compression_astc_{hdr,ldr}:
4982 * "Add a second new column "3D Tex." which is empty for all non-ASTC
4983 * formats. If only the LDR profile is supported by the implementation,
4984 * this column is also empty for all ASTC formats. If both the LDR and HDR
4985 * profiles are supported, this column is checked for all ASTC formats."
4987 * "An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4988 * <format> is one of the formats in table 8.19 and <target> is not
4989 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
4991 * An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4992 * <format> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array" column of
4993 * table 8.19 is *not* checked, or if <format> is TEXTURE_3D and the "3D
4994 * Tex." column of table 8.19 is *not* checked"
4996 * And from GL_KHR_texture_compression_astc_sliced_3d:
4998 * "Modify the "3D Tex." column to be checked for all ASTC formats."
5000 format
= _mesa_glenum_to_compressed_format(intFormat
);
5001 layout
= _mesa_get_format_layout(format
);
5003 case MESA_FORMAT_LAYOUT_BPTC
:
5006 case MESA_FORMAT_LAYOUT_ASTC
:
5008 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
5009 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
5012 /* invalid format */
5013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5014 "%s(invalid target %s for format %s)", caller
,
5015 _mesa_enum_to_string(target
),
5016 _mesa_enum_to_string(intFormat
));
5021 targetOK
= GL_FALSE
;
5027 /* no 1D compressed textures at this time */
5028 targetOK
= GL_FALSE
;
5033 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
5034 _mesa_enum_to_string(target
));
5042 * Error checking for glCompressedTexSubImage[123]D().
5043 * \return GL_TRUE if error, GL_FALSE if no error
5046 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
5047 const struct gl_texture_object
*texObj
,
5048 GLenum target
, GLint level
,
5049 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5050 GLsizei width
, GLsizei height
, GLsizei depth
,
5051 GLenum format
, GLsizei imageSize
,
5052 const GLvoid
*data
, const char *callerName
)
5054 struct gl_texture_image
*texImage
;
5057 /* this will catch any invalid compressed format token */
5058 if (!_mesa_is_compressed_format(ctx
, format
)) {
5059 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
5063 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
5064 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
5068 /* validate the bound PBO, if any */
5069 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
5070 imageSize
, data
, callerName
)) {
5074 /* Check for invalid pixel storage modes */
5075 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
5076 &ctx
->Unpack
, callerName
)) {
5080 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
5081 if (expectedSize
!= imageSize
) {
5082 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
5086 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5088 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
5093 if ((GLint
) format
!= texImage
->InternalFormat
) {
5094 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
5095 callerName
, _mesa_enum_to_string(format
));
5099 if (compressedteximage_only_format(format
)) {
5100 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
5101 callerName
, _mesa_enum_to_string(format
));
5105 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
5106 depth
, callerName
)) {
5110 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
5111 zoffset
, width
, height
, depth
,
5121 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
5122 GLenum internalFormat
, GLsizei width
,
5123 GLint border
, GLsizei imageSize
,
5126 GET_CURRENT_CONTEXT(ctx
);
5127 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
5128 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5133 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
5134 GLenum internalFormat
, GLsizei width
,
5135 GLsizei height
, GLint border
, GLsizei imageSize
,
5138 GET_CURRENT_CONTEXT(ctx
);
5139 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
5140 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5145 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
5146 GLenum internalFormat
, GLsizei width
,
5147 GLsizei height
, GLsizei depth
, GLint border
,
5148 GLsizei imageSize
, const GLvoid
*data
)
5150 GET_CURRENT_CONTEXT(ctx
);
5151 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
5152 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5157 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
5158 GLenum internalFormat
, GLsizei width
,
5159 GLint border
, GLsizei imageSize
,
5162 GET_CURRENT_CONTEXT(ctx
);
5163 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
5164 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5169 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
5170 GLenum internalFormat
, GLsizei width
,
5171 GLsizei height
, GLint border
,
5172 GLsizei imageSize
, const GLvoid
*data
)
5174 GET_CURRENT_CONTEXT(ctx
);
5175 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
5176 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5181 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
5182 GLenum internalFormat
, GLsizei width
,
5183 GLsizei height
, GLsizei depth
, GLint border
,
5184 GLsizei imageSize
, const GLvoid
*data
)
5186 GET_CURRENT_CONTEXT(ctx
);
5187 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
5188 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5193 * Common helper for glCompressedTexSubImage1/2/3D() and
5194 * glCompressedTextureSubImage1/2/3D().
5197 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
5198 struct gl_texture_object
*texObj
,
5199 struct gl_texture_image
*texImage
,
5200 GLenum target
, GLint level
, GLint xoffset
,
5201 GLint yoffset
, GLint zoffset
, GLsizei width
,
5202 GLsizei height
, GLsizei depth
, GLenum format
,
5203 GLsizei imageSize
, const GLvoid
*data
)
5205 FLUSH_VERTICES(ctx
, 0);
5207 _mesa_lock_texture(ctx
, texObj
);
5209 if (width
> 0 && height
> 0 && depth
> 0) {
5210 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
5211 xoffset
, yoffset
, zoffset
,
5212 width
, height
, depth
,
5213 format
, imageSize
, data
);
5215 check_gen_mipmap(ctx
, target
, texObj
, level
);
5217 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
5218 * the texel data, not the texture format, size, etc.
5222 _mesa_unlock_texture(ctx
, texObj
);
5226 static ALWAYS_INLINE
void
5227 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint texture
,
5228 GLint level
, GLint xoffset
, GLint yoffset
,
5229 GLint zoffset
, GLsizei width
, GLsizei height
,
5230 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5231 const GLvoid
*data
, bool dsa
, bool ext_dsa
,
5232 bool no_error
, const char *caller
)
5234 struct gl_texture_object
*texObj
= NULL
;
5235 struct gl_texture_image
*texImage
;
5237 GET_CURRENT_CONTEXT(ctx
);
5241 texObj
= _mesa_lookup_texture(ctx
, texture
);
5242 target
= texObj
->Target
;
5245 texObj
= _mesa_lookup_texture_err(ctx
, texture
, caller
);
5249 target
= texObj
->Target
;
5251 texObj
= lookup_texture_ext_dsa(ctx
, target
, texture
, caller
);
5259 compressed_subtexture_target_check(ctx
, target
, dim
, format
, dsa
,
5265 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5266 if (!no_error
&& !texObj
)
5271 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
5272 xoffset
, yoffset
, zoffset
, width
,
5273 height
, depth
, format
,
5274 imageSize
, data
, caller
)) {
5278 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5279 if (dim
== 3 && dsa
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5280 const char *pixels
= data
;
5283 /* Make sure the texture object is a proper cube.
5284 * (See texturesubimage in teximage.c for details on why this check is
5287 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
5288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5289 "glCompressedTextureSubImage3D(cube map incomplete)");
5293 /* Copy in each face. */
5294 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5295 texImage
= texObj
->Image
[i
][level
];
5298 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5299 texObj
->Target
, level
, xoffset
, yoffset
,
5300 0, width
, height
, 1, format
,
5303 /* Compressed images don't have a client format */
5304 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5306 texImage
->Height
, 1);
5308 pixels
+= image_stride
;
5309 imageSize
-= image_stride
;
5312 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5315 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5316 xoffset
, yoffset
, zoffset
, width
, height
,
5317 depth
, format
, imageSize
, data
);
5322 compressed_tex_sub_image_error(unsigned dim
, GLenum target
, GLuint texture
,
5323 GLint level
, GLint xoffset
, GLint yoffset
,
5324 GLint zoffset
, GLsizei width
, GLsizei height
,
5325 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5326 const GLvoid
*data
, bool dsa
, bool ext_dsa
,
5329 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5330 zoffset
, width
, height
, depth
, format
, imageSize
,
5331 data
, dsa
, ext_dsa
, false, caller
);
5335 compressed_tex_sub_image_no_error(unsigned dim
, GLenum target
, GLuint texture
,
5336 GLint level
, GLint xoffset
, GLint yoffset
,
5337 GLint zoffset
, GLsizei width
, GLsizei height
,
5338 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5339 const GLvoid
*data
, bool dsa
, bool ext_dsa
,
5342 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5343 zoffset
, width
, height
, depth
, format
, imageSize
,
5344 data
, dsa
, ext_dsa
, true, caller
);
5348 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5349 GLint xoffset
, GLsizei width
,
5350 GLenum format
, GLsizei imageSize
,
5353 compressed_tex_sub_image_no_error(1, target
, 0, level
, xoffset
, 0, 0, width
,
5354 1, 1, format
, imageSize
, data
, false,
5355 false, "glCompressedTexSubImage1D");
5360 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5361 GLsizei width
, GLenum format
,
5362 GLsizei imageSize
, const GLvoid
*data
)
5364 compressed_tex_sub_image_error(1, target
, 0, level
, xoffset
, 0, 0, width
, 1,
5365 1, format
, imageSize
, data
, false, false,
5366 "glCompressedTexSubImage1D");
5371 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5372 GLint xoffset
, GLsizei width
,
5373 GLenum format
, GLsizei imageSize
,
5376 compressed_tex_sub_image_no_error(1, 0, texture
, level
, xoffset
, 0, 0,
5377 width
, 1, 1, format
, imageSize
, data
,
5379 "glCompressedTextureSubImage1D");
5384 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5385 GLsizei width
, GLenum format
,
5386 GLsizei imageSize
, const GLvoid
*data
)
5388 compressed_tex_sub_image_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5389 1, 1, format
, imageSize
, data
, true, false,
5390 "glCompressedTextureSubImage1D");
5395 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5396 GLint xoffset
, GLint yoffset
,
5397 GLsizei width
, GLsizei height
,
5398 GLenum format
, GLsizei imageSize
,
5401 compressed_tex_sub_image_no_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5402 width
, height
, 1, format
, imageSize
, data
,
5404 "glCompressedTexSubImage2D");
5409 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5410 GLint yoffset
, GLsizei width
, GLsizei height
,
5411 GLenum format
, GLsizei imageSize
,
5414 compressed_tex_sub_image_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5415 width
, height
, 1, format
, imageSize
, data
,
5417 "glCompressedTexSubImage2D");
5422 _mesa_CompressedTextureSubImage2DEXT(GLuint texture
, GLenum target
,
5423 GLint level
, GLint xoffset
,
5424 GLint yoffset
, GLsizei width
,
5425 GLsizei height
, GLenum format
,
5426 GLsizei imageSize
, const GLvoid
*data
)
5428 compressed_tex_sub_image_error(2, target
, texture
, level
, xoffset
, yoffset
,
5429 0, width
, height
, 1, format
, imageSize
,
5431 "glCompressedTextureSubImage2DEXT");
5436 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5437 GLint xoffset
, GLint yoffset
,
5438 GLsizei width
, GLsizei height
,
5439 GLenum format
, GLsizei imageSize
,
5442 compressed_tex_sub_image_no_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5443 width
, height
, 1, format
, imageSize
, data
,
5445 "glCompressedTextureSubImage2D");
5450 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5452 GLsizei width
, GLsizei height
,
5453 GLenum format
, GLsizei imageSize
,
5456 compressed_tex_sub_image_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5457 width
, height
, 1, format
, imageSize
, data
,
5459 "glCompressedTextureSubImage2D");
5463 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5464 GLint xoffset
, GLint yoffset
,
5465 GLint zoffset
, GLsizei width
,
5466 GLsizei height
, GLsizei depth
,
5467 GLenum format
, GLsizei imageSize
,
5470 compressed_tex_sub_image_no_error(3, target
, 0, level
, xoffset
, yoffset
,
5471 zoffset
, width
, height
, depth
, format
,
5472 imageSize
, data
, false, false,
5473 "glCompressedTexSubImage3D");
5477 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5478 GLint yoffset
, GLint zoffset
, GLsizei width
,
5479 GLsizei height
, GLsizei depth
, GLenum format
,
5480 GLsizei imageSize
, const GLvoid
*data
)
5482 compressed_tex_sub_image_error(3, target
, 0, level
, xoffset
, yoffset
,
5483 zoffset
, width
, height
, depth
, format
,
5484 imageSize
, data
, false, false,
5485 "glCompressedTexSubImage3D");
5489 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
5490 GLint xoffset
, GLint yoffset
,
5491 GLint zoffset
, GLsizei width
,
5492 GLsizei height
, GLsizei depth
,
5493 GLenum format
, GLsizei imageSize
,
5496 compressed_tex_sub_image_no_error(3, 0, texture
, level
, xoffset
, yoffset
,
5497 zoffset
, width
, height
, depth
, format
,
5498 imageSize
, data
, true, false,
5499 "glCompressedTextureSubImage3D");
5503 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5504 GLint yoffset
, GLint zoffset
, GLsizei width
,
5505 GLsizei height
, GLsizei depth
,
5506 GLenum format
, GLsizei imageSize
,
5509 compressed_tex_sub_image_error(3, 0, texture
, level
, xoffset
, yoffset
,
5510 zoffset
, width
, height
, depth
, format
,
5511 imageSize
, data
, true, false,
5512 "glCompressedTextureSubImage3D");
5516 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5518 if (ctx
->API
== API_OPENGL_COMPAT
) {
5519 switch (internalFormat
) {
5521 return MESA_FORMAT_A_UNORM8
;
5523 return MESA_FORMAT_A_UNORM16
;
5524 case GL_ALPHA16F_ARB
:
5525 return MESA_FORMAT_A_FLOAT16
;
5526 case GL_ALPHA32F_ARB
:
5527 return MESA_FORMAT_A_FLOAT32
;
5528 case GL_ALPHA8I_EXT
:
5529 return MESA_FORMAT_A_SINT8
;
5530 case GL_ALPHA16I_EXT
:
5531 return MESA_FORMAT_A_SINT16
;
5532 case GL_ALPHA32I_EXT
:
5533 return MESA_FORMAT_A_SINT32
;
5534 case GL_ALPHA8UI_EXT
:
5535 return MESA_FORMAT_A_UINT8
;
5536 case GL_ALPHA16UI_EXT
:
5537 return MESA_FORMAT_A_UINT16
;
5538 case GL_ALPHA32UI_EXT
:
5539 return MESA_FORMAT_A_UINT32
;
5541 return MESA_FORMAT_L_UNORM8
;
5542 case GL_LUMINANCE16
:
5543 return MESA_FORMAT_L_UNORM16
;
5544 case GL_LUMINANCE16F_ARB
:
5545 return MESA_FORMAT_L_FLOAT16
;
5546 case GL_LUMINANCE32F_ARB
:
5547 return MESA_FORMAT_L_FLOAT32
;
5548 case GL_LUMINANCE8I_EXT
:
5549 return MESA_FORMAT_L_SINT8
;
5550 case GL_LUMINANCE16I_EXT
:
5551 return MESA_FORMAT_L_SINT16
;
5552 case GL_LUMINANCE32I_EXT
:
5553 return MESA_FORMAT_L_SINT32
;
5554 case GL_LUMINANCE8UI_EXT
:
5555 return MESA_FORMAT_L_UINT8
;
5556 case GL_LUMINANCE16UI_EXT
:
5557 return MESA_FORMAT_L_UINT16
;
5558 case GL_LUMINANCE32UI_EXT
:
5559 return MESA_FORMAT_L_UINT32
;
5560 case GL_LUMINANCE8_ALPHA8
:
5561 return MESA_FORMAT_L8A8_UNORM
;
5562 case GL_LUMINANCE16_ALPHA16
:
5563 return MESA_FORMAT_L16A16_UNORM
;
5564 case GL_LUMINANCE_ALPHA16F_ARB
:
5565 return MESA_FORMAT_LA_FLOAT16
;
5566 case GL_LUMINANCE_ALPHA32F_ARB
:
5567 return MESA_FORMAT_LA_FLOAT32
;
5568 case GL_LUMINANCE_ALPHA8I_EXT
:
5569 return MESA_FORMAT_LA_SINT8
;
5570 case GL_LUMINANCE_ALPHA16I_EXT
:
5571 return MESA_FORMAT_LA_SINT16
;
5572 case GL_LUMINANCE_ALPHA32I_EXT
:
5573 return MESA_FORMAT_LA_SINT32
;
5574 case GL_LUMINANCE_ALPHA8UI_EXT
:
5575 return MESA_FORMAT_LA_UINT8
;
5576 case GL_LUMINANCE_ALPHA16UI_EXT
:
5577 return MESA_FORMAT_LA_UINT16
;
5578 case GL_LUMINANCE_ALPHA32UI_EXT
:
5579 return MESA_FORMAT_LA_UINT32
;
5581 return MESA_FORMAT_I_UNORM8
;
5582 case GL_INTENSITY16
:
5583 return MESA_FORMAT_I_UNORM16
;
5584 case GL_INTENSITY16F_ARB
:
5585 return MESA_FORMAT_I_FLOAT16
;
5586 case GL_INTENSITY32F_ARB
:
5587 return MESA_FORMAT_I_FLOAT32
;
5588 case GL_INTENSITY8I_EXT
:
5589 return MESA_FORMAT_I_SINT8
;
5590 case GL_INTENSITY16I_EXT
:
5591 return MESA_FORMAT_I_SINT16
;
5592 case GL_INTENSITY32I_EXT
:
5593 return MESA_FORMAT_I_SINT32
;
5594 case GL_INTENSITY8UI_EXT
:
5595 return MESA_FORMAT_I_UINT8
;
5596 case GL_INTENSITY16UI_EXT
:
5597 return MESA_FORMAT_I_UINT16
;
5598 case GL_INTENSITY32UI_EXT
:
5599 return MESA_FORMAT_I_UINT32
;
5605 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
5606 _mesa_has_OES_texture_buffer(ctx
)) {
5607 switch (internalFormat
) {
5609 return MESA_FORMAT_RGB_FLOAT32
;
5611 return MESA_FORMAT_RGB_UINT32
;
5613 return MESA_FORMAT_RGB_SINT32
;
5619 switch (internalFormat
) {
5621 return MESA_FORMAT_R8G8B8A8_UNORM
;
5623 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5624 return MESA_FORMAT_NONE
;
5625 return MESA_FORMAT_RGBA_UNORM16
;
5626 case GL_RGBA16F_ARB
:
5627 return MESA_FORMAT_RGBA_FLOAT16
;
5628 case GL_RGBA32F_ARB
:
5629 return MESA_FORMAT_RGBA_FLOAT32
;
5631 return MESA_FORMAT_RGBA_SINT8
;
5632 case GL_RGBA16I_EXT
:
5633 return MESA_FORMAT_RGBA_SINT16
;
5634 case GL_RGBA32I_EXT
:
5635 return MESA_FORMAT_RGBA_SINT32
;
5636 case GL_RGBA8UI_EXT
:
5637 return MESA_FORMAT_RGBA_UINT8
;
5638 case GL_RGBA16UI_EXT
:
5639 return MESA_FORMAT_RGBA_UINT16
;
5640 case GL_RGBA32UI_EXT
:
5641 return MESA_FORMAT_RGBA_UINT32
;
5644 return MESA_FORMAT_R8G8_UNORM
;
5646 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5647 return MESA_FORMAT_NONE
;
5648 return MESA_FORMAT_R16G16_UNORM
;
5650 return MESA_FORMAT_RG_FLOAT16
;
5652 return MESA_FORMAT_RG_FLOAT32
;
5654 return MESA_FORMAT_RG_SINT8
;
5656 return MESA_FORMAT_RG_SINT16
;
5658 return MESA_FORMAT_RG_SINT32
;
5660 return MESA_FORMAT_RG_UINT8
;
5662 return MESA_FORMAT_RG_UINT16
;
5664 return MESA_FORMAT_RG_UINT32
;
5667 return MESA_FORMAT_R_UNORM8
;
5669 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5670 return MESA_FORMAT_NONE
;
5671 return MESA_FORMAT_R_UNORM16
;
5673 return MESA_FORMAT_R_FLOAT16
;
5675 return MESA_FORMAT_R_FLOAT32
;
5677 return MESA_FORMAT_R_SINT8
;
5679 return MESA_FORMAT_R_SINT16
;
5681 return MESA_FORMAT_R_SINT32
;
5683 return MESA_FORMAT_R_UINT8
;
5685 return MESA_FORMAT_R_UINT16
;
5687 return MESA_FORMAT_R_UINT32
;
5690 return MESA_FORMAT_NONE
;
5696 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5697 GLenum internalFormat
)
5699 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
5702 if (format
== MESA_FORMAT_NONE
)
5703 return MESA_FORMAT_NONE
;
5705 datatype
= _mesa_get_format_datatype(format
);
5707 /* The GL_ARB_texture_buffer_object spec says:
5709 * "If ARB_texture_float is not supported, references to the
5710 * floating-point internal formats provided by that extension should be
5711 * removed, and such formats may not be passed to TexBufferARB."
5713 * As a result, GL_HALF_FLOAT internal format depends on both
5714 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5716 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5717 !ctx
->Extensions
.ARB_texture_float
)
5718 return MESA_FORMAT_NONE
;
5720 if (!ctx
->Extensions
.ARB_texture_rg
) {
5721 GLenum base_format
= _mesa_get_format_base_format(format
);
5722 if (base_format
== GL_R
|| base_format
== GL_RG
)
5723 return MESA_FORMAT_NONE
;
5726 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5727 GLenum base_format
= _mesa_get_format_base_format(format
);
5728 if (base_format
== GL_RGB
)
5729 return MESA_FORMAT_NONE
;
5736 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5737 * and glTextureBufferRange, including some error checking.
5740 texture_buffer_range(struct gl_context
*ctx
,
5741 struct gl_texture_object
*texObj
,
5742 GLenum internalFormat
,
5743 struct gl_buffer_object
*bufObj
,
5744 GLintptr offset
, GLsizeiptr size
,
5747 GLintptr oldOffset
= texObj
->BufferOffset
;
5748 GLsizeiptr oldSize
= texObj
->BufferSize
;
5751 /* NOTE: ARB_texture_buffer_object might not be supported in
5752 * the compatibility profile.
5754 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5755 !_mesa_has_OES_texture_buffer(ctx
)) {
5756 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5757 "%s(ARB_texture_buffer_object is not"
5758 " implemented for the compatibility profile)", caller
);
5762 if (texObj
->HandleAllocated
) {
5763 /* The ARB_bindless_texture spec says:
5765 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
5766 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
5767 * functions defined in terms of these, if the texture object to be
5768 * modified is referenced by one or more texture or image handles."
5770 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
5774 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5775 if (format
== MESA_FORMAT_NONE
) {
5776 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5777 caller
, _mesa_enum_to_string(internalFormat
));
5781 FLUSH_VERTICES(ctx
, 0);
5783 _mesa_lock_texture(ctx
, texObj
);
5785 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5786 texObj
->BufferObjectFormat
= internalFormat
;
5787 texObj
->_BufferObjectFormat
= format
;
5788 texObj
->BufferOffset
= offset
;
5789 texObj
->BufferSize
= size
;
5791 _mesa_unlock_texture(ctx
, texObj
);
5793 if (ctx
->Driver
.TexParameter
) {
5794 if (offset
!= oldOffset
) {
5795 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5797 if (size
!= oldSize
) {
5798 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5802 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5805 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5811 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5812 * Return true if it is, and return false if it is not
5813 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5814 * core spec, 02.02.2015, PDF page 245).
5817 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5820 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5821 _mesa_error(ctx
, GL_INVALID_ENUM
,
5822 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5830 * Check for errors related to the texture buffer range.
5831 * Return false if errors are found, true if none are found.
5834 check_texture_buffer_range(struct gl_context
*ctx
,
5835 struct gl_buffer_object
*bufObj
,
5836 GLintptr offset
, GLsizeiptr size
,
5839 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5840 * Textures (PDF page 245):
5841 * "An INVALID_VALUE error is generated if offset is negative, if
5842 * size is less than or equal to zero, or if offset + size is greater
5843 * than the value of BUFFER_SIZE for the buffer bound to target."
5846 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5852 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5857 if (offset
+ size
> bufObj
->Size
) {
5858 _mesa_error(ctx
, GL_INVALID_VALUE
,
5859 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5860 (int) offset
, (int) size
, (int) bufObj
->Size
);
5864 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5865 * Textures (PDF page 245):
5866 * "An INVALID_VALUE error is generated if offset is not an integer
5867 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5869 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5870 _mesa_error(ctx
, GL_INVALID_VALUE
,
5871 "%s(invalid offset alignment)", caller
);
5879 /** GL_ARB_texture_buffer_object */
5881 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5883 struct gl_texture_object
*texObj
;
5884 struct gl_buffer_object
*bufObj
;
5886 GET_CURRENT_CONTEXT(ctx
);
5888 /* Need to catch a bad target before it gets to
5889 * _mesa_get_current_tex_object.
5891 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5895 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5901 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5905 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5906 buffer
? -1 : 0, "glTexBuffer");
5910 /** GL_ARB_texture_buffer_range */
5912 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5913 GLintptr offset
, GLsizeiptr size
)
5915 struct gl_texture_object
*texObj
;
5916 struct gl_buffer_object
*bufObj
;
5918 GET_CURRENT_CONTEXT(ctx
);
5920 /* Need to catch a bad target before it gets to
5921 * _mesa_get_current_tex_object.
5923 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5927 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5931 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5932 "glTexBufferRange"))
5936 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5937 * Textures (PDF page 254):
5938 * "If buffer is zero, then any buffer object attached to the buffer
5939 * texture is detached, the values offset and size are ignored and
5940 * the state for offset and size for the buffer texture are reset to
5948 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5952 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5953 offset
, size
, "glTexBufferRange");
5957 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5959 struct gl_texture_object
*texObj
;
5960 struct gl_buffer_object
*bufObj
;
5962 GET_CURRENT_CONTEXT(ctx
);
5965 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5971 /* Get the texture object by Name. */
5972 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5976 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5979 texture_buffer_range(ctx
, texObj
, internalFormat
,
5980 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5984 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5985 GLintptr offset
, GLsizeiptr size
)
5987 struct gl_texture_object
*texObj
;
5988 struct gl_buffer_object
*bufObj
;
5990 GET_CURRENT_CONTEXT(ctx
);
5993 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5994 "glTextureBufferRange");
5998 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5999 "glTextureBufferRange"))
6003 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6004 * Textures (PDF page 254):
6005 * "If buffer is zero, then any buffer object attached to the buffer
6006 * texture is detached, the values offset and size are ignored and
6007 * the state for offset and size for the buffer texture are reset to
6015 /* Get the texture object by Name. */
6016 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
6020 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
6021 "glTextureBufferRange"))
6024 texture_buffer_range(ctx
, texObj
, internalFormat
,
6025 bufObj
, offset
, size
, "glTextureBufferRange");
6029 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
6030 GLenum internalformat
)
6032 /* Everything that is allowed for renderbuffers,
6033 * except for a base format of GL_STENCIL_INDEX, unless supported.
6035 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
6036 if (ctx
->Extensions
.ARB_texture_stencil8
)
6037 return baseFormat
!= 0;
6039 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
6043 /** GL_ARB_texture_multisample */
6045 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
6048 case GL_TEXTURE_2D_MULTISAMPLE
:
6050 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
6051 return dims
== 2 && !dsa
;
6052 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
6054 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
6055 return dims
== 3 && !dsa
;
6063 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
6064 struct gl_texture_object
*texObj
,
6065 struct gl_memory_object
*memObj
,
6066 GLenum target
, GLsizei samples
,
6067 GLint internalformat
, GLsizei width
,
6068 GLsizei height
, GLsizei depth
,
6069 GLboolean fixedsamplelocations
,
6070 GLboolean immutable
, GLuint64 offset
,
6073 struct gl_texture_image
*texImage
;
6074 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
6075 mesa_format texFormat
;
6076 GLenum sample_count_error
;
6077 bool dsa
= strstr(func
, "ture") ? true : false;
6079 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
6080 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
6081 _mesa_enum_to_string(target
), samples
);
6084 if (!((ctx
->Extensions
.ARB_texture_multisample
6085 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
6086 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
6091 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
6095 if (!check_multisample_target(dims
, target
, dsa
)) {
6096 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
6097 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
6098 _mesa_enum_to_string(target
));
6102 /* check that the specified internalformat is color/depth/stencil-renderable;
6103 * refer GL3.1 spec 4.4.4
6106 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
6107 _mesa_error(ctx
, GL_INVALID_ENUM
,
6108 "%s(internalformat=%s not legal for immutable-format)",
6109 func
, _mesa_enum_to_string(internalformat
));
6113 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
6114 /* Page 172 of OpenGL ES 3.1 spec says:
6115 * "An INVALID_ENUM error is generated if sizedinternalformat is not
6116 * color-renderable, depth-renderable, or stencil-renderable (as
6117 * defined in section 9.4).
6119 * (Same error is also defined for desktop OpenGL for multisample
6120 * teximage/texstorage functions.)
6122 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
6123 _mesa_enum_to_string(internalformat
));
6127 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
6128 internalformat
, samples
, samples
);
6129 samplesOK
= sample_count_error
== GL_NO_ERROR
;
6131 /* Page 254 of OpenGL 4.4 spec says:
6132 * "Proxy arrays for two-dimensional multisample and two-dimensional
6133 * multisample array textures are operated on in the same way when
6134 * TexImage2DMultisample is called with target specified as
6135 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
6136 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
6137 * However, if samples is not supported, then no error is generated.
6139 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
6140 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
6144 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
6145 _mesa_error(ctx
, GL_INVALID_OPERATION
,
6146 "%s(texture object 0)",
6151 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
6153 if (texImage
== NULL
) {
6154 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
6158 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
6159 internalformat
, GL_NONE
, GL_NONE
);
6160 assert(texFormat
!= MESA_FORMAT_NONE
);
6162 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
6163 width
, height
, depth
, 0);
6165 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
6166 samples
, width
, height
, depth
);
6168 if (_mesa_is_proxy_texture(target
)) {
6169 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
6170 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
6171 internalformat
, texFormat
,
6172 samples
, fixedsamplelocations
);
6175 /* clear all image fields */
6176 clear_teximage_fields(texImage
);
6180 if (!dimensionsOK
) {
6181 _mesa_error(ctx
, GL_INVALID_VALUE
,
6182 "%s(invalid width=%d or height=%d)", func
, width
, height
);
6187 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
6191 /* Check if texObj->Immutable is set */
6192 if (texObj
->Immutable
) {
6193 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
6197 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
6199 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
6200 internalformat
, texFormat
,
6201 samples
, fixedsamplelocations
);
6203 if (width
> 0 && height
> 0 && depth
> 0) {
6205 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
6210 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
6211 internalformat
, texFormat
);
6214 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
6215 width
, height
, depth
)) {
6216 /* tidy up the texture image state. strictly speaking,
6217 * we're allowed to just leave this in whatever state we
6218 * like, but being tidy is good.
6220 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
6221 internalformat
, texFormat
);
6226 texObj
->Immutable
|= immutable
;
6229 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
6232 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
6238 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
6239 GLenum internalformat
, GLsizei width
,
6240 GLsizei height
, GLboolean fixedsamplelocations
)
6242 struct gl_texture_object
*texObj
;
6243 GET_CURRENT_CONTEXT(ctx
);
6245 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6249 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6250 internalformat
, width
, height
, 1,
6251 fixedsamplelocations
, GL_FALSE
, 0,
6252 "glTexImage2DMultisample");
6257 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
6258 GLenum internalformat
, GLsizei width
,
6259 GLsizei height
, GLsizei depth
,
6260 GLboolean fixedsamplelocations
)
6262 struct gl_texture_object
*texObj
;
6263 GET_CURRENT_CONTEXT(ctx
);
6265 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6269 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6270 internalformat
, width
, height
, depth
,
6271 fixedsamplelocations
, GL_FALSE
, 0,
6272 "glTexImage3DMultisample");
6276 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
6279 GET_CURRENT_CONTEXT(ctx
);
6281 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
6282 _mesa_error(ctx
, GL_INVALID_VALUE
,
6283 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
6284 dims
, width
, height
, depth
);
6291 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
6292 GLenum internalformat
, GLsizei width
,
6293 GLsizei height
, GLboolean fixedsamplelocations
)
6295 struct gl_texture_object
*texObj
;
6296 GET_CURRENT_CONTEXT(ctx
);
6298 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6302 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6305 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6306 internalformat
, width
, height
, 1,
6307 fixedsamplelocations
, GL_TRUE
, 0,
6308 "glTexStorage2DMultisample");
6312 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
6313 GLenum internalformat
, GLsizei width
,
6314 GLsizei height
, GLsizei depth
,
6315 GLboolean fixedsamplelocations
)
6317 struct gl_texture_object
*texObj
;
6318 GET_CURRENT_CONTEXT(ctx
);
6320 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6324 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6327 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6328 internalformat
, width
, height
, depth
,
6329 fixedsamplelocations
, GL_TRUE
, 0,
6330 "glTexStorage3DMultisample");
6334 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6335 GLenum internalformat
, GLsizei width
,
6337 GLboolean fixedsamplelocations
)
6339 struct gl_texture_object
*texObj
;
6340 GET_CURRENT_CONTEXT(ctx
);
6342 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6343 "glTextureStorage2DMultisample");
6347 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6350 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
6351 samples
, internalformat
, width
, height
, 1,
6352 fixedsamplelocations
, GL_TRUE
, 0,
6353 "glTextureStorage2DMultisample");
6357 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
6358 GLenum internalformat
, GLsizei width
,
6359 GLsizei height
, GLsizei depth
,
6360 GLboolean fixedsamplelocations
)
6362 struct gl_texture_object
*texObj
;
6363 GET_CURRENT_CONTEXT(ctx
);
6365 /* Get the texture object by Name. */
6366 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6367 "glTextureStorage3DMultisample");
6371 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6374 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
6375 internalformat
, width
, height
, depth
,
6376 fixedsamplelocations
, GL_TRUE
, 0,
6377 "glTextureStorage3DMultisample");
6381 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
6382 struct gl_texture_object
*texObj
,
6383 struct gl_memory_object
*memObj
,
6384 GLenum target
, GLsizei samples
,
6385 GLenum internalFormat
, GLsizei width
,
6386 GLsizei height
, GLsizei depth
,
6387 GLboolean fixedSampleLocations
,
6388 GLuint64 offset
, const char* func
)
6392 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
6393 internalFormat
, width
, height
, depth
,
6394 fixedSampleLocations
, GL_TRUE
, offset
,