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"
41 #include "util/imports.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 if (!texture_formats_agree(texImage
->InternalFormat
, format
)) {
2209 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2210 "%s(incompatible internalFormat = %s, format = %s)",
2212 _mesa_enum_to_string(texImage
->InternalFormat
),
2213 _mesa_enum_to_string(format
));
2217 GLenum internalFormat
= _mesa_is_gles(ctx
) ?
2218 oes_float_internal_format(ctx
, texImage
->InternalFormat
, type
) :
2219 texImage
->InternalFormat
;
2221 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2222 * combinations of format, internalFormat, and type that can be used.
2223 * Formats and types that require additional extensions (e.g., GL_FLOAT
2224 * requires GL_OES_texture_float) are filtered elsewhere.
2226 if (_mesa_is_gles(ctx
) &&
2227 texture_format_error_check_gles(ctx
, format
, type
,
2228 internalFormat
, callerName
)) {
2232 /* validate the bound PBO, if any */
2233 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2234 width
, height
, depth
, format
, type
,
2235 INT_MAX
, pixels
, callerName
)) {
2239 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2240 texImage
, xoffset
, yoffset
, zoffset
,
2241 width
, height
, depth
, callerName
)) {
2245 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2246 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2248 "%s(no compression for format)", callerName
);
2253 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2254 /* both source and dest must be integer-valued, or neither */
2255 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2256 _mesa_is_enum_format_integer(format
)) {
2257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2258 "%s(integer/non-integer format mismatch)", callerName
);
2268 * Test glCopyTexImage[12]D() parameters for errors.
2270 * \param ctx GL context.
2271 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2272 * \param target texture target given by the user.
2273 * \param level image level given by the user.
2274 * \param internalFormat internal format given by the user.
2275 * \param width image width given by the user.
2276 * \param height image height given by the user.
2277 * \param border texture border.
2279 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2281 * Verifies each of the parameters against the constants specified in
2282 * __struct gl_contextRec::Const and the supported extensions, and according
2283 * to the OpenGL specification.
2286 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2287 GLenum target
, struct gl_texture_object
* texObj
,
2288 GLint level
, GLint internalFormat
, GLint border
)
2291 GLint rb_base_format
;
2292 struct gl_renderbuffer
*rb
;
2293 GLenum rb_internal_format
;
2296 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2297 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2298 dimensions
, _mesa_enum_to_string(target
));
2303 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2304 _mesa_error(ctx
, GL_INVALID_VALUE
,
2305 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2309 /* Check that the source buffer is complete */
2310 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2311 if (ctx
->ReadBuffer
->_Status
== 0) {
2312 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2314 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2315 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2316 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2320 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2321 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2322 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2328 if (border
< 0 || border
> 1 ||
2329 ((ctx
->API
!= API_OPENGL_COMPAT
||
2330 target
== GL_TEXTURE_RECTANGLE_NV
||
2331 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2332 _mesa_error(ctx
, GL_INVALID_VALUE
,
2333 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2337 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2340 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2341 switch (internalFormat
) {
2346 case GL_LUMINANCE_ALPHA
:
2349 _mesa_error(ctx
, GL_INVALID_ENUM
,
2350 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2351 _mesa_enum_to_string(internalFormat
));
2356 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2357 * OpenGL 4.5 (Compatibility Profile) spec says:
2359 * "Parameters level, internalformat, and border are specified using
2360 * the same values, with the same meanings, as the corresponding
2361 * arguments of TexImage2D, except that internalformat may not be
2362 * specified as 1, 2, 3, or 4."
2364 if (internalFormat
>= 1 && internalFormat
<= 4) {
2365 _mesa_error(ctx
, GL_INVALID_ENUM
,
2366 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2372 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2373 if (baseFormat
< 0) {
2374 _mesa_error(ctx
, GL_INVALID_ENUM
,
2375 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2376 _mesa_enum_to_string(internalFormat
));
2380 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2382 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2383 "glCopyTexImage%dD(read buffer)", dimensions
);
2387 rb_internal_format
= rb
->InternalFormat
;
2388 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2389 if (_mesa_is_color_format(internalFormat
)) {
2390 if (rb_base_format
< 0) {
2391 _mesa_error(ctx
, GL_INVALID_VALUE
,
2392 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2393 _mesa_enum_to_string(internalFormat
));
2398 if (_mesa_is_gles(ctx
)) {
2400 if (_mesa_components_in_format(baseFormat
) >
2401 _mesa_components_in_format(rb_base_format
)) {
2404 if (baseFormat
== GL_DEPTH_COMPONENT
||
2405 baseFormat
== GL_DEPTH_STENCIL
||
2406 baseFormat
== GL_STENCIL_INDEX
||
2407 rb_base_format
== GL_DEPTH_COMPONENT
||
2408 rb_base_format
== GL_DEPTH_STENCIL
||
2409 rb_base_format
== GL_STENCIL_INDEX
||
2410 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2411 baseFormat
== GL_ALPHA
) &&
2412 rb_base_format
!= GL_RGBA
) ||
2413 internalFormat
== GL_RGB9_E5
) {
2416 if (internalFormat
== GL_RGB9_E5
) {
2420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2421 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2422 _mesa_enum_to_string(internalFormat
));
2427 if (_mesa_is_gles3(ctx
)) {
2428 bool rb_is_srgb
= (ctx
->Extensions
.EXT_sRGB
&&
2429 _mesa_is_format_srgb(rb
->Format
));
2430 bool dst_is_srgb
= false;
2432 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2436 if (rb_is_srgb
!= dst_is_srgb
) {
2437 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2438 * OpenGLES 3.0.0 spec says:
2440 * "The error INVALID_OPERATION is also generated if the
2441 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2442 * framebuffer attachment corresponding to the read buffer
2443 * is LINEAR (see section 6.1.13) and internalformat is
2444 * one of the sRGB formats described in section 3.8.16, or
2445 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2446 * SRGB and internalformat is not one of the sRGB formats."
2448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2449 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2453 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2454 * types for SNORM formats. Also, conversion to SNORM formats is not
2455 * allowed by Table 3.2 on Page 110.
2457 if (!_mesa_has_EXT_render_snorm(ctx
) &&
2458 _mesa_is_enum_format_snorm(internalFormat
)) {
2459 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2460 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2461 _mesa_enum_to_string(internalFormat
));
2466 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2468 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2472 /* From the EXT_texture_integer spec:
2474 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2475 * if the texture internalformat is an integer format and the read color
2476 * buffer is not an integer format, or if the internalformat is not an
2477 * integer format and the read color buffer is an integer format."
2479 if (_mesa_is_color_format(internalFormat
)) {
2480 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2481 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2482 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2483 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2484 if (is_int
|| is_rbint
) {
2485 if (is_int
!= is_rbint
) {
2486 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2487 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2489 } else if (_mesa_is_gles(ctx
) &&
2490 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2491 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2492 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2493 "glCopyTexImage%dD(signed vs unsigned integer)",
2499 /* From page 138 of OpenGL ES 3.0 spec:
2500 * "The error INVALID_OPERATION is generated if floating-point RGBA
2501 * data is required; if signed integer RGBA data is required and the
2502 * format of the current color buffer is not signed integer; if
2503 * unsigned integer RGBA data is required and the format of the
2504 * current color buffer is not unsigned integer; or if fixed-point
2505 * RGBA data is required and the format of the current color buffer
2506 * is not fixed-point.
2508 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2513 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2515 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2516 _mesa_error(ctx
, err
,
2517 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2520 if (_mesa_format_no_online_compression(internalFormat
)) {
2521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2522 "glCopyTexImage%dD(no compression for format)", dimensions
);
2526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2527 "glCopyTexImage%dD(border!=0)", dimensions
);
2532 if (!mutable_tex_object(texObj
)) {
2533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2534 "glCopyTexImage%dD(immutable texture)", dimensions
);
2538 /* if we get here, the parameters are OK */
2544 * Test glCopyTexSubImage[12]D() parameters for errors.
2545 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2548 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2549 const struct gl_texture_object
*texObj
,
2550 GLenum target
, GLint level
,
2551 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2552 GLint width
, GLint height
, const char *caller
)
2556 struct gl_texture_image
*texImage
;
2558 /* Check that the source buffer is complete */
2559 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2560 if (ctx
->ReadBuffer
->_Status
== 0) {
2561 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2563 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2564 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2565 "%s(invalid readbuffer)", caller
);
2569 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2570 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2571 "%s(multisample FBO)", caller
);
2577 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2578 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2582 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2584 /* destination image does not exist */
2585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2586 "%s(invalid texture level %d)", caller
, level
);
2590 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2591 width
, height
, 1, caller
)) {
2595 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2596 xoffset
, yoffset
, zoffset
,
2597 width
, height
, 1, caller
)) {
2601 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2602 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2604 "%s(no compression for format)", caller
);
2609 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2610 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2614 /* From OpenGL ES 3.2 spec, section 8.6:
2616 * "An INVALID_OPERATION error is generated by CopyTexSubImage3D,
2617 * CopyTexImage2D, or CopyTexSubImage2D if the internalformat of the
2618 * texture image being (re)specified is RGB9_E5"
2620 if (texImage
->InternalFormat
== GL_RGB9_E5
&&
2621 !_mesa_is_desktop_gl(ctx
)) {
2622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2623 "%s(invalid internal format %s)", caller
,
2624 _mesa_enum_to_string(texImage
->InternalFormat
));
2628 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2629 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2630 "%s(missing readbuffer, format=%s)", caller
,
2631 _mesa_enum_to_string(texImage
->_BaseFormat
));
2635 /* From the EXT_texture_integer spec:
2637 * "INVALID_OPERATION is generated by CopyTexImage* and
2638 * CopyTexSubImage* if the texture internalformat is an integer format
2639 * and the read color buffer is not an integer format, or if the
2640 * internalformat is not an integer format and the read color buffer
2641 * is an integer format."
2643 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2644 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2646 if (_mesa_is_format_integer_color(rb
->Format
) !=
2647 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2649 "%s(integer vs non-integer)", caller
);
2654 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2655 * framebuffer/destination texture base internal format combinations),
2656 * all the entries for stencil are left blank (unsupported).
2658 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2659 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2663 /* if we get here, the parameters are OK */
2668 /** Callback info for walking over FBO hash table */
2671 struct gl_context
*ctx
;
2672 struct gl_texture_object
*texObj
;
2678 * Check render to texture callback. Called from _mesa_HashWalk().
2681 check_rtt_cb(UNUSED GLuint key
, void *data
, void *userData
)
2683 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2684 const struct cb_info
*info
= (struct cb_info
*) userData
;
2685 struct gl_context
*ctx
= info
->ctx
;
2686 const struct gl_texture_object
*texObj
= info
->texObj
;
2687 const GLuint level
= info
->level
, face
= info
->face
;
2689 /* If this is a user-created FBO */
2690 if (_mesa_is_user_fbo(fb
)) {
2692 /* check if any of the FBO's attachments point to 'texObj' */
2693 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2694 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2695 if (att
->Type
== GL_TEXTURE
&&
2696 att
->Texture
== texObj
&&
2697 att
->TextureLevel
== level
&&
2698 att
->CubeMapFace
== face
) {
2699 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2700 assert(att
->Renderbuffer
->TexImage
);
2701 /* Mark fb status as indeterminate to force re-validation */
2704 /* Make sure that the revalidation actually happens if this is
2705 * being done to currently-bound buffers.
2707 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2708 ctx
->NewState
|= _NEW_BUFFERS
;
2716 * When a texture image is specified we have to check if it's bound to
2717 * any framebuffer objects (render to texture) in order to detect changes
2718 * in size or format since that effects FBO completeness.
2719 * Any FBOs rendering into the texture must be re-validated.
2722 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2723 struct gl_texture_object
*texObj
,
2724 GLuint face
, GLuint level
)
2726 /* Only check this texture if it's been marked as RenderToTexture */
2727 if (texObj
->_RenderToTexture
) {
2728 struct cb_info info
;
2730 info
.texObj
= texObj
;
2733 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2739 * If the texture object's GenerateMipmap flag is set and we've
2740 * changed the texture base level image, regenerate the rest of the
2741 * mipmap levels now.
2744 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2745 struct gl_texture_object
*texObj
, GLint level
)
2747 if (texObj
->GenerateMipmap
&&
2748 level
== texObj
->BaseLevel
&&
2749 level
< texObj
->MaxLevel
) {
2750 assert(ctx
->Driver
.GenerateMipmap
);
2751 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2756 /** Debug helper: override the user-requested internal format */
2758 override_internal_format(GLenum internalFormat
, UNUSED GLint width
,
2759 UNUSED GLint height
)
2762 if (internalFormat
== GL_RGBA16F_ARB
||
2763 internalFormat
== GL_RGBA32F_ARB
) {
2764 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2767 else if (internalFormat
== GL_RGB16F_ARB
||
2768 internalFormat
== GL_RGB32F_ARB
) {
2769 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2772 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2773 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2774 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2775 return GL_LUMINANCE_ALPHA
;
2777 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2778 internalFormat
== GL_LUMINANCE32F_ARB
) {
2779 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2780 return GL_LUMINANCE
;
2782 else if (internalFormat
== GL_ALPHA16F_ARB
||
2783 internalFormat
== GL_ALPHA32F_ARB
) {
2784 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2788 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2789 internalFormat = GL_RGBA;
2793 return internalFormat
;
2796 return internalFormat
;
2802 * Choose the actual hardware format for a texture image.
2803 * Try to use the same format as the previous image level when possible.
2804 * Otherwise, ask the driver for the best format.
2805 * It's important to try to choose a consistant format for all levels
2806 * for efficient texture memory layout/allocation. In particular, this
2807 * comes up during automatic mipmap generation.
2810 _mesa_choose_texture_format(struct gl_context
*ctx
,
2811 struct gl_texture_object
*texObj
,
2812 GLenum target
, GLint level
,
2813 GLenum internalFormat
, GLenum format
, GLenum type
)
2817 /* see if we've already chosen a format for the previous level */
2819 struct gl_texture_image
*prevImage
=
2820 _mesa_select_tex_image(texObj
, target
, level
- 1);
2821 /* See if the prev level is defined and has an internal format which
2822 * matches the new internal format.
2825 prevImage
->Width
> 0 &&
2826 prevImage
->InternalFormat
== internalFormat
) {
2827 /* use the same format */
2828 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2829 return prevImage
->TexFormat
;
2833 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2835 assert(f
!= MESA_FORMAT_NONE
);
2841 * Adjust pixel unpack params and image dimensions to strip off the
2842 * one-pixel texture border.
2844 * Gallium and intel don't support texture borders. They've seldem been used
2845 * and seldom been implemented correctly anyway.
2847 * \param unpackNew returns the new pixel unpack parameters
2850 strip_texture_border(GLenum target
,
2851 GLint
*width
, GLint
*height
, GLint
*depth
,
2852 const struct gl_pixelstore_attrib
*unpack
,
2853 struct gl_pixelstore_attrib
*unpackNew
)
2859 *unpackNew
= *unpack
;
2861 if (unpackNew
->RowLength
== 0)
2862 unpackNew
->RowLength
= *width
;
2864 if (unpackNew
->ImageHeight
== 0)
2865 unpackNew
->ImageHeight
= *height
;
2867 assert(*width
>= 3);
2868 unpackNew
->SkipPixels
++; /* skip the border */
2869 *width
= *width
- 2; /* reduce the width by two border pixels */
2871 /* The min height of a texture with a border is 3 */
2872 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2873 unpackNew
->SkipRows
++; /* skip the border */
2874 *height
= *height
- 2; /* reduce the height by two border pixels */
2878 target
!= GL_TEXTURE_2D_ARRAY
&&
2879 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2880 unpackNew
->SkipImages
++; /* skip the border */
2881 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2885 static struct gl_texture_object
*
2886 lookup_texture_ext_dsa(struct gl_context
*ctx
, GLenum target
, GLuint texture
,
2891 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2893 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2894 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2895 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2896 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2897 boundTarget
= GL_TEXTURE_CUBE_MAP
;
2900 boundTarget
= target
;
2904 int targetIndex
= _mesa_tex_target_to_index(ctx
, boundTarget
);
2905 if (targetIndex
< 0) {
2906 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target = %s)", caller
,
2907 _mesa_enum_to_string(target
));
2910 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
2912 struct gl_texture_object
*texObj
;
2914 /* Use a default texture object */
2915 texObj
= ctx
->Shared
->DefaultTex
[targetIndex
];
2918 texObj
= _mesa_lookup_texture(ctx
, texture
);
2919 if (!texObj
&& ctx
->API
== API_OPENGL_CORE
) {
2920 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", caller
);
2925 texObj
= ctx
->Driver
.NewTextureObject(ctx
, texture
, boundTarget
);
2927 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
2931 /* insert into hash table */
2932 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texObj
->Name
, texObj
);
2935 if (texObj
->Target
!= boundTarget
) {
2936 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s != %s)",
2937 caller
, _mesa_enum_to_string(texObj
->Target
),
2938 _mesa_enum_to_string(target
));
2947 * Common code to implement all the glTexImage1D/2D/3D functions,
2948 * glCompressedTexImage1D/2D/3D and glTextureImage1D/2D/3DEXT
2949 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2950 * \param format the user's image format (only used if !compressed)
2951 * \param type the user's image type (only used if !compressed)
2952 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2954 static ALWAYS_INLINE
void
2955 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2956 struct gl_texture_object
*texObj
,
2957 GLenum target
, GLint level
, GLint internalFormat
,
2958 GLsizei width
, GLsizei height
, GLsizei depth
,
2959 GLint border
, GLenum format
, GLenum type
,
2960 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2962 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2963 struct gl_pixelstore_attrib unpack_no_border
;
2964 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2965 mesa_format texFormat
;
2966 bool dimensionsOK
= true, sizeOK
= true;
2968 FLUSH_VERTICES(ctx
, 0);
2970 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2973 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2975 _mesa_enum_to_string(target
), level
,
2976 _mesa_enum_to_string(internalFormat
),
2977 width
, height
, depth
, border
, pixels
);
2980 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2982 _mesa_enum_to_string(target
), level
,
2983 _mesa_enum_to_string(internalFormat
),
2984 width
, height
, depth
, border
,
2985 _mesa_enum_to_string(format
),
2986 _mesa_enum_to_string(type
), pixels
);
2989 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2992 /* target error checking */
2993 !legal_teximage_target(ctx
, dims
, target
)) {
2994 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2995 func
, dims
, _mesa_enum_to_string(target
));
3000 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3003 /* general error checking */
3005 if (compressed_texture_error_check(ctx
, dims
, target
, texObj
,
3006 level
, internalFormat
,
3007 width
, height
, depth
,
3008 border
, imageSize
, pixels
))
3011 if (texture_error_check(ctx
, dims
, target
, texObj
, level
, internalFormat
,
3012 format
, type
, width
, height
, depth
, border
,
3019 /* Here we convert a cpal compressed image into a regular glTexImage2D
3020 * call by decompressing the texture. If we really want to support cpal
3021 * textures in any driver this would have to be changed.
3023 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3024 switch (internalFormat
) {
3025 case GL_PALETTE4_RGB8_OES
:
3026 case GL_PALETTE4_RGBA8_OES
:
3027 case GL_PALETTE4_R5_G6_B5_OES
:
3028 case GL_PALETTE4_RGBA4_OES
:
3029 case GL_PALETTE4_RGB5_A1_OES
:
3030 case GL_PALETTE8_RGB8_OES
:
3031 case GL_PALETTE8_RGBA8_OES
:
3032 case GL_PALETTE8_R5_G6_B5_OES
:
3033 case GL_PALETTE8_RGBA4_OES
:
3034 case GL_PALETTE8_RGB5_A1_OES
:
3035 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3036 width
, height
, imageSize
, pixels
);
3042 /* For glCompressedTexImage() the driver has no choice about the
3043 * texture format since we'll never transcode the user's compressed
3044 * image data. The internalFormat was error checked earlier.
3046 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3049 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3050 * internal floating point format for the given base format.
3052 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3053 if (type
== GL_FLOAT
) {
3054 texObj
->_IsFloat
= GL_TRUE
;
3055 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3056 texObj
->_IsHalfFloat
= GL_TRUE
;
3059 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
3062 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3063 internalFormat
, format
, type
);
3066 assert(texFormat
!= MESA_FORMAT_NONE
);
3069 /* check that width, height, depth are legal for the mipmap level */
3070 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3071 height
, depth
, border
);
3073 /* check that the texture won't take too much memory, etc */
3074 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3075 0, level
, texFormat
, 1,
3076 width
, height
, depth
);
3079 if (_mesa_is_proxy_texture(target
)) {
3080 /* Proxy texture: just clear or set state depending on error checking */
3081 struct gl_texture_image
*texImage
=
3082 get_proxy_tex_image(ctx
, target
, level
);
3085 return; /* GL_OUT_OF_MEMORY already recorded */
3087 if (dimensionsOK
&& sizeOK
) {
3088 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3089 border
, internalFormat
, texFormat
);
3092 clear_teximage_fields(texImage
);
3096 /* non-proxy target */
3097 const GLuint face
= _mesa_tex_target_to_face(target
);
3098 struct gl_texture_image
*texImage
;
3100 if (!dimensionsOK
) {
3101 _mesa_error(ctx
, GL_INVALID_VALUE
,
3102 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3103 func
, dims
, width
, height
, depth
);
3108 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3109 "%s%uD(image too large: %d x %d x %d, %s format)",
3110 func
, dims
, width
, height
, depth
,
3111 _mesa_enum_to_string(internalFormat
));
3115 /* Allow a hardware driver to just strip out the border, to provide
3116 * reliable but slightly incorrect hardware rendering instead of
3117 * rarely-tested software fallback rendering.
3119 if (border
&& ctx
->Const
.StripTextureBorder
) {
3120 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3123 unpack
= &unpack_no_border
;
3126 if (ctx
->NewState
& _NEW_PIXEL
)
3127 _mesa_update_state(ctx
);
3129 _mesa_lock_texture(ctx
, texObj
);
3131 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3134 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3137 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3139 _mesa_init_teximage_fields(ctx
, texImage
,
3140 width
, height
, depth
,
3141 border
, internalFormat
, texFormat
);
3143 /* Give the texture to the driver. <pixels> may be null. */
3144 if (width
> 0 && height
> 0 && depth
> 0) {
3146 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3150 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3151 type
, pixels
, unpack
);
3155 check_gen_mipmap(ctx
, target
, texObj
, level
);
3157 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3159 _mesa_dirty_texobj(ctx
, texObj
);
3162 _mesa_unlock_texture(ctx
, texObj
);
3167 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3168 * logic to be inlined without inlining the function into all the callers.
3171 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3172 GLenum target
, GLint level
, GLint internalFormat
,
3173 GLsizei width
, GLsizei height
, GLsizei depth
,
3174 GLint border
, GLenum format
, GLenum type
,
3175 GLsizei imageSize
, const GLvoid
*pixels
)
3177 teximage(ctx
, compressed
, dims
, NULL
, target
, level
, internalFormat
, width
, height
,
3178 depth
, border
, format
, type
, imageSize
, pixels
, false);
3183 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3184 GLenum target
, GLint level
, GLint internalFormat
,
3185 GLsizei width
, GLsizei height
, GLsizei depth
,
3186 GLint border
, GLenum format
, GLenum type
,
3187 GLsizei imageSize
, const GLvoid
*pixels
)
3189 teximage(ctx
, compressed
, dims
, NULL
, target
, level
, internalFormat
, width
, height
,
3190 depth
, border
, format
, type
, imageSize
, pixels
, true);
3195 * Called from the API. Note that width includes the border.
3198 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3199 GLsizei width
, GLint border
, GLenum format
,
3200 GLenum type
, const GLvoid
*pixels
)
3202 GET_CURRENT_CONTEXT(ctx
);
3203 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3204 border
, format
, type
, 0, pixels
);
3208 _mesa_TextureImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
3209 GLint internalFormat
, GLsizei width
, GLint border
,
3210 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3212 struct gl_texture_object
* texObj
;
3213 GET_CURRENT_CONTEXT(ctx
);
3215 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3216 "glTextureImage1DEXT");
3219 teximage(ctx
, GL_FALSE
, 1, texObj
, target
, level
, internalFormat
,
3220 width
, 1, 1, border
, format
, type
, 0, pixels
, false);
3224 _mesa_MultiTexImage1DEXT(GLenum texunit
, GLenum target
, GLint level
,
3225 GLint internalFormat
, GLsizei width
, GLint border
,
3226 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3228 struct gl_texture_object
* texObj
;
3229 GET_CURRENT_CONTEXT(ctx
);
3231 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
3232 texunit
- GL_TEXTURE0
,
3234 "glMultiTexImage1DEXT");
3237 teximage(ctx
, GL_FALSE
, 1, texObj
, target
, level
, internalFormat
, width
, 1, 1,
3238 border
, format
, type
, 0, pixels
, false);
3242 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3243 GLsizei width
, GLsizei height
, GLint border
,
3244 GLenum format
, GLenum type
,
3245 const GLvoid
*pixels
)
3247 GET_CURRENT_CONTEXT(ctx
);
3248 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3249 border
, format
, type
, 0, pixels
);
3253 _mesa_TextureImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
3254 GLint internalFormat
, GLsizei width
, GLsizei height
,
3256 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3258 struct gl_texture_object
* texObj
;
3259 GET_CURRENT_CONTEXT(ctx
);
3261 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3262 "glTextureImage2DEXT");
3265 teximage(ctx
, GL_FALSE
, 2, texObj
, target
, level
, internalFormat
,
3266 width
, height
, 1, border
, format
, type
, 0, pixels
, false);
3270 _mesa_MultiTexImage2DEXT(GLenum texunit
, GLenum target
, GLint level
,
3271 GLint internalFormat
, GLsizei width
, GLsizei height
,
3273 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3275 struct gl_texture_object
* texObj
;
3276 GET_CURRENT_CONTEXT(ctx
);
3278 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
3279 texunit
- GL_TEXTURE0
,
3281 "glMultiTexImage2DEXT");
3284 teximage(ctx
, GL_FALSE
, 2, texObj
, target
, level
, internalFormat
, width
, height
, 1,
3285 border
, format
, type
, 0, pixels
, false);
3289 * Called by the API or display list executor.
3290 * Note that width and height include the border.
3293 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3294 GLsizei width
, GLsizei height
, GLsizei depth
,
3295 GLint border
, GLenum format
, GLenum type
,
3296 const GLvoid
*pixels
)
3298 GET_CURRENT_CONTEXT(ctx
);
3299 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3300 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3304 _mesa_TextureImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
3305 GLint internalFormat
, GLsizei width
, GLsizei height
,
3306 GLsizei depth
, GLint border
,
3307 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3309 struct gl_texture_object
* texObj
;
3310 GET_CURRENT_CONTEXT(ctx
);
3312 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
3313 "glTextureImage3DEXT");
3316 teximage(ctx
, GL_FALSE
, 3, texObj
, target
, level
, internalFormat
,
3317 width
, height
, depth
, border
, format
, type
, 0, pixels
, false);
3322 _mesa_MultiTexImage3DEXT(GLenum texunit
, GLenum target
, GLint level
,
3323 GLint internalFormat
, GLsizei width
, GLsizei height
,
3324 GLsizei depth
, GLint border
, GLenum format
, GLenum type
,
3325 const GLvoid
*pixels
)
3327 struct gl_texture_object
* texObj
;
3328 GET_CURRENT_CONTEXT(ctx
);
3330 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
3331 texunit
- GL_TEXTURE0
,
3333 "glMultiTexImage3DEXT");
3336 teximage(ctx
, GL_FALSE
, 3, texObj
, target
, level
, internalFormat
,
3337 width
, height
, depth
, border
, format
, type
, 0, pixels
, false);
3342 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3343 GLsizei width
, GLsizei height
, GLsizei depth
,
3344 GLint border
, GLenum format
, GLenum type
,
3345 const GLvoid
*pixels
)
3347 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3348 depth
, border
, format
, type
, pixels
);
3353 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3354 GLsizei width
, GLint border
, GLenum format
,
3355 GLenum type
, const GLvoid
*pixels
)
3357 GET_CURRENT_CONTEXT(ctx
);
3358 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3359 1, border
, format
, type
, 0, pixels
);
3364 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3365 GLsizei width
, GLsizei height
, GLint border
,
3366 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3368 GET_CURRENT_CONTEXT(ctx
);
3369 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3370 height
, 1, border
, format
, type
, 0, pixels
);
3375 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3376 GLsizei width
, GLsizei height
, GLsizei depth
,
3377 GLint border
, GLenum format
, GLenum type
,
3378 const GLvoid
*pixels
)
3380 GET_CURRENT_CONTEXT(ctx
);
3381 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3382 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3386 * Helper used by __mesa_EGLImageTargetTexture2DOES and
3387 * _mesa_EGLImageTargetTexStorageEXT.
3390 egl_image_target_texture(struct gl_context
*ctx
,
3391 struct gl_texture_object
*texObj
, GLenum target
,
3392 GLeglImageOES image
, bool tex_storage
,
3395 struct gl_texture_image
*texImage
;
3397 FLUSH_VERTICES(ctx
, 0);
3401 valid_target
= _mesa_has_OES_EGL_image(ctx
) ||
3402 (tex_storage
&& _mesa_has_EXT_EGL_image_storage(ctx
));
3404 case GL_TEXTURE_EXTERNAL_OES
:
3406 _mesa_is_gles(ctx
) ? _mesa_has_OES_EGL_image_external(ctx
) : false;
3409 valid_target
= false;
3413 if (!valid_target
) {
3414 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%d)", caller
, target
);
3419 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(image=%p)", caller
, image
);
3423 if (ctx
->NewState
& _NEW_PIXEL
)
3424 _mesa_update_state(ctx
);
3426 _mesa_lock_texture(ctx
, texObj
);
3428 if (texObj
->Immutable
) {
3429 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture is immutable)", caller
);
3430 _mesa_unlock_texture(ctx
, texObj
);
3434 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3436 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
3438 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3441 ctx
->Driver
.EGLImageTargetTexStorage(ctx
, target
, texObj
, texImage
,
3444 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
, texObj
, texImage
,
3448 _mesa_dirty_texobj(ctx
, texObj
);
3452 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
3454 _mesa_unlock_texture(ctx
, texObj
);
3458 _mesa_EGLImageTargetTexture2DOES(GLenum target
, GLeglImageOES image
)
3460 struct gl_texture_object
*texObj
;
3461 const char *func
= "glEGLImageTargetTexture2D";
3462 GET_CURRENT_CONTEXT(ctx
);
3464 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3466 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%d)", func
, target
);
3470 egl_image_target_texture(ctx
, texObj
, target
, image
, false, func
);
3474 egl_image_target_texture_storage(struct gl_context
*ctx
,
3475 struct gl_texture_object
*texObj
, GLenum target
,
3476 GLeglImageOES image
, const GLint
*attrib_list
,
3480 * EXT_EGL_image_storage:
3482 * "<attrib_list> must be NULL or a pointer to the value GL_NONE."
3484 if (attrib_list
&& attrib_list
[0] != GL_NONE
) {
3485 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(image=%p)", caller
, image
);
3491 case GL_TEXTURE_EXTERNAL_OES
:
3495 * The EXT_EGL_image_storage spec allows for many other targets besides
3496 * GL_TEXTURE_2D and GL_TEXTURE_EXTERNAL_OES, however these are complicated
3499 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported target=%d)",
3504 egl_image_target_texture(ctx
, texObj
, target
, image
, true, caller
);
3509 _mesa_EGLImageTargetTexStorageEXT(GLenum target
, GLeglImageOES image
,
3510 const GLint
*attrib_list
)
3512 struct gl_texture_object
*texObj
;
3513 const char *func
= "glEGLImageTargetTexStorageEXT";
3514 GET_CURRENT_CONTEXT(ctx
);
3516 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3518 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%d)", func
, target
);
3522 egl_image_target_texture_storage(ctx
, texObj
, target
, image
, attrib_list
,
3527 _mesa_EGLImageTargetTextureStorageEXT(GLuint texture
, GLeglImageOES image
,
3528 const GLint
*attrib_list
)
3530 struct gl_texture_object
*texObj
;
3531 const char *func
= "glEGLImageTargetTextureStorageEXT";
3532 GET_CURRENT_CONTEXT(ctx
);
3534 if (!(_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 45) &&
3535 !_mesa_has_ARB_direct_state_access(ctx
) &&
3536 !_mesa_has_EXT_direct_state_access(ctx
)) {
3537 _mesa_error(ctx
, GL_INVALID_OPERATION
, "direct access not supported");
3541 texObj
= _mesa_lookup_texture_err(ctx
, texture
, func
);
3545 egl_image_target_texture_storage(ctx
, texObj
, texObj
->Target
, image
,
3550 * Helper that implements the glTexSubImage1/2/3D()
3551 * and glTextureSubImage1/2/3D() functions.
3554 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3555 struct gl_texture_object
*texObj
,
3556 struct gl_texture_image
*texImage
,
3557 GLenum target
, GLint level
,
3558 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3559 GLsizei width
, GLsizei height
, GLsizei depth
,
3560 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3562 FLUSH_VERTICES(ctx
, 0);
3564 if (ctx
->NewState
& _NEW_PIXEL
)
3565 _mesa_update_state(ctx
);
3567 _mesa_lock_texture(ctx
, texObj
);
3569 if (width
> 0 && height
> 0 && depth
> 0) {
3570 /* If we have a border, offset=-1 is legal. Bias by border width. */
3573 if (target
!= GL_TEXTURE_2D_ARRAY
)
3574 zoffset
+= texImage
->Border
;
3577 if (target
!= GL_TEXTURE_1D_ARRAY
)
3578 yoffset
+= texImage
->Border
;
3581 xoffset
+= texImage
->Border
;
3584 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3585 xoffset
, yoffset
, zoffset
,
3586 width
, height
, depth
,
3587 format
, type
, pixels
, &ctx
->Unpack
);
3589 check_gen_mipmap(ctx
, target
, texObj
, level
);
3591 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3592 * the texel data, not the texture format, size, etc.
3596 _mesa_unlock_texture(ctx
, texObj
);
3600 * Implement all the glTexSubImage1/2/3D() functions.
3601 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3604 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3605 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3606 GLsizei width
, GLsizei height
, GLsizei depth
,
3607 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3608 const char *callerName
)
3610 struct gl_texture_object
*texObj
;
3611 struct gl_texture_image
*texImage
;
3613 /* check target (proxies not allowed) */
3614 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3615 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3616 dims
, _mesa_enum_to_string(target
));
3620 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3624 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3625 xoffset
, yoffset
, zoffset
,
3626 width
, height
, depth
, format
, type
,
3627 pixels
, callerName
)) {
3628 return; /* error was detected */
3631 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3632 /* texsubimage_error_check ensures that texImage is not NULL */
3634 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3635 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3637 _mesa_enum_to_string(target
), level
,
3638 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3639 _mesa_enum_to_string(format
),
3640 _mesa_enum_to_string(type
), pixels
);
3642 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3643 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3644 format
, type
, pixels
);
3649 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3650 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3651 GLsizei width
, GLsizei height
, GLsizei depth
,
3652 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3654 struct gl_texture_object
*texObj
;
3655 struct gl_texture_image
*texImage
;
3657 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3658 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3660 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3661 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3662 format
, type
, pixels
);
3667 * Implement all the glTextureSubImage1/2/3D() functions.
3668 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3670 static ALWAYS_INLINE
void
3671 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3672 GLuint texture
, GLenum target
, GLint level
,
3673 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3674 GLsizei width
, GLsizei height
, GLsizei depth
,
3675 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3676 const char *callerName
, bool no_error
, bool ext_dsa
)
3678 struct gl_texture_object
*texObj
;
3679 struct gl_texture_image
*texImage
;
3682 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3684 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3685 dims
, texture
, level
,
3686 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3687 _mesa_enum_to_string(format
),
3688 _mesa_enum_to_string(type
), pixels
);
3690 /* Get the texture object by Name. */
3693 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3695 texObj
= lookup_texture_ext_dsa(ctx
, target
, texture
, callerName
);
3700 texObj
= _mesa_lookup_texture(ctx
, texture
);
3704 /* check target (proxies not allowed) */
3705 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3706 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3707 callerName
, _mesa_enum_to_string(texObj
->Target
));
3711 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3712 xoffset
, yoffset
, zoffset
,
3713 width
, height
, depth
, format
, type
,
3714 pixels
, callerName
)) {
3715 return; /* error was detected */
3719 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3720 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3724 * What do we do if the user created a texture with the following code
3725 * and then called this function with its handle?
3728 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3729 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3730 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3731 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3732 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3733 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3734 * // wrong format, or given the wrong size, etc.
3735 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3736 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3738 * A bug has been filed against the spec for this case. In the
3739 * meantime, we will check for cube completeness.
3741 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3742 * Core Profile spec (30.10.2014):
3743 * "[A] cube map texture is cube complete if the
3744 * following conditions all hold true: The [base level] texture
3745 * images of each of the six cube map faces have identical, positive,
3746 * and square dimensions. The [base level] images were each specified
3747 * with the same internal format."
3749 * It seems reasonable to check for cube completeness of an arbitrary
3750 * level here so that the image data has a consistent format and size.
3752 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3753 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3754 "glTextureSubImage%uD(cube map incomplete)",
3759 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3761 /* Copy in each face. */
3762 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3763 texImage
= texObj
->Image
[i
][level
];
3766 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3767 level
, xoffset
, yoffset
, 0,
3768 width
, height
, 1, format
,
3770 pixels
= (GLubyte
*) pixels
+ imageStride
;
3774 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3777 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3778 level
, xoffset
, yoffset
, zoffset
,
3779 width
, height
, depth
, format
,
3786 texturesubimage_error(struct gl_context
*ctx
, GLuint dims
,
3787 GLuint texture
, GLenum target
, GLint level
,
3788 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3789 GLsizei width
, GLsizei height
, GLsizei depth
,
3790 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3791 const char *callerName
, bool ext_dsa
)
3793 texturesubimage(ctx
, dims
, texture
, target
, level
, xoffset
, yoffset
,
3794 zoffset
, width
, height
, depth
, format
, type
, pixels
,
3795 callerName
, false, ext_dsa
);
3800 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3801 GLuint texture
, GLenum target
, GLint level
,
3802 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3803 GLsizei width
, GLsizei height
, GLsizei depth
,
3804 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3805 const char *callerName
, bool ext_dsa
)
3807 texturesubimage(ctx
, dims
, texture
, target
, level
, xoffset
, yoffset
,
3808 zoffset
, width
, height
, depth
, format
, type
, pixels
,
3809 callerName
, true, ext_dsa
);
3814 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
,
3815 GLint xoffset
, GLsizei width
,
3816 GLenum format
, GLenum type
,
3817 const GLvoid
*pixels
)
3819 GET_CURRENT_CONTEXT(ctx
);
3820 texsubimage(ctx
, 1, target
, level
,
3823 format
, type
, pixels
);
3828 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3829 GLint xoffset
, GLsizei width
,
3830 GLenum format
, GLenum type
,
3831 const GLvoid
*pixels
)
3833 GET_CURRENT_CONTEXT(ctx
);
3834 texsubimage_err(ctx
, 1, target
, level
,
3837 format
, type
, pixels
, "glTexSubImage1D");
3842 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3843 GLint xoffset
, GLint yoffset
,
3844 GLsizei width
, GLsizei height
,
3845 GLenum format
, GLenum type
,
3846 const GLvoid
*pixels
)
3848 GET_CURRENT_CONTEXT(ctx
);
3849 texsubimage(ctx
, 2, target
, level
,
3850 xoffset
, yoffset
, 0,
3852 format
, type
, pixels
);
3857 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3858 GLint xoffset
, GLint yoffset
,
3859 GLsizei width
, GLsizei height
,
3860 GLenum format
, GLenum type
,
3861 const GLvoid
*pixels
)
3863 GET_CURRENT_CONTEXT(ctx
);
3864 texsubimage_err(ctx
, 2, target
, level
,
3865 xoffset
, yoffset
, 0,
3867 format
, type
, pixels
, "glTexSubImage2D");
3872 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3873 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3874 GLsizei width
, GLsizei height
, GLsizei depth
,
3875 GLenum format
, GLenum type
,
3876 const GLvoid
*pixels
)
3878 GET_CURRENT_CONTEXT(ctx
);
3879 texsubimage(ctx
, 3, target
, level
,
3880 xoffset
, yoffset
, zoffset
,
3881 width
, height
, depth
,
3882 format
, type
, pixels
);
3887 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3888 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3889 GLsizei width
, GLsizei height
, GLsizei depth
,
3890 GLenum format
, GLenum type
,
3891 const GLvoid
*pixels
)
3893 GET_CURRENT_CONTEXT(ctx
);
3894 texsubimage_err(ctx
, 3, target
, level
,
3895 xoffset
, yoffset
, zoffset
,
3896 width
, height
, depth
,
3897 format
, type
, pixels
, "glTexSubImage3D");
3902 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3903 GLsizei width
, GLenum format
, GLenum type
,
3904 const GLvoid
*pixels
)
3906 GET_CURRENT_CONTEXT(ctx
);
3907 texturesubimage_no_error(ctx
, 1, texture
, 0, level
, xoffset
, 0, 0, width
,
3908 1, 1, format
, type
, pixels
, "glTextureSubImage1D",
3914 _mesa_TextureSubImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
3915 GLint xoffset
, GLsizei width
,
3916 GLenum format
, GLenum type
,
3917 const GLvoid
*pixels
)
3919 GET_CURRENT_CONTEXT(ctx
);
3920 texturesubimage_error(ctx
, 1, texture
, target
, level
, xoffset
, 0, 0, width
, 1,
3921 1, format
, type
, pixels
, "glTextureSubImage1DEXT",
3927 _mesa_MultiTexSubImage1DEXT(GLenum texunit
, GLenum target
, GLint level
,
3928 GLint xoffset
, GLsizei width
,
3929 GLenum format
, GLenum type
,
3930 const GLvoid
*pixels
)
3932 GET_CURRENT_CONTEXT(ctx
);
3933 struct gl_texture_object
*texObj
;
3934 struct gl_texture_image
*texImage
;
3936 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
3937 texunit
- GL_TEXTURE0
,
3939 "glMultiTexImage1DEXT");
3940 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3942 texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
3943 xoffset
, 0, 0, width
, 1, 1,
3944 format
, type
, pixels
);
3949 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3950 GLint xoffset
, GLsizei width
,
3951 GLenum format
, GLenum type
,
3952 const GLvoid
*pixels
)
3954 GET_CURRENT_CONTEXT(ctx
);
3955 texturesubimage_error(ctx
, 1, texture
, 0, level
, xoffset
, 0, 0, width
, 1,
3956 1, format
, type
, pixels
, "glTextureSubImage1D",
3962 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3963 GLint yoffset
, GLsizei width
, GLsizei height
,
3964 GLenum format
, GLenum type
,
3965 const GLvoid
*pixels
)
3967 GET_CURRENT_CONTEXT(ctx
);
3968 texturesubimage_no_error(ctx
, 2, texture
, 0, level
, xoffset
, yoffset
, 0,
3969 width
, height
, 1, format
, type
, pixels
,
3970 "glTextureSubImage2D", false);
3975 _mesa_TextureSubImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
3976 GLint xoffset
, GLint yoffset
, GLsizei width
,
3977 GLsizei height
, GLenum format
, GLenum type
,
3978 const GLvoid
*pixels
)
3980 GET_CURRENT_CONTEXT(ctx
);
3981 texturesubimage_error(ctx
, 2, texture
, target
, level
, xoffset
, yoffset
, 0,
3982 width
, height
, 1, format
, type
, pixels
,
3983 "glTextureSubImage2DEXT", true);
3988 _mesa_MultiTexSubImage2DEXT(GLenum texunit
, GLenum target
, GLint level
,
3989 GLint xoffset
, GLint yoffset
, GLsizei width
,
3990 GLsizei height
, GLenum format
, GLenum type
,
3991 const GLvoid
*pixels
)
3993 GET_CURRENT_CONTEXT(ctx
);
3994 struct gl_texture_object
*texObj
;
3995 struct gl_texture_image
*texImage
;
3997 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
3998 texunit
- GL_TEXTURE0
,
4000 "glMultiTexImage2DEXT");
4001 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4003 texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4004 xoffset
, yoffset
, 0, width
, height
, 1,
4005 format
, type
, pixels
);
4010 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
4011 GLint xoffset
, GLint yoffset
,
4012 GLsizei width
, GLsizei height
,
4013 GLenum format
, GLenum type
,
4014 const GLvoid
*pixels
)
4016 GET_CURRENT_CONTEXT(ctx
);
4017 texturesubimage_error(ctx
, 2, texture
, 0, level
, xoffset
, yoffset
, 0,
4018 width
, height
, 1, format
, type
, pixels
,
4019 "glTextureSubImage2D", false);
4024 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4025 GLint yoffset
, GLint zoffset
, GLsizei width
,
4026 GLsizei height
, GLsizei depth
, GLenum format
,
4027 GLenum type
, const GLvoid
*pixels
)
4029 GET_CURRENT_CONTEXT(ctx
);
4030 texturesubimage_no_error(ctx
, 3, texture
, 0, level
, xoffset
, yoffset
,
4031 zoffset
, width
, height
, depth
, format
, type
,
4032 pixels
, "glTextureSubImage3D", false);
4037 _mesa_TextureSubImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
4038 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4039 GLsizei width
, GLsizei height
, GLsizei depth
,
4040 GLenum format
, GLenum type
, const GLvoid
*pixels
)
4042 GET_CURRENT_CONTEXT(ctx
);
4043 texturesubimage_error(ctx
, 3, texture
, target
, level
, xoffset
, yoffset
,
4044 zoffset
, width
, height
, depth
, format
, type
,
4045 pixels
, "glTextureSubImage3DEXT", true);
4050 _mesa_MultiTexSubImage3DEXT(GLenum texunit
, GLenum target
, GLint level
,
4051 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4052 GLsizei width
, GLsizei height
, GLsizei depth
,
4053 GLenum format
, GLenum type
, const GLvoid
*pixels
)
4055 GET_CURRENT_CONTEXT(ctx
);
4056 struct gl_texture_object
*texObj
;
4057 struct gl_texture_image
*texImage
;
4059 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4060 texunit
- GL_TEXTURE0
,
4062 "glMultiTexImage3DEXT");
4063 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4065 texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4066 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4067 format
, type
, pixels
);
4072 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
4073 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4074 GLsizei width
, GLsizei height
, GLsizei depth
,
4075 GLenum format
, GLenum type
,
4076 const GLvoid
*pixels
)
4078 GET_CURRENT_CONTEXT(ctx
);
4079 texturesubimage_error(ctx
, 3, texture
, 0, level
, xoffset
, yoffset
, zoffset
,
4080 width
, height
, depth
, format
, type
, pixels
,
4081 "glTextureSubImage3D", false);
4086 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
4087 * from. This depends on whether the texture contains color or depth values.
4089 static struct gl_renderbuffer
*
4090 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
4092 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
4093 /* reading from depth/stencil buffer */
4094 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
4095 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
4096 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
4098 /* copying from color buffer */
4099 return ctx
->ReadBuffer
->_ColorReadBuffer
;
4105 copytexsubimage_by_slice(struct gl_context
*ctx
,
4106 struct gl_texture_image
*texImage
,
4108 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4109 struct gl_renderbuffer
*rb
,
4111 GLsizei width
, GLsizei height
)
4113 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
4116 /* For 1D arrays, we copy each scanline of the source rectangle into the
4119 assert(zoffset
== 0);
4121 for (slice
= 0; slice
< height
; slice
++) {
4122 assert(yoffset
+ slice
< texImage
->Height
);
4123 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
4124 xoffset
, 0, yoffset
+ slice
,
4125 rb
, x
, y
+ slice
, width
, 1);
4128 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
4129 xoffset
, yoffset
, zoffset
,
4130 rb
, x
, y
, width
, height
);
4136 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
4138 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
4139 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
4140 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
4141 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
4143 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
4144 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
4145 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
4146 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
4148 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
4149 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
4150 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
4151 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
4159 * Check if the given texture format and size arguments match those
4160 * of the texture image.
4161 * \param return true if arguments match, false otherwise.
4164 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
4165 GLenum internalFormat
,
4166 mesa_format texFormat
, GLsizei width
,
4167 GLsizei height
, GLint border
)
4169 if (texImage
->InternalFormat
!= internalFormat
)
4171 if (texImage
->TexFormat
!= texFormat
)
4173 if (texImage
->Border
!= border
)
4175 if (texImage
->Width2
!= width
)
4177 if (texImage
->Height2
!= height
)
4184 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4187 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4188 struct gl_texture_object
*texObj
,
4189 GLenum target
, GLint level
,
4190 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4191 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4193 struct gl_texture_image
*texImage
;
4195 _mesa_lock_texture(ctx
, texObj
);
4197 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4199 /* If we have a border, offset=-1 is legal. Bias by border width. */
4202 if (target
!= GL_TEXTURE_2D_ARRAY
)
4203 zoffset
+= texImage
->Border
;
4206 if (target
!= GL_TEXTURE_1D_ARRAY
)
4207 yoffset
+= texImage
->Border
;
4210 xoffset
+= texImage
->Border
;
4213 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4215 struct gl_renderbuffer
*srcRb
=
4216 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4218 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
4219 srcRb
, x
, y
, width
, height
);
4221 check_gen_mipmap(ctx
, target
, texObj
, level
);
4223 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
4224 * the texel data, not the texture format, size, etc.
4228 _mesa_unlock_texture(ctx
, texObj
);
4233 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
4234 struct gl_texture_object
*texObj
,
4235 GLenum target
, GLint level
,
4236 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4237 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4240 FLUSH_VERTICES(ctx
, 0);
4242 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4243 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4244 _mesa_enum_to_string(target
),
4245 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4247 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4248 _mesa_update_state(ctx
);
4250 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4251 xoffset
, yoffset
, zoffset
,
4252 width
, height
, caller
)) {
4256 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
4257 zoffset
, x
, y
, width
, height
);
4262 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
4263 struct gl_texture_object
*texObj
,
4264 GLenum target
, GLint level
,
4265 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4266 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4268 FLUSH_VERTICES(ctx
, 0);
4270 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4271 _mesa_update_state(ctx
);
4273 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
4274 zoffset
, x
, y
, width
, height
);
4279 * Implement the glCopyTexImage1/2D() functions.
4281 static ALWAYS_INLINE
void
4282 copyteximage(struct gl_context
*ctx
, GLuint dims
, struct gl_texture_object
*texObj
,
4283 GLenum target
, GLint level
, GLenum internalFormat
,
4284 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
4287 struct gl_texture_image
*texImage
;
4288 mesa_format texFormat
;
4290 FLUSH_VERTICES(ctx
, 0);
4292 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4293 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4295 _mesa_enum_to_string(target
), level
,
4296 _mesa_enum_to_string(internalFormat
),
4297 x
, y
, width
, height
, border
);
4299 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4300 _mesa_update_state(ctx
);
4303 if (copytexture_error_check(ctx
, dims
, target
, texObj
, level
,
4304 internalFormat
, border
))
4307 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4309 _mesa_error(ctx
, GL_INVALID_VALUE
,
4310 "glCopyTexImage%uD(invalid width=%d or height=%d)",
4311 dims
, width
, height
);
4318 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4319 internalFormat
, GL_NONE
, GL_NONE
);
4321 /* First check if reallocating the texture buffer can be avoided.
4322 * Without the realloc the copy can be 20x faster.
4324 _mesa_lock_texture(ctx
, texObj
);
4326 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4327 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
4328 width
, height
, border
)) {
4329 _mesa_unlock_texture(ctx
, texObj
);
4331 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
4332 0, 0, x
, y
, width
, height
);
4334 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
4335 0, x
, y
, width
, height
,"CopyTexImage");
4340 _mesa_unlock_texture(ctx
, texObj
);
4341 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
4342 "can't avoid reallocating texture storage\n");
4344 if (!no_error
&& _mesa_is_gles3(ctx
)) {
4345 struct gl_renderbuffer
*rb
=
4346 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4348 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4349 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4350 * OpenGL ES 3.0. Khronos bug# 9807.
4352 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4353 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4354 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4355 " and writing to unsized internal format)", dims
);
4359 /* From Page 139 of OpenGL ES 3.0 spec:
4360 * "If internalformat is sized, the internal format of the new texel
4361 * array is internalformat, and this is also the new texel array’s
4362 * effective internal format. If the component sizes of internalformat
4363 * do not exactly match the corresponding component sizes of the source
4364 * buffer’s effective internal format, described below, an
4365 * INVALID_OPERATION error is generated. If internalformat is unsized,
4366 * the internal format of the new texel array is the effective internal
4367 * format of the source buffer, and this is also the new texel array’s
4368 * effective internal format.
4370 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4371 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4372 "glCopyTexImage%uD(component size changed in"
4373 " internal format)", dims
);
4378 assert(texFormat
!= MESA_FORMAT_NONE
);
4380 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4381 0, level
, texFormat
, 1,
4382 width
, height
, 1)) {
4383 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4384 "glCopyTexImage%uD(image too large)", dims
);
4388 if (border
&& ctx
->Const
.StripTextureBorder
) {
4390 width
-= border
* 2;
4393 height
-= border
* 2;
4398 _mesa_lock_texture(ctx
, texObj
);
4400 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4403 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4406 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4407 const GLuint face
= _mesa_tex_target_to_face(target
);
4409 /* Free old texture image */
4410 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4412 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4413 border
, internalFormat
, texFormat
);
4415 if (width
&& height
) {
4416 /* Allocate texture memory (no pixel data yet) */
4417 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4419 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4421 struct gl_renderbuffer
*srcRb
=
4422 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4424 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4426 srcRb
, srcX
, srcY
, width
, height
);
4429 check_gen_mipmap(ctx
, target
, texObj
, level
);
4432 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4434 _mesa_dirty_texobj(ctx
, texObj
);
4437 _mesa_unlock_texture(ctx
, texObj
);
4442 copyteximage_err(struct gl_context
*ctx
, GLuint dims
,
4444 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4445 GLsizei width
, GLsizei height
, GLint border
)
4447 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4448 copyteximage(ctx
, dims
, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4454 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4455 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4456 GLsizei width
, GLsizei height
, GLint border
)
4458 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4459 copyteximage(ctx
, dims
, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4465 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4466 GLenum internalFormat
,
4468 GLsizei width
, GLint border
)
4470 GET_CURRENT_CONTEXT(ctx
);
4471 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4477 _mesa_CopyTextureImage1DEXT( GLuint texture
, GLenum target
, GLint level
,
4478 GLenum internalFormat
,
4480 GLsizei width
, GLint border
)
4482 GET_CURRENT_CONTEXT(ctx
);
4483 struct gl_texture_object
* texObj
=
4484 _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4485 "glCopyTextureImage1DEXT");
4488 copyteximage(ctx
, 1, texObj
, target
, level
, internalFormat
, x
, y
, width
, 1,
4494 _mesa_CopyMultiTexImage1DEXT( GLenum texunit
, GLenum target
, GLint level
,
4495 GLenum internalFormat
,
4497 GLsizei width
, GLint border
)
4499 GET_CURRENT_CONTEXT(ctx
);
4500 struct gl_texture_object
* texObj
=
4501 _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4502 texunit
- GL_TEXTURE0
,
4504 "glCopyMultiTexImage1DEXT");
4507 copyteximage(ctx
, 1, texObj
, target
, level
, internalFormat
, x
, y
, width
, 1,
4513 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4514 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4517 GET_CURRENT_CONTEXT(ctx
);
4518 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4519 x
, y
, width
, height
, border
);
4524 _mesa_CopyTextureImage2DEXT( GLuint texture
, GLenum target
, GLint level
,
4525 GLenum internalFormat
,
4527 GLsizei width
, GLsizei height
,
4530 GET_CURRENT_CONTEXT(ctx
);
4531 struct gl_texture_object
* texObj
=
4532 _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4533 "glCopyTextureImage2DEXT");
4536 copyteximage(ctx
, 2, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4542 _mesa_CopyMultiTexImage2DEXT( GLenum texunit
, GLenum target
, GLint level
,
4543 GLenum internalFormat
,
4545 GLsizei width
, GLsizei height
, GLint border
)
4547 GET_CURRENT_CONTEXT(ctx
);
4548 struct gl_texture_object
* texObj
=
4549 _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4550 texunit
- GL_TEXTURE0
,
4552 "glCopyMultiTexImage2DEXT");
4555 copyteximage(ctx
, 2, texObj
, target
, level
, internalFormat
, x
, y
, width
, height
,
4561 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4562 GLint x
, GLint y
, GLsizei width
, GLint border
)
4564 GET_CURRENT_CONTEXT(ctx
);
4565 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4571 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4572 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4575 GET_CURRENT_CONTEXT(ctx
);
4576 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4577 x
, y
, width
, height
, border
);
4582 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4583 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4585 struct gl_texture_object
* texObj
;
4586 const char *self
= "glCopyTexSubImage1D";
4587 GET_CURRENT_CONTEXT(ctx
);
4589 /* Check target (proxies not allowed). Target must be checked prior to
4590 * calling _mesa_get_current_tex_object.
4592 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4593 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4594 _mesa_enum_to_string(target
));
4598 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4602 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4603 x
, y
, width
, 1, self
);
4608 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4609 GLint xoffset
, GLint yoffset
,
4610 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4612 struct gl_texture_object
* texObj
;
4613 const char *self
= "glCopyTexSubImage2D";
4614 GET_CURRENT_CONTEXT(ctx
);
4616 /* Check target (proxies not allowed). Target must be checked prior to
4617 * calling _mesa_get_current_tex_object.
4619 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4620 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4621 _mesa_enum_to_string(target
));
4625 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4629 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4630 0, x
, y
, width
, height
, self
);
4635 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4636 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4637 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4639 struct gl_texture_object
* texObj
;
4640 const char *self
= "glCopyTexSubImage3D";
4641 GET_CURRENT_CONTEXT(ctx
);
4643 /* Check target (proxies not allowed). Target must be checked prior to
4644 * calling _mesa_get_current_tex_object.
4646 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4647 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4648 _mesa_enum_to_string(target
));
4652 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4656 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4657 zoffset
, x
, y
, width
, height
, self
);
4662 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4663 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4665 struct gl_texture_object
* texObj
;
4666 const char *self
= "glCopyTextureSubImage1D";
4667 GET_CURRENT_CONTEXT(ctx
);
4669 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4673 /* Check target (proxies not allowed). */
4674 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4675 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4676 _mesa_enum_to_string(texObj
->Target
));
4680 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4681 0, x
, y
, width
, 1, self
);
4686 _mesa_CopyTextureSubImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
4687 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4689 struct gl_texture_object
* texObj
;
4690 const char *self
= "glCopyTextureSubImage1DEXT";
4691 GET_CURRENT_CONTEXT(ctx
);
4693 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
4698 /* Check target (proxies not allowed). */
4699 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4700 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4701 _mesa_enum_to_string(texObj
->Target
));
4705 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4706 0, x
, y
, width
, 1, self
);
4711 _mesa_CopyMultiTexSubImage1DEXT(GLenum texunit
, GLenum target
, GLint level
,
4712 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4714 struct gl_texture_object
* texObj
;
4715 const char *self
= "glCopyMultiTexSubImage1DEXT";
4716 GET_CURRENT_CONTEXT(ctx
);
4718 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4719 texunit
- GL_TEXTURE0
,
4724 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4725 0, x
, y
, width
, 1, self
);
4730 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4731 GLint xoffset
, GLint yoffset
,
4732 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4734 struct gl_texture_object
* texObj
;
4735 const char *self
= "glCopyTextureSubImage2D";
4736 GET_CURRENT_CONTEXT(ctx
);
4738 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4742 /* Check target (proxies not allowed). */
4743 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4744 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4745 _mesa_enum_to_string(texObj
->Target
));
4749 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4750 yoffset
, 0, x
, y
, width
, height
, self
);
4755 _mesa_CopyTextureSubImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
4756 GLint xoffset
, GLint yoffset
,
4757 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4759 struct gl_texture_object
* texObj
;
4760 const char *self
= "glCopyTextureSubImage2DEXT";
4761 GET_CURRENT_CONTEXT(ctx
);
4763 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true, self
);
4767 /* Check target (proxies not allowed). */
4768 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4769 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4770 _mesa_enum_to_string(texObj
->Target
));
4774 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4775 yoffset
, 0, x
, y
, width
, height
, self
);
4780 _mesa_CopyMultiTexSubImage2DEXT(GLenum texunit
, GLenum target
, GLint level
,
4781 GLint xoffset
, GLint yoffset
,
4782 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4784 struct gl_texture_object
* texObj
;
4785 const char *self
= "glCopyMultiTexSubImage2DEXT";
4786 GET_CURRENT_CONTEXT(ctx
);
4788 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4789 texunit
- GL_TEXTURE0
,
4794 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4795 yoffset
, 0, x
, y
, width
, height
, self
);
4799 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4800 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4801 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4803 struct gl_texture_object
* texObj
;
4804 const char *self
= "glCopyTextureSubImage3D";
4805 GET_CURRENT_CONTEXT(ctx
);
4807 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4811 /* Check target (proxies not allowed). */
4812 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4813 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4814 _mesa_enum_to_string(texObj
->Target
));
4818 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4819 /* Act like CopyTexSubImage2D */
4820 copy_texture_sub_image_err(ctx
, 2, texObj
,
4821 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4822 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4826 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4827 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4832 _mesa_CopyTextureSubImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
4833 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4834 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4836 struct gl_texture_object
* texObj
;
4837 const char *self
= "glCopyTextureSubImage3D";
4838 GET_CURRENT_CONTEXT(ctx
);
4840 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true, self
);
4844 /* Check target (proxies not allowed). */
4845 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4846 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4847 _mesa_enum_to_string(texObj
->Target
));
4851 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4852 /* Act like CopyTexSubImage2D */
4853 copy_texture_sub_image_err(ctx
, 2, texObj
,
4854 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4855 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4859 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4860 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4865 _mesa_CopyMultiTexSubImage3DEXT(GLenum texunit
, GLenum target
, GLint level
,
4866 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4867 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4869 struct gl_texture_object
* texObj
;
4870 const char *self
= "glCopyMultiTexSubImage3D";
4871 GET_CURRENT_CONTEXT(ctx
);
4873 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
4874 texunit
- GL_TEXTURE0
,
4879 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4880 /* Act like CopyTexSubImage2D */
4881 copy_texture_sub_image_err(ctx
, 2, texObj
,
4882 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4883 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4887 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4888 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4893 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4894 GLint x
, GLint y
, GLsizei width
)
4896 GET_CURRENT_CONTEXT(ctx
);
4898 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4899 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4905 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4906 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4909 GET_CURRENT_CONTEXT(ctx
);
4911 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4912 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4913 yoffset
, 0, x
, y
, width
, height
);
4918 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4919 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4920 GLsizei width
, GLsizei height
)
4922 GET_CURRENT_CONTEXT(ctx
);
4924 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4925 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4926 yoffset
, zoffset
, x
, y
, width
, height
);
4931 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4932 GLint x
, GLint y
, GLsizei width
)
4934 GET_CURRENT_CONTEXT(ctx
);
4936 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4937 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4938 xoffset
, 0, 0, x
, y
, width
, 1);
4943 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4944 GLint yoffset
, GLint x
, GLint y
,
4945 GLsizei width
, GLsizei height
)
4947 GET_CURRENT_CONTEXT(ctx
);
4949 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4950 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4951 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4956 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4957 GLint yoffset
, GLint zoffset
, GLint x
,
4958 GLint y
, GLsizei width
, GLsizei height
)
4960 GET_CURRENT_CONTEXT(ctx
);
4962 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4963 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4964 /* Act like CopyTexSubImage2D */
4965 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4966 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4967 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4971 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4972 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4978 check_clear_tex_image(struct gl_context
*ctx
,
4979 const char *function
,
4980 struct gl_texture_image
*texImage
,
4981 GLenum format
, GLenum type
,
4983 GLubyte
*clearValue
)
4985 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4986 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4987 GLenum internalFormat
= texImage
->InternalFormat
;
4990 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4991 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4992 "%s(buffer texture)", function
);
4996 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4998 "%s(compressed texture)", function
);
5002 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
5003 if (err
!= GL_NO_ERROR
) {
5004 _mesa_error(ctx
, err
,
5005 "%s(incompatible format = %s, type = %s)",
5007 _mesa_enum_to_string(format
),
5008 _mesa_enum_to_string(type
));
5012 /* make sure internal format and format basically agree */
5013 if (!texture_formats_agree(internalFormat
, format
)) {
5014 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5015 "%s(incompatible internalFormat = %s, format = %s)",
5017 _mesa_enum_to_string(internalFormat
),
5018 _mesa_enum_to_string(format
));
5022 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
5023 /* both source and dest must be integer-valued, or neither */
5024 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
5025 _mesa_is_enum_format_integer(format
)) {
5026 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5027 "%s(integer/non-integer format mismatch)",
5033 if (!_mesa_texstore(ctx
,
5035 texImage
->_BaseFormat
,
5036 texImage
->TexFormat
,
5037 0, /* dstRowStride */
5039 1, 1, 1, /* srcWidth/Height/Depth */
5041 data
? data
: zeroData
,
5042 &ctx
->DefaultPacking
)) {
5043 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
5051 static struct gl_texture_object
*
5052 get_tex_obj_for_clear(struct gl_context
*ctx
,
5053 const char *function
,
5056 struct gl_texture_object
*texObj
;
5058 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
5062 if (texObj
->Target
== 0) {
5063 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
5072 * For clearing cube textures, the zoffset and depth parameters indicate
5073 * which cube map faces are to be cleared. This is the one case where we
5074 * need to be concerned with multiple gl_texture_images. This function
5075 * returns the array of texture images to clear for cube maps, or one
5076 * texture image otherwise.
5077 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
5080 get_tex_images_for_clear(struct gl_context
*ctx
,
5081 const char *function
,
5082 struct gl_texture_object
*texObj
,
5084 struct gl_texture_image
**texImages
)
5089 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
5090 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
5094 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5095 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
5096 numFaces
= MAX_FACES
;
5099 target
= texObj
->Target
;
5103 for (i
= 0; i
< numFaces
; i
++) {
5104 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
5105 if (texImages
[i
] == NULL
) {
5106 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
5116 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
5117 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5118 GLsizei width
, GLsizei height
, GLsizei depth
,
5119 GLenum format
, GLenum type
, const void *data
)
5121 GET_CURRENT_CONTEXT(ctx
);
5122 struct gl_texture_object
*texObj
;
5123 struct gl_texture_image
*texImages
[MAX_FACES
];
5124 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
5126 int minDepth
, maxDepth
;
5128 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
5133 _mesa_lock_texture(ctx
, texObj
);
5135 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
5136 texObj
, level
, texImages
);
5140 if (numImages
== 1) {
5141 minDepth
= -(int) texImages
[0]->Border
;
5142 maxDepth
= texImages
[0]->Depth
;
5144 assert(numImages
== MAX_FACES
);
5146 maxDepth
= numImages
;
5149 if (xoffset
< -(GLint
) texImages
[0]->Border
||
5150 yoffset
< -(GLint
) texImages
[0]->Border
||
5151 zoffset
< minDepth
||
5155 xoffset
+ width
> texImages
[0]->Width
||
5156 yoffset
+ height
> texImages
[0]->Height
||
5157 zoffset
+ depth
> maxDepth
) {
5158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5159 "glClearSubTexImage(invalid dimensions)");
5163 if (numImages
== 1) {
5164 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
5165 format
, type
, data
, clearValue
[0])) {
5166 ctx
->Driver
.ClearTexSubImage(ctx
,
5168 xoffset
, yoffset
, zoffset
,
5169 width
, height
, depth
,
5170 data
? clearValue
[0] : NULL
);
5173 /* loop over cube face images */
5174 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
5175 assert(i
< MAX_FACES
);
5176 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
5177 format
, type
, data
, clearValue
[i
]))
5180 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
5181 ctx
->Driver
.ClearTexSubImage(ctx
,
5183 xoffset
, yoffset
, 0,
5185 data
? clearValue
[i
] : NULL
);
5190 _mesa_unlock_texture(ctx
, texObj
);
5195 _mesa_ClearTexImage( GLuint texture
, GLint level
,
5196 GLenum format
, GLenum type
, const void *data
)
5198 GET_CURRENT_CONTEXT(ctx
);
5199 struct gl_texture_object
*texObj
;
5200 struct gl_texture_image
*texImages
[MAX_FACES
];
5201 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
5204 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
5209 _mesa_lock_texture(ctx
, texObj
);
5211 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
5212 texObj
, level
, texImages
);
5214 for (i
= 0; i
< numImages
; i
++) {
5215 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
5216 type
, data
, clearValue
[i
]))
5220 for (i
= 0; i
< numImages
; i
++) {
5221 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
5222 -(GLint
) texImages
[i
]->Border
, /* xoffset */
5223 -(GLint
) texImages
[i
]->Border
, /* yoffset */
5224 -(GLint
) texImages
[i
]->Border
, /* zoffset */
5225 texImages
[i
]->Width
,
5226 texImages
[i
]->Height
,
5227 texImages
[i
]->Depth
,
5228 data
? clearValue
[i
] : NULL
);
5232 _mesa_unlock_texture(ctx
, texObj
);
5238 /**********************************************************************/
5239 /****** Compressed Textures ******/
5240 /**********************************************************************/
5244 * Target checking for glCompressedTexSubImage[123]D().
5245 * \return GL_TRUE if error, GL_FALSE if no error
5246 * Must come before other error checking so that the texture object can
5247 * be correctly retrieved using _mesa_get_current_tex_object.
5250 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
5251 GLint dims
, GLenum intFormat
, bool dsa
,
5256 enum mesa_format_layout layout
;
5258 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
5259 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
5260 _mesa_enum_to_string(target
));
5270 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
5271 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
5272 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
5273 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
5274 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
5275 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
5276 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
5279 targetOK
= GL_FALSE
;
5285 case GL_TEXTURE_CUBE_MAP
:
5286 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
5288 case GL_TEXTURE_2D_ARRAY
:
5289 targetOK
= _mesa_is_gles3(ctx
) ||
5290 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
5292 case GL_TEXTURE_CUBE_MAP_ARRAY
:
5293 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
5298 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
5300 * "An INVALID_OPERATION error is generated by
5301 * CompressedTex*SubImage3D if the internal format of the texture
5302 * is one of the EAC, ETC2, or RGTC formats and either border is
5303 * non-zero, or the effective target for the texture is not
5304 * TEXTURE_2D_ARRAY."
5306 * NOTE: that's probably a spec error. It should probably say
5307 * "... or the effective target for the texture is not
5308 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
5309 * GL_TEXTURE_CUBE_MAP_ARRAY."
5310 * since those targets are 2D images and they support all compression
5313 * Instead of listing all these, just list those which are allowed,
5314 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
5315 * more) are valid here, which they are not, but of course not
5316 * mentioned by core spec.
5318 * Also, from GL_KHR_texture_compression_astc_{hdr,ldr}:
5320 * "Add a second new column "3D Tex." which is empty for all non-ASTC
5321 * formats. If only the LDR profile is supported by the implementation,
5322 * this column is also empty for all ASTC formats. If both the LDR and HDR
5323 * profiles are supported, this column is checked for all ASTC formats."
5325 * "An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
5326 * <format> is one of the formats in table 8.19 and <target> is not
5327 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
5329 * An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
5330 * <format> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array" column of
5331 * table 8.19 is *not* checked, or if <format> is TEXTURE_3D and the "3D
5332 * Tex." column of table 8.19 is *not* checked"
5334 * And from GL_KHR_texture_compression_astc_sliced_3d:
5336 * "Modify the "3D Tex." column to be checked for all ASTC formats."
5338 format
= _mesa_glenum_to_compressed_format(intFormat
);
5339 layout
= _mesa_get_format_layout(format
);
5341 case MESA_FORMAT_LAYOUT_BPTC
:
5344 case MESA_FORMAT_LAYOUT_ASTC
:
5346 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
5347 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
5350 /* invalid format */
5351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5352 "%s(invalid target %s for format %s)", caller
,
5353 _mesa_enum_to_string(target
),
5354 _mesa_enum_to_string(intFormat
));
5359 targetOK
= GL_FALSE
;
5365 /* no 1D compressed textures at this time */
5366 targetOK
= GL_FALSE
;
5371 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
5372 _mesa_enum_to_string(target
));
5380 * Error checking for glCompressedTexSubImage[123]D().
5381 * \return GL_TRUE if error, GL_FALSE if no error
5384 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
5385 const struct gl_texture_object
*texObj
,
5386 GLenum target
, GLint level
,
5387 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5388 GLsizei width
, GLsizei height
, GLsizei depth
,
5389 GLenum format
, GLsizei imageSize
,
5390 const GLvoid
*data
, const char *callerName
)
5392 struct gl_texture_image
*texImage
;
5395 /* this will catch any invalid compressed format token */
5396 if (!_mesa_is_compressed_format(ctx
, format
)) {
5397 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
5401 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
5402 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
5406 /* validate the bound PBO, if any */
5407 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
5408 imageSize
, data
, callerName
)) {
5412 /* Check for invalid pixel storage modes */
5413 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
5414 &ctx
->Unpack
, callerName
)) {
5418 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
5419 if (expectedSize
!= imageSize
) {
5420 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
5424 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5426 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
5431 if ((GLint
) format
!= texImage
->InternalFormat
) {
5432 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
5433 callerName
, _mesa_enum_to_string(format
));
5437 if (compressedteximage_only_format(format
)) {
5438 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
5439 callerName
, _mesa_enum_to_string(format
));
5443 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
5444 depth
, callerName
)) {
5448 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
5449 zoffset
, width
, height
, depth
,
5459 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
5460 GLenum internalFormat
, GLsizei width
,
5461 GLint border
, GLsizei imageSize
,
5464 GET_CURRENT_CONTEXT(ctx
);
5465 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
5466 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5471 _mesa_CompressedTextureImage1DEXT(GLuint texture
, GLenum target
, GLint level
,
5472 GLenum internalFormat
, GLsizei width
,
5473 GLint border
, GLsizei imageSize
,
5474 const GLvoid
*pixels
)
5476 struct gl_texture_object
* texObj
;
5477 GET_CURRENT_CONTEXT(ctx
);
5479 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
5480 "glCompressedTextureImage1DEXT");
5483 teximage(ctx
, GL_TRUE
, 1, texObj
, target
, level
, internalFormat
,
5484 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5489 _mesa_CompressedMultiTexImage1DEXT(GLenum texunit
, GLenum target
, GLint level
,
5490 GLenum internalFormat
, GLsizei width
,
5491 GLint border
, GLsizei imageSize
,
5492 const GLvoid
*pixels
)
5494 struct gl_texture_object
* texObj
;
5495 GET_CURRENT_CONTEXT(ctx
);
5497 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
5498 texunit
- GL_TEXTURE0
,
5500 "glCompressedMultiTexImage1DEXT");
5503 teximage(ctx
, GL_TRUE
, 1, texObj
, target
, level
, internalFormat
,
5504 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5509 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
5510 GLenum internalFormat
, GLsizei width
,
5511 GLsizei height
, GLint border
, GLsizei imageSize
,
5514 GET_CURRENT_CONTEXT(ctx
);
5515 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
5516 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5521 _mesa_CompressedTextureImage2DEXT(GLuint texture
, GLenum target
, GLint level
,
5522 GLenum internalFormat
, GLsizei width
,
5523 GLsizei height
, GLint border
, GLsizei imageSize
,
5524 const GLvoid
*pixels
)
5526 struct gl_texture_object
* texObj
;
5527 GET_CURRENT_CONTEXT(ctx
);
5529 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
5530 "glCompressedTextureImage2DEXT");
5533 teximage(ctx
, GL_TRUE
, 2, texObj
, target
, level
, internalFormat
,
5534 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5539 _mesa_CompressedMultiTexImage2DEXT(GLenum texunit
, GLenum target
, GLint level
,
5540 GLenum internalFormat
, GLsizei width
,
5541 GLsizei height
, GLint border
, GLsizei imageSize
,
5542 const GLvoid
*pixels
)
5544 struct gl_texture_object
* texObj
;
5545 GET_CURRENT_CONTEXT(ctx
);
5547 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
5548 texunit
- GL_TEXTURE0
,
5550 "glCompressedMultiTexImage2DEXT");
5553 teximage(ctx
, GL_TRUE
, 2, texObj
, target
, level
, internalFormat
,
5554 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5559 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
5560 GLenum internalFormat
, GLsizei width
,
5561 GLsizei height
, GLsizei depth
, GLint border
,
5562 GLsizei imageSize
, const GLvoid
*data
)
5564 GET_CURRENT_CONTEXT(ctx
);
5565 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
5566 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5571 _mesa_CompressedTextureImage3DEXT(GLuint texture
, GLenum target
, GLint level
,
5572 GLenum internalFormat
, GLsizei width
,
5573 GLsizei height
, GLsizei depth
, GLint border
,
5574 GLsizei imageSize
, const GLvoid
*pixels
)
5576 struct gl_texture_object
* texObj
;
5577 GET_CURRENT_CONTEXT(ctx
);
5579 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
5580 "glCompressedTextureImage3DEXT");
5583 teximage(ctx
, GL_TRUE
, 3, texObj
, target
, level
, internalFormat
,
5584 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5589 _mesa_CompressedMultiTexImage3DEXT(GLenum texunit
, GLenum target
, GLint level
,
5590 GLenum internalFormat
, GLsizei width
,
5591 GLsizei height
, GLsizei depth
, GLint border
,
5592 GLsizei imageSize
, const GLvoid
*pixels
)
5594 struct gl_texture_object
* texObj
;
5595 GET_CURRENT_CONTEXT(ctx
);
5597 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
5598 texunit
- GL_TEXTURE0
,
5600 "glCompressedMultiTexImage3DEXT");
5603 teximage(ctx
, GL_TRUE
, 3, texObj
, target
, level
, internalFormat
,
5604 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, pixels
, false);
5609 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
5610 GLenum internalFormat
, GLsizei width
,
5611 GLint border
, GLsizei imageSize
,
5614 GET_CURRENT_CONTEXT(ctx
);
5615 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
5616 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5621 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
5622 GLenum internalFormat
, GLsizei width
,
5623 GLsizei height
, GLint border
,
5624 GLsizei imageSize
, const GLvoid
*data
)
5626 GET_CURRENT_CONTEXT(ctx
);
5627 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
5628 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5633 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
5634 GLenum internalFormat
, GLsizei width
,
5635 GLsizei height
, GLsizei depth
, GLint border
,
5636 GLsizei imageSize
, const GLvoid
*data
)
5638 GET_CURRENT_CONTEXT(ctx
);
5639 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
5640 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
5645 * Common helper for glCompressedTexSubImage1/2/3D() and
5646 * glCompressedTextureSubImage1/2/3D().
5649 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
5650 struct gl_texture_object
*texObj
,
5651 struct gl_texture_image
*texImage
,
5652 GLenum target
, GLint level
, GLint xoffset
,
5653 GLint yoffset
, GLint zoffset
, GLsizei width
,
5654 GLsizei height
, GLsizei depth
, GLenum format
,
5655 GLsizei imageSize
, const GLvoid
*data
)
5657 FLUSH_VERTICES(ctx
, 0);
5659 _mesa_lock_texture(ctx
, texObj
);
5661 if (width
> 0 && height
> 0 && depth
> 0) {
5662 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
5663 xoffset
, yoffset
, zoffset
,
5664 width
, height
, depth
,
5665 format
, imageSize
, data
);
5667 check_gen_mipmap(ctx
, target
, texObj
, level
);
5669 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
5670 * the texel data, not the texture format, size, etc.
5674 _mesa_unlock_texture(ctx
, texObj
);
5679 /* Use bound texture to current unit */
5680 TEX_MODE_CURRENT_NO_ERROR
= 0,
5681 TEX_MODE_CURRENT_ERROR
,
5682 /* Use the specified texture name */
5683 TEX_MODE_DSA_NO_ERROR
,
5685 /* Use the specified texture name + target */
5686 TEX_MODE_EXT_DSA_TEXTURE
,
5687 /* Use the specified texture unit + target */
5688 TEX_MODE_EXT_DSA_TEXUNIT
,
5693 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint textureOrIndex
,
5694 GLint level
, GLint xoffset
, GLint yoffset
,
5695 GLint zoffset
, GLsizei width
, GLsizei height
,
5696 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5697 const GLvoid
*data
, enum tex_mode mode
,
5700 struct gl_texture_object
*texObj
= NULL
;
5701 struct gl_texture_image
*texImage
;
5702 bool no_error
= false;
5703 GET_CURRENT_CONTEXT(ctx
);
5706 case TEX_MODE_DSA_ERROR
:
5707 assert(target
== 0);
5708 texObj
= _mesa_lookup_texture_err(ctx
, textureOrIndex
, caller
);
5710 target
= texObj
->Target
;
5712 case TEX_MODE_DSA_NO_ERROR
:
5713 assert(target
== 0);
5714 texObj
= _mesa_lookup_texture(ctx
, textureOrIndex
);
5716 target
= texObj
->Target
;
5719 case TEX_MODE_EXT_DSA_TEXTURE
:
5720 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, textureOrIndex
,
5721 false, true, caller
);
5723 case TEX_MODE_EXT_DSA_TEXUNIT
:
5724 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
5729 case TEX_MODE_CURRENT_NO_ERROR
:
5731 case TEX_MODE_CURRENT_ERROR
:
5733 assert(textureOrIndex
== 0);
5738 compressed_subtexture_target_check(ctx
, target
, dim
, format
,
5739 mode
== TEX_MODE_DSA_ERROR
,
5744 if (mode
== TEX_MODE_CURRENT_NO_ERROR
||
5745 mode
== TEX_MODE_CURRENT_ERROR
) {
5746 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5753 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
5754 xoffset
, yoffset
, zoffset
, width
,
5755 height
, depth
, format
,
5756 imageSize
, data
, caller
)) {
5760 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5762 (mode
== TEX_MODE_DSA_ERROR
|| mode
== TEX_MODE_DSA_NO_ERROR
) &&
5763 texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5764 const char *pixels
= data
;
5767 /* Make sure the texture object is a proper cube.
5768 * (See texturesubimage in teximage.c for details on why this check is
5771 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
5772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5773 "glCompressedTextureSubImage3D(cube map incomplete)");
5777 /* Copy in each face. */
5778 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5779 texImage
= texObj
->Image
[i
][level
];
5782 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5783 texObj
->Target
, level
, xoffset
, yoffset
,
5784 0, width
, height
, 1, format
,
5787 /* Compressed images don't have a client format */
5788 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5790 texImage
->Height
, 1);
5792 pixels
+= image_stride
;
5793 imageSize
-= image_stride
;
5796 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5799 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5800 xoffset
, yoffset
, zoffset
, width
, height
,
5801 depth
, format
, imageSize
, data
);
5807 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5808 GLint xoffset
, GLsizei width
,
5809 GLenum format
, GLsizei imageSize
,
5812 compressed_tex_sub_image(1, target
, 0,
5813 level
, xoffset
, 0, 0, width
,
5814 1, 1, format
, imageSize
, data
,
5815 TEX_MODE_CURRENT_NO_ERROR
,
5816 "glCompressedTexSubImage1D");
5821 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5822 GLsizei width
, GLenum format
,
5823 GLsizei imageSize
, const GLvoid
*data
)
5825 compressed_tex_sub_image(1, target
, 0,
5826 level
, xoffset
, 0, 0, width
,
5827 1, 1, format
, imageSize
, data
,
5828 TEX_MODE_CURRENT_ERROR
,
5829 "glCompressedTexSubImage1D");
5834 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5835 GLint xoffset
, GLsizei width
,
5836 GLenum format
, GLsizei imageSize
,
5839 compressed_tex_sub_image(1, 0, texture
,
5840 level
, xoffset
, 0, 0,
5841 width
, 1, 1, format
, imageSize
, data
,
5842 TEX_MODE_DSA_NO_ERROR
,
5843 "glCompressedTextureSubImage1D");
5848 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5849 GLsizei width
, GLenum format
,
5850 GLsizei imageSize
, const GLvoid
*data
)
5852 compressed_tex_sub_image(1, 0, texture
,
5853 level
, xoffset
, 0, 0,
5854 width
, 1, 1, format
, imageSize
, data
,
5856 "glCompressedTextureSubImage1D");
5861 _mesa_CompressedTextureSubImage1DEXT(GLuint texture
, GLenum target
,
5862 GLint level
, GLint xoffset
,
5863 GLsizei width
, GLenum format
,
5864 GLsizei imageSize
, const GLvoid
*data
)
5866 compressed_tex_sub_image(1, target
, texture
, level
, xoffset
, 0,
5867 0, width
, 1, 1, format
, imageSize
,
5869 TEX_MODE_EXT_DSA_TEXTURE
,
5870 "glCompressedTextureSubImage1DEXT");
5875 _mesa_CompressedMultiTexSubImage1DEXT(GLenum texunit
, GLenum target
,
5876 GLint level
, GLint xoffset
,
5877 GLsizei width
, GLenum format
,
5878 GLsizei imageSize
, const GLvoid
*data
)
5880 compressed_tex_sub_image(1, target
, texunit
- GL_TEXTURE0
, level
,
5881 xoffset
, 0, 0, width
, 1, 1, format
, imageSize
,
5883 TEX_MODE_EXT_DSA_TEXUNIT
,
5884 "glCompressedMultiTexSubImage1DEXT");
5889 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5890 GLint xoffset
, GLint yoffset
,
5891 GLsizei width
, GLsizei height
,
5892 GLenum format
, GLsizei imageSize
,
5895 compressed_tex_sub_image(2, target
, 0, level
,
5896 xoffset
, yoffset
, 0,
5897 width
, height
, 1, format
, imageSize
, data
,
5898 TEX_MODE_CURRENT_NO_ERROR
,
5899 "glCompressedTexSubImage2D");
5904 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5905 GLint yoffset
, GLsizei width
, GLsizei height
,
5906 GLenum format
, GLsizei imageSize
,
5909 compressed_tex_sub_image(2, target
, 0, level
,
5910 xoffset
, yoffset
, 0,
5911 width
, height
, 1, format
, imageSize
, data
,
5912 TEX_MODE_CURRENT_ERROR
,
5913 "glCompressedTexSubImage2D");
5918 _mesa_CompressedTextureSubImage2DEXT(GLuint texture
, GLenum target
,
5919 GLint level
, GLint xoffset
,
5920 GLint yoffset
, GLsizei width
,
5921 GLsizei height
, GLenum format
,
5922 GLsizei imageSize
, const GLvoid
*data
)
5924 compressed_tex_sub_image(2, target
, texture
, level
, xoffset
,
5925 yoffset
, 0, width
, height
, 1, format
,
5927 TEX_MODE_EXT_DSA_TEXTURE
,
5928 "glCompressedTextureSubImage2DEXT");
5933 _mesa_CompressedMultiTexSubImage2DEXT(GLenum texunit
, GLenum target
,
5934 GLint level
, GLint xoffset
, GLint yoffset
,
5935 GLsizei width
, GLsizei height
, GLenum format
,
5936 GLsizei imageSize
, const GLvoid
*data
)
5938 compressed_tex_sub_image(2, target
, texunit
- GL_TEXTURE0
, level
,
5939 xoffset
, yoffset
, 0, width
, height
, 1, format
,
5941 TEX_MODE_EXT_DSA_TEXUNIT
,
5942 "glCompressedMultiTexSubImage2DEXT");
5947 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5948 GLint xoffset
, GLint yoffset
,
5949 GLsizei width
, GLsizei height
,
5950 GLenum format
, GLsizei imageSize
,
5953 compressed_tex_sub_image(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5954 width
, height
, 1, format
, imageSize
, data
,
5955 TEX_MODE_DSA_NO_ERROR
,
5956 "glCompressedTextureSubImage2D");
5961 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5963 GLsizei width
, GLsizei height
,
5964 GLenum format
, GLsizei imageSize
,
5967 compressed_tex_sub_image(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5968 width
, height
, 1, format
, imageSize
, data
,
5970 "glCompressedTextureSubImage2D");
5974 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5975 GLint xoffset
, GLint yoffset
,
5976 GLint zoffset
, GLsizei width
,
5977 GLsizei height
, GLsizei depth
,
5978 GLenum format
, GLsizei imageSize
,
5981 compressed_tex_sub_image(3, target
, 0, level
, xoffset
, yoffset
,
5982 zoffset
, width
, height
, depth
, format
,
5984 TEX_MODE_CURRENT_NO_ERROR
,
5985 "glCompressedTexSubImage3D");
5989 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5990 GLint yoffset
, GLint zoffset
, GLsizei width
,
5991 GLsizei height
, GLsizei depth
, GLenum format
,
5992 GLsizei imageSize
, const GLvoid
*data
)
5994 compressed_tex_sub_image(3, target
, 0, level
, xoffset
, yoffset
,
5995 zoffset
, width
, height
, depth
, format
,
5997 TEX_MODE_CURRENT_ERROR
,
5998 "glCompressedTexSubImage3D");
6002 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
6003 GLint xoffset
, GLint yoffset
,
6004 GLint zoffset
, GLsizei width
,
6005 GLsizei height
, GLsizei depth
,
6006 GLenum format
, GLsizei imageSize
,
6009 compressed_tex_sub_image(3, 0, texture
, level
, xoffset
, yoffset
,
6010 zoffset
, width
, height
, depth
, format
,
6012 TEX_MODE_DSA_NO_ERROR
,
6013 "glCompressedTextureSubImage3D");
6017 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
6018 GLint yoffset
, GLint zoffset
, GLsizei width
,
6019 GLsizei height
, GLsizei depth
,
6020 GLenum format
, GLsizei imageSize
,
6023 compressed_tex_sub_image(3, 0, texture
, level
, xoffset
, yoffset
,
6024 zoffset
, width
, height
, depth
, format
,
6027 "glCompressedTextureSubImage3D");
6032 _mesa_CompressedTextureSubImage3DEXT(GLuint texture
, GLenum target
,
6033 GLint level
, GLint xoffset
,
6034 GLint yoffset
, GLint zoffset
,
6035 GLsizei width
, GLsizei height
,
6036 GLsizei depth
, GLenum format
,
6037 GLsizei imageSize
, const GLvoid
*data
)
6039 compressed_tex_sub_image(3, target
, texture
, level
, xoffset
, yoffset
,
6040 zoffset
, width
, height
, depth
, format
,
6042 TEX_MODE_EXT_DSA_TEXTURE
,
6043 "glCompressedTextureSubImage3DEXT");
6048 _mesa_CompressedMultiTexSubImage3DEXT(GLenum texunit
, GLenum target
,
6049 GLint level
, GLint xoffset
, GLint yoffset
,
6050 GLint zoffset
, GLsizei width
, GLsizei height
,
6051 GLsizei depth
, GLenum format
,
6052 GLsizei imageSize
, const GLvoid
*data
)
6054 compressed_tex_sub_image(3, target
, texunit
- GL_TEXTURE0
, level
,
6055 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
6056 format
, imageSize
, data
,
6057 TEX_MODE_EXT_DSA_TEXUNIT
,
6058 "glCompressedMultiTexSubImage3DEXT");
6063 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
6065 if (ctx
->API
== API_OPENGL_COMPAT
) {
6066 switch (internalFormat
) {
6068 return MESA_FORMAT_A_UNORM8
;
6070 return MESA_FORMAT_A_UNORM16
;
6071 case GL_ALPHA16F_ARB
:
6072 return MESA_FORMAT_A_FLOAT16
;
6073 case GL_ALPHA32F_ARB
:
6074 return MESA_FORMAT_A_FLOAT32
;
6075 case GL_ALPHA8I_EXT
:
6076 return MESA_FORMAT_A_SINT8
;
6077 case GL_ALPHA16I_EXT
:
6078 return MESA_FORMAT_A_SINT16
;
6079 case GL_ALPHA32I_EXT
:
6080 return MESA_FORMAT_A_SINT32
;
6081 case GL_ALPHA8UI_EXT
:
6082 return MESA_FORMAT_A_UINT8
;
6083 case GL_ALPHA16UI_EXT
:
6084 return MESA_FORMAT_A_UINT16
;
6085 case GL_ALPHA32UI_EXT
:
6086 return MESA_FORMAT_A_UINT32
;
6088 return MESA_FORMAT_L_UNORM8
;
6089 case GL_LUMINANCE16
:
6090 return MESA_FORMAT_L_UNORM16
;
6091 case GL_LUMINANCE16F_ARB
:
6092 return MESA_FORMAT_L_FLOAT16
;
6093 case GL_LUMINANCE32F_ARB
:
6094 return MESA_FORMAT_L_FLOAT32
;
6095 case GL_LUMINANCE8I_EXT
:
6096 return MESA_FORMAT_L_SINT8
;
6097 case GL_LUMINANCE16I_EXT
:
6098 return MESA_FORMAT_L_SINT16
;
6099 case GL_LUMINANCE32I_EXT
:
6100 return MESA_FORMAT_L_SINT32
;
6101 case GL_LUMINANCE8UI_EXT
:
6102 return MESA_FORMAT_L_UINT8
;
6103 case GL_LUMINANCE16UI_EXT
:
6104 return MESA_FORMAT_L_UINT16
;
6105 case GL_LUMINANCE32UI_EXT
:
6106 return MESA_FORMAT_L_UINT32
;
6107 case GL_LUMINANCE8_ALPHA8
:
6108 return MESA_FORMAT_LA_UNORM8
;
6109 case GL_LUMINANCE16_ALPHA16
:
6110 return MESA_FORMAT_LA_UNORM16
;
6111 case GL_LUMINANCE_ALPHA16F_ARB
:
6112 return MESA_FORMAT_LA_FLOAT16
;
6113 case GL_LUMINANCE_ALPHA32F_ARB
:
6114 return MESA_FORMAT_LA_FLOAT32
;
6115 case GL_LUMINANCE_ALPHA8I_EXT
:
6116 return MESA_FORMAT_LA_SINT8
;
6117 case GL_LUMINANCE_ALPHA16I_EXT
:
6118 return MESA_FORMAT_LA_SINT16
;
6119 case GL_LUMINANCE_ALPHA32I_EXT
:
6120 return MESA_FORMAT_LA_SINT32
;
6121 case GL_LUMINANCE_ALPHA8UI_EXT
:
6122 return MESA_FORMAT_LA_UINT8
;
6123 case GL_LUMINANCE_ALPHA16UI_EXT
:
6124 return MESA_FORMAT_LA_UINT16
;
6125 case GL_LUMINANCE_ALPHA32UI_EXT
:
6126 return MESA_FORMAT_LA_UINT32
;
6128 return MESA_FORMAT_I_UNORM8
;
6129 case GL_INTENSITY16
:
6130 return MESA_FORMAT_I_UNORM16
;
6131 case GL_INTENSITY16F_ARB
:
6132 return MESA_FORMAT_I_FLOAT16
;
6133 case GL_INTENSITY32F_ARB
:
6134 return MESA_FORMAT_I_FLOAT32
;
6135 case GL_INTENSITY8I_EXT
:
6136 return MESA_FORMAT_I_SINT8
;
6137 case GL_INTENSITY16I_EXT
:
6138 return MESA_FORMAT_I_SINT16
;
6139 case GL_INTENSITY32I_EXT
:
6140 return MESA_FORMAT_I_SINT32
;
6141 case GL_INTENSITY8UI_EXT
:
6142 return MESA_FORMAT_I_UINT8
;
6143 case GL_INTENSITY16UI_EXT
:
6144 return MESA_FORMAT_I_UINT16
;
6145 case GL_INTENSITY32UI_EXT
:
6146 return MESA_FORMAT_I_UINT32
;
6152 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
6153 _mesa_has_OES_texture_buffer(ctx
)) {
6154 switch (internalFormat
) {
6156 return MESA_FORMAT_RGB_FLOAT32
;
6158 return MESA_FORMAT_RGB_UINT32
;
6160 return MESA_FORMAT_RGB_SINT32
;
6166 switch (internalFormat
) {
6168 return MESA_FORMAT_R8G8B8A8_UNORM
;
6170 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
6171 return MESA_FORMAT_NONE
;
6172 return MESA_FORMAT_RGBA_UNORM16
;
6173 case GL_RGBA16F_ARB
:
6174 return MESA_FORMAT_RGBA_FLOAT16
;
6175 case GL_RGBA32F_ARB
:
6176 return MESA_FORMAT_RGBA_FLOAT32
;
6178 return MESA_FORMAT_RGBA_SINT8
;
6179 case GL_RGBA16I_EXT
:
6180 return MESA_FORMAT_RGBA_SINT16
;
6181 case GL_RGBA32I_EXT
:
6182 return MESA_FORMAT_RGBA_SINT32
;
6183 case GL_RGBA8UI_EXT
:
6184 return MESA_FORMAT_RGBA_UINT8
;
6185 case GL_RGBA16UI_EXT
:
6186 return MESA_FORMAT_RGBA_UINT16
;
6187 case GL_RGBA32UI_EXT
:
6188 return MESA_FORMAT_RGBA_UINT32
;
6191 return MESA_FORMAT_RG_UNORM8
;
6193 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
6194 return MESA_FORMAT_NONE
;
6195 return MESA_FORMAT_RG_UNORM16
;
6197 return MESA_FORMAT_RG_FLOAT16
;
6199 return MESA_FORMAT_RG_FLOAT32
;
6201 return MESA_FORMAT_RG_SINT8
;
6203 return MESA_FORMAT_RG_SINT16
;
6205 return MESA_FORMAT_RG_SINT32
;
6207 return MESA_FORMAT_RG_UINT8
;
6209 return MESA_FORMAT_RG_UINT16
;
6211 return MESA_FORMAT_RG_UINT32
;
6214 return MESA_FORMAT_R_UNORM8
;
6216 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
6217 return MESA_FORMAT_NONE
;
6218 return MESA_FORMAT_R_UNORM16
;
6220 return MESA_FORMAT_R_FLOAT16
;
6222 return MESA_FORMAT_R_FLOAT32
;
6224 return MESA_FORMAT_R_SINT8
;
6226 return MESA_FORMAT_R_SINT16
;
6228 return MESA_FORMAT_R_SINT32
;
6230 return MESA_FORMAT_R_UINT8
;
6232 return MESA_FORMAT_R_UINT16
;
6234 return MESA_FORMAT_R_UINT32
;
6237 return MESA_FORMAT_NONE
;
6243 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
6244 GLenum internalFormat
)
6246 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
6249 if (format
== MESA_FORMAT_NONE
)
6250 return MESA_FORMAT_NONE
;
6252 datatype
= _mesa_get_format_datatype(format
);
6254 /* The GL_ARB_texture_buffer_object spec says:
6256 * "If ARB_texture_float is not supported, references to the
6257 * floating-point internal formats provided by that extension should be
6258 * removed, and such formats may not be passed to TexBufferARB."
6260 * As a result, GL_HALF_FLOAT internal format depends on both
6261 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
6263 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
6264 !ctx
->Extensions
.ARB_texture_float
)
6265 return MESA_FORMAT_NONE
;
6267 if (!ctx
->Extensions
.ARB_texture_rg
) {
6268 GLenum base_format
= _mesa_get_format_base_format(format
);
6269 if (base_format
== GL_R
|| base_format
== GL_RG
)
6270 return MESA_FORMAT_NONE
;
6273 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
6274 GLenum base_format
= _mesa_get_format_base_format(format
);
6275 if (base_format
== GL_RGB
)
6276 return MESA_FORMAT_NONE
;
6283 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
6284 * and glTextureBufferRange, including some error checking.
6287 texture_buffer_range(struct gl_context
*ctx
,
6288 struct gl_texture_object
*texObj
,
6289 GLenum internalFormat
,
6290 struct gl_buffer_object
*bufObj
,
6291 GLintptr offset
, GLsizeiptr size
,
6294 GLintptr oldOffset
= texObj
->BufferOffset
;
6295 GLsizeiptr oldSize
= texObj
->BufferSize
;
6298 /* NOTE: ARB_texture_buffer_object might not be supported in
6299 * the compatibility profile.
6301 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
6302 !_mesa_has_OES_texture_buffer(ctx
)) {
6303 _mesa_error(ctx
, GL_INVALID_OPERATION
,
6304 "%s(ARB_texture_buffer_object is not"
6305 " implemented for the compatibility profile)", caller
);
6309 if (texObj
->HandleAllocated
) {
6310 /* The ARB_bindless_texture spec says:
6312 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
6313 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
6314 * functions defined in terms of these, if the texture object to be
6315 * modified is referenced by one or more texture or image handles."
6317 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
6321 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
6322 if (format
== MESA_FORMAT_NONE
) {
6323 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
6324 caller
, _mesa_enum_to_string(internalFormat
));
6328 FLUSH_VERTICES(ctx
, 0);
6330 _mesa_lock_texture(ctx
, texObj
);
6332 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
6333 texObj
->BufferObjectFormat
= internalFormat
;
6334 texObj
->_BufferObjectFormat
= format
;
6335 texObj
->BufferOffset
= offset
;
6336 texObj
->BufferSize
= size
;
6338 _mesa_unlock_texture(ctx
, texObj
);
6340 if (ctx
->Driver
.TexParameter
) {
6341 if (offset
!= oldOffset
) {
6342 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
6344 if (size
!= oldSize
) {
6345 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
6349 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
6352 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
6358 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
6359 * Return true if it is, and return false if it is not
6360 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
6361 * core spec, 02.02.2015, PDF page 245).
6364 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
6367 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
6368 _mesa_error(ctx
, GL_INVALID_ENUM
,
6369 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
6377 * Check for errors related to the texture buffer range.
6378 * Return false if errors are found, true if none are found.
6381 check_texture_buffer_range(struct gl_context
*ctx
,
6382 struct gl_buffer_object
*bufObj
,
6383 GLintptr offset
, GLsizeiptr size
,
6386 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6387 * Textures (PDF page 245):
6388 * "An INVALID_VALUE error is generated if offset is negative, if
6389 * size is less than or equal to zero, or if offset + size is greater
6390 * than the value of BUFFER_SIZE for the buffer bound to target."
6393 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
6399 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
6404 if (offset
+ size
> bufObj
->Size
) {
6405 _mesa_error(ctx
, GL_INVALID_VALUE
,
6406 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
6407 (int) offset
, (int) size
, (int) bufObj
->Size
);
6411 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6412 * Textures (PDF page 245):
6413 * "An INVALID_VALUE error is generated if offset is not an integer
6414 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
6416 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
6417 _mesa_error(ctx
, GL_INVALID_VALUE
,
6418 "%s(invalid offset alignment)", caller
);
6426 /** GL_ARB_texture_buffer_object */
6428 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
6430 struct gl_texture_object
*texObj
;
6431 struct gl_buffer_object
*bufObj
;
6433 GET_CURRENT_CONTEXT(ctx
);
6435 /* Need to catch a bad target before it gets to
6436 * _mesa_get_current_tex_object.
6438 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
6442 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
6448 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6452 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
6453 buffer
? -1 : 0, "glTexBuffer");
6457 /** GL_ARB_texture_buffer_range */
6459 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
6460 GLintptr offset
, GLsizeiptr size
)
6462 struct gl_texture_object
*texObj
;
6463 struct gl_buffer_object
*bufObj
;
6465 GET_CURRENT_CONTEXT(ctx
);
6467 /* Need to catch a bad target before it gets to
6468 * _mesa_get_current_tex_object.
6470 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
6474 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
6478 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
6479 "glTexBufferRange"))
6483 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6484 * Textures (PDF page 254):
6485 * "If buffer is zero, then any buffer object attached to the buffer
6486 * texture is detached, the values offset and size are ignored and
6487 * the state for offset and size for the buffer texture are reset to
6495 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6499 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
6500 offset
, size
, "glTexBufferRange");
6504 /** GL_ARB_texture_buffer_range + GL_EXT_direct_state_access */
6506 _mesa_TextureBufferRangeEXT(GLuint texture
, GLenum target
, GLenum internalFormat
,
6507 GLuint buffer
, GLintptr offset
, GLsizeiptr size
)
6509 struct gl_texture_object
*texObj
;
6510 struct gl_buffer_object
*bufObj
;
6512 GET_CURRENT_CONTEXT(ctx
);
6514 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
, false, true,
6515 "glTextureBufferRangeEXT");
6519 if (!check_texture_buffer_target(ctx
, target
, "glTextureBufferRangeEXT"))
6523 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBufferRangeEXT");
6527 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
6528 "glTextureBufferRangeEXT"))
6532 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6533 * Textures (PDF page 254):
6534 * "If buffer is zero, then any buffer object attached to the buffer
6535 * texture is detached, the values offset and size are ignored and
6536 * the state for offset and size for the buffer texture are reset to
6544 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
6545 offset
, size
, "glTextureBufferRangeEXT");
6550 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
6552 struct gl_texture_object
*texObj
;
6553 struct gl_buffer_object
*bufObj
;
6555 GET_CURRENT_CONTEXT(ctx
);
6558 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
6564 /* Get the texture object by Name. */
6565 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
6569 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
6572 texture_buffer_range(ctx
, texObj
, internalFormat
,
6573 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
6577 _mesa_TextureBufferEXT(GLuint texture
, GLenum target
,
6578 GLenum internalFormat
, GLuint buffer
)
6580 struct gl_texture_object
*texObj
;
6581 struct gl_buffer_object
*bufObj
;
6583 GET_CURRENT_CONTEXT(ctx
);
6586 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
6592 /* Get the texture object by Name. */
6593 texObj
= _mesa_lookup_or_create_texture(ctx
, target
, texture
,
6595 "glTextureBufferEXT");
6598 !check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBufferEXT"))
6601 texture_buffer_range(ctx
, texObj
, internalFormat
,
6602 bufObj
, 0, buffer
? -1 : 0, "glTextureBufferEXT");
6606 _mesa_MultiTexBufferEXT(GLenum texunit
, GLenum target
,
6607 GLenum internalFormat
, GLuint buffer
)
6609 struct gl_texture_object
*texObj
;
6610 struct gl_buffer_object
*bufObj
;
6612 GET_CURRENT_CONTEXT(ctx
);
6615 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glMultiTexBufferEXT");
6621 /* Get the texture object */
6622 texObj
= _mesa_get_texobj_by_target_and_texunit(ctx
, target
,
6623 texunit
- GL_TEXTURE0
,
6625 "glMultiTexBufferEXT");
6628 !check_texture_buffer_target(ctx
, texObj
->Target
, "glMultiTexBufferEXT"))
6631 texture_buffer_range(ctx
, texObj
, internalFormat
,
6632 bufObj
, 0, buffer
? -1 : 0, "glMultiTexBufferEXT");
6636 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
6637 GLintptr offset
, GLsizeiptr size
)
6639 struct gl_texture_object
*texObj
;
6640 struct gl_buffer_object
*bufObj
;
6642 GET_CURRENT_CONTEXT(ctx
);
6645 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
6646 "glTextureBufferRange");
6650 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
6651 "glTextureBufferRange"))
6655 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
6656 * Textures (PDF page 254):
6657 * "If buffer is zero, then any buffer object attached to the buffer
6658 * texture is detached, the values offset and size are ignored and
6659 * the state for offset and size for the buffer texture are reset to
6667 /* Get the texture object by Name. */
6668 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
6672 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
6673 "glTextureBufferRange"))
6676 texture_buffer_range(ctx
, texObj
, internalFormat
,
6677 bufObj
, offset
, size
, "glTextureBufferRange");
6681 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
6682 GLenum internalformat
)
6684 /* Everything that is allowed for renderbuffers,
6685 * except for a base format of GL_STENCIL_INDEX, unless supported.
6687 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
6688 if (ctx
->Extensions
.ARB_texture_stencil8
)
6689 return baseFormat
!= 0;
6691 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
6695 /** GL_ARB_texture_multisample */
6697 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
6700 case GL_TEXTURE_2D_MULTISAMPLE
:
6702 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
6703 return dims
== 2 && !dsa
;
6704 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
6706 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
6707 return dims
== 3 && !dsa
;
6715 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
6716 struct gl_texture_object
*texObj
,
6717 struct gl_memory_object
*memObj
,
6718 GLenum target
, GLsizei samples
,
6719 GLint internalformat
, GLsizei width
,
6720 GLsizei height
, GLsizei depth
,
6721 GLboolean fixedsamplelocations
,
6722 GLboolean immutable
, GLuint64 offset
,
6725 struct gl_texture_image
*texImage
;
6726 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
6727 mesa_format texFormat
;
6728 GLenum sample_count_error
;
6729 bool dsa
= strstr(func
, "ture") ? true : false;
6731 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
6732 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
6733 _mesa_enum_to_string(target
), samples
);
6736 if (!((ctx
->Extensions
.ARB_texture_multisample
6737 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
6738 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
6743 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
6747 if (!check_multisample_target(dims
, target
, dsa
)) {
6748 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
6749 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
6750 _mesa_enum_to_string(target
));
6754 /* check that the specified internalformat is color/depth/stencil-renderable;
6755 * refer GL3.1 spec 4.4.4
6758 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
6759 _mesa_error(ctx
, GL_INVALID_ENUM
,
6760 "%s(internalformat=%s not legal for immutable-format)",
6761 func
, _mesa_enum_to_string(internalformat
));
6765 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
6766 /* Page 172 of OpenGL ES 3.1 spec says:
6767 * "An INVALID_ENUM error is generated if sizedinternalformat is not
6768 * color-renderable, depth-renderable, or stencil-renderable (as
6769 * defined in section 9.4).
6771 * (Same error is also defined for desktop OpenGL for multisample
6772 * teximage/texstorage functions.)
6774 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
6775 _mesa_enum_to_string(internalformat
));
6779 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
6780 internalformat
, samples
, samples
);
6781 samplesOK
= sample_count_error
== GL_NO_ERROR
;
6783 /* Page 254 of OpenGL 4.4 spec says:
6784 * "Proxy arrays for two-dimensional multisample and two-dimensional
6785 * multisample array textures are operated on in the same way when
6786 * TexImage2DMultisample is called with target specified as
6787 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
6788 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
6789 * However, if samples is not supported, then no error is generated.
6791 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
6792 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
6796 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
6797 _mesa_error(ctx
, GL_INVALID_OPERATION
,
6798 "%s(texture object 0)",
6803 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
6805 if (texImage
== NULL
) {
6806 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
6810 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
6811 internalformat
, GL_NONE
, GL_NONE
);
6812 assert(texFormat
!= MESA_FORMAT_NONE
);
6814 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
6815 width
, height
, depth
, 0);
6817 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
6818 samples
, width
, height
, depth
);
6820 if (_mesa_is_proxy_texture(target
)) {
6821 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
6822 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
6823 internalformat
, texFormat
,
6824 samples
, fixedsamplelocations
);
6827 /* clear all image fields */
6828 clear_teximage_fields(texImage
);
6832 if (!dimensionsOK
) {
6833 _mesa_error(ctx
, GL_INVALID_VALUE
,
6834 "%s(invalid width=%d or height=%d)", func
, width
, height
);
6839 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
6843 /* Check if texObj->Immutable is set */
6844 if (texObj
->Immutable
) {
6845 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
6849 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
6851 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
6852 internalformat
, texFormat
,
6853 samples
, fixedsamplelocations
);
6855 if (width
> 0 && height
> 0 && depth
> 0) {
6857 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
6862 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
6863 internalformat
, texFormat
);
6866 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
6867 width
, height
, depth
)) {
6868 /* tidy up the texture image state. strictly speaking,
6869 * we're allowed to just leave this in whatever state we
6870 * like, but being tidy is good.
6872 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
6873 internalformat
, texFormat
);
6878 texObj
->Immutable
|= immutable
;
6881 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
6884 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
6890 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
6891 GLenum internalformat
, GLsizei width
,
6892 GLsizei height
, GLboolean fixedsamplelocations
)
6894 struct gl_texture_object
*texObj
;
6895 GET_CURRENT_CONTEXT(ctx
);
6897 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6901 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6902 internalformat
, width
, height
, 1,
6903 fixedsamplelocations
, GL_FALSE
, 0,
6904 "glTexImage2DMultisample");
6909 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
6910 GLenum internalformat
, GLsizei width
,
6911 GLsizei height
, GLsizei depth
,
6912 GLboolean fixedsamplelocations
)
6914 struct gl_texture_object
*texObj
;
6915 GET_CURRENT_CONTEXT(ctx
);
6917 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6921 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6922 internalformat
, width
, height
, depth
,
6923 fixedsamplelocations
, GL_FALSE
, 0,
6924 "glTexImage3DMultisample");
6928 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
6931 GET_CURRENT_CONTEXT(ctx
);
6933 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
6934 _mesa_error(ctx
, GL_INVALID_VALUE
,
6935 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
6936 dims
, width
, height
, depth
);
6943 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
6944 GLenum internalformat
, GLsizei width
,
6945 GLsizei height
, GLboolean fixedsamplelocations
)
6947 struct gl_texture_object
*texObj
;
6948 GET_CURRENT_CONTEXT(ctx
);
6950 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6954 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6957 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6958 internalformat
, width
, height
, 1,
6959 fixedsamplelocations
, GL_TRUE
, 0,
6960 "glTexStorage2DMultisample");
6964 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
6965 GLenum internalformat
, GLsizei width
,
6966 GLsizei height
, GLsizei depth
,
6967 GLboolean fixedsamplelocations
)
6969 struct gl_texture_object
*texObj
;
6970 GET_CURRENT_CONTEXT(ctx
);
6972 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6976 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6979 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6980 internalformat
, width
, height
, depth
,
6981 fixedsamplelocations
, GL_TRUE
, 0,
6982 "glTexStorage3DMultisample");
6986 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6987 GLenum internalformat
, GLsizei width
,
6989 GLboolean fixedsamplelocations
)
6991 struct gl_texture_object
*texObj
;
6992 GET_CURRENT_CONTEXT(ctx
);
6994 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6995 "glTextureStorage2DMultisample");
6999 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
7002 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
7003 samples
, internalformat
, width
, height
, 1,
7004 fixedsamplelocations
, GL_TRUE
, 0,
7005 "glTextureStorage2DMultisample");
7009 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
7010 GLenum internalformat
, GLsizei width
,
7011 GLsizei height
, GLsizei depth
,
7012 GLboolean fixedsamplelocations
)
7014 struct gl_texture_object
*texObj
;
7015 GET_CURRENT_CONTEXT(ctx
);
7017 /* Get the texture object by Name. */
7018 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
7019 "glTextureStorage3DMultisample");
7023 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
7026 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
7027 internalformat
, width
, height
, depth
,
7028 fixedsamplelocations
, GL_TRUE
, 0,
7029 "glTextureStorage3DMultisample");
7033 _mesa_TextureStorage2DMultisampleEXT(GLuint texture
, GLenum target
, GLsizei samples
,
7034 GLenum internalformat
, GLsizei width
,
7036 GLboolean fixedsamplelocations
)
7038 struct gl_texture_object
*texObj
;
7039 GET_CURRENT_CONTEXT(ctx
);
7041 texObj
= lookup_texture_ext_dsa(ctx
, target
, texture
,
7042 "glTextureStorage2DMultisampleEXT");
7046 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
7049 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
7050 samples
, internalformat
, width
, height
, 1,
7051 fixedsamplelocations
, GL_TRUE
, 0,
7052 "glTextureStorage2DMultisampleEXT");
7056 _mesa_TextureStorage3DMultisampleEXT(GLuint texture
, GLenum target
, GLsizei samples
,
7057 GLenum internalformat
, GLsizei width
,
7058 GLsizei height
, GLsizei depth
,
7059 GLboolean fixedsamplelocations
)
7061 struct gl_texture_object
*texObj
;
7062 GET_CURRENT_CONTEXT(ctx
);
7064 texObj
= lookup_texture_ext_dsa(ctx
, target
, texture
,
7065 "glTextureStorage3DMultisampleEXT");
7069 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
7072 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
7073 internalformat
, width
, height
, depth
,
7074 fixedsamplelocations
, GL_TRUE
, 0,
7075 "glTextureStorage3DMultisampleEXT");
7079 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
7080 struct gl_texture_object
*texObj
,
7081 struct gl_memory_object
*memObj
,
7082 GLenum target
, GLsizei samples
,
7083 GLenum internalFormat
, GLsizei width
,
7084 GLsizei height
, GLsizei depth
,
7085 GLboolean fixedSampleLocations
,
7086 GLuint64 offset
, const char* func
)
7090 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
7091 internalFormat
, width
, height
, depth
,
7092 fixedSampleLocations
, GL_TRUE
, offset
,