1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "main/mtypes.h"
29 #include "main/enums.h"
30 #include "main/image.h"
31 #include "main/teximage.h"
32 #include "main/texstate.h"
33 #include "main/fbobject.h"
35 #include "drivers/common/meta.h"
37 #include "intel_screen.h"
38 #include "intel_context.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41 #include "intel_fbo.h"
42 #include "intel_tex.h"
43 #include "intel_blit.h"
45 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
49 intel_copy_texsubimage(struct intel_context
*intel
,
50 struct intel_texture_image
*intelImage
,
51 GLint dstx
, GLint dsty
,
52 struct intel_renderbuffer
*irb
,
53 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
55 struct gl_context
*ctx
= &intel
->ctx
;
56 struct intel_region
*region
;
57 const GLenum internalFormat
= intelImage
->base
.Base
.InternalFormat
;
58 bool copy_supported
= false;
59 bool copy_supported_with_alpha_override
= false;
61 intel_prepare_render(intel
);
63 if (!intelImage
->mt
|| !irb
|| !irb
->mt
) {
64 if (unlikely(INTEL_DEBUG
& DEBUG_FALLBACKS
))
65 fprintf(stderr
, "%s fail %p %p (0x%08x)\n",
66 __FUNCTION__
, intelImage
->mt
, irb
, internalFormat
);
69 region
= irb
->mt
->region
;
73 copy_supported
= intelImage
->base
.Base
.TexFormat
== intel_rb_format(irb
);
75 /* Converting ARGB8888 to XRGB8888 is trivial: ignore the alpha bits */
76 if (intel_rb_format(irb
) == MESA_FORMAT_ARGB8888
&&
77 intelImage
->base
.Base
.TexFormat
== MESA_FORMAT_XRGB8888
) {
78 copy_supported
= true;
81 /* Converting XRGB8888 to ARGB8888 requires setting the alpha bits to 1.0 */
82 if (intel_rb_format(irb
) == MESA_FORMAT_XRGB8888
&&
83 intelImage
->base
.Base
.TexFormat
== MESA_FORMAT_ARGB8888
) {
84 copy_supported_with_alpha_override
= true;
87 if (!copy_supported
&& !copy_supported_with_alpha_override
) {
88 if (unlikely(INTEL_DEBUG
& DEBUG_FALLBACKS
))
89 fprintf(stderr
, "%s mismatched formats %s, %s\n",
91 _mesa_get_format_name(intelImage
->base
.Base
.TexFormat
),
92 _mesa_get_format_name(intel_rb_format(irb
)));
97 GLuint image_x
, image_y
;
100 /* get dest x/y in destination texture */
101 intel_miptree_get_image_offset(intelImage
->mt
,
102 intelImage
->base
.Base
.Level
,
103 intelImage
->base
.Base
.Face
,
107 /* The blitter can't handle Y-tiled buffers. */
108 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
) {
112 if (_mesa_is_winsys_fbo(ctx
->ReadBuffer
)) {
113 /* Flip vertical orientation for system framebuffers */
114 y
= ctx
->ReadBuffer
->Height
- (y
+ height
);
115 src_pitch
= -region
->pitch
;
117 /* reading from a FBO, y is already oriented the way we like */
118 src_pitch
= region
->pitch
;
121 /* blit from src buffer to texture */
122 if (!intelEmitCopyBlit(intel
,
128 intelImage
->mt
->region
->pitch
,
129 intelImage
->mt
->region
->bo
,
131 intelImage
->mt
->region
->tiling
,
132 irb
->draw_x
+ x
, irb
->draw_y
+ y
,
133 image_x
+ dstx
, image_y
+ dsty
,
140 if (copy_supported_with_alpha_override
)
141 intel_set_teximage_alpha_to_one(ctx
, intelImage
);
148 intelCopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
149 struct gl_texture_image
*texImage
,
150 GLint xoffset
, GLint yoffset
, GLint zoffset
,
151 struct gl_renderbuffer
*rb
,
153 GLsizei width
, GLsizei height
)
155 if (dims
== 3 || !intel_copy_texsubimage(intel_context(ctx
),
156 intel_texture_image(texImage
),
158 intel_renderbuffer(rb
), x
, y
, width
, height
)) {
159 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
160 _mesa_meta_CopyTexSubImage(ctx
, dims
, texImage
,
161 xoffset
, yoffset
, zoffset
,
162 rb
, x
, y
, width
, height
);
168 intelInitTextureCopyImageFuncs(struct dd_function_table
*functions
)
170 functions
->CopyTexSubImage
= intelCopyTexSubImage
;