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"
34 #include "drivers/common/meta.h"
36 #include "intel_screen.h"
37 #include "intel_context.h"
38 #include "intel_mipmap_tree.h"
39 #include "intel_regions.h"
40 #include "intel_fbo.h"
41 #include "intel_tex.h"
42 #include "intel_blit.h"
44 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
48 intel_copy_texsubimage(struct intel_context
*intel
,
49 struct intel_texture_image
*intelImage
,
50 GLint dstx
, GLint dsty
,
51 struct intel_renderbuffer
*irb
,
52 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
54 struct gl_context
*ctx
= &intel
->ctx
;
55 struct intel_region
*region
;
56 const GLenum internalFormat
= intelImage
->base
.Base
.InternalFormat
;
57 bool copy_supported
= false;
58 bool copy_supported_with_alpha_override
= false;
60 intel_prepare_render(intel
);
62 if (!intelImage
->mt
|| !irb
|| !irb
->mt
) {
63 if (unlikely(INTEL_DEBUG
& DEBUG_FALLBACKS
))
64 fprintf(stderr
, "%s fail %p %p (0x%08x)\n",
65 __FUNCTION__
, intelImage
->mt
, irb
, internalFormat
);
68 region
= irb
->mt
->region
;
72 copy_supported
= intelImage
->base
.Base
.TexFormat
== intel_rb_format(irb
);
74 /* Converting ARGB8888 to XRGB8888 is trivial: ignore the alpha bits */
75 if (intel_rb_format(irb
) == MESA_FORMAT_ARGB8888
&&
76 intelImage
->base
.Base
.TexFormat
== MESA_FORMAT_XRGB8888
) {
77 copy_supported
= true;
80 /* Converting XRGB8888 to ARGB8888 requires setting the alpha bits to 1.0 */
81 if (intel_rb_format(irb
) == MESA_FORMAT_XRGB8888
&&
82 intelImage
->base
.Base
.TexFormat
== MESA_FORMAT_ARGB8888
) {
83 copy_supported_with_alpha_override
= true;
86 if (!copy_supported
&& !copy_supported_with_alpha_override
) {
87 if (unlikely(INTEL_DEBUG
& DEBUG_FALLBACKS
))
88 fprintf(stderr
, "%s mismatched formats %s, %s\n",
90 _mesa_get_format_name(intelImage
->base
.Base
.TexFormat
),
91 _mesa_get_format_name(intel_rb_format(irb
)));
96 GLuint image_x
, image_y
;
99 /* get dest x/y in destination texture */
100 intel_miptree_get_image_offset(intelImage
->mt
,
101 intelImage
->base
.Base
.Level
,
102 intelImage
->base
.Base
.Face
,
106 /* The blitter can't handle Y-tiled buffers. */
107 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
) {
111 if (ctx
->ReadBuffer
->Name
== 0) {
112 /* Flip vertical orientation for system framebuffers */
113 y
= ctx
->ReadBuffer
->Height
- (y
+ height
);
114 src_pitch
= -region
->pitch
;
116 /* reading from a FBO, y is already oriented the way we like */
117 src_pitch
= region
->pitch
;
120 /* blit from src buffer to texture */
121 if (!intelEmitCopyBlit(intel
,
127 intelImage
->mt
->region
->pitch
,
128 intelImage
->mt
->region
->bo
,
130 intelImage
->mt
->region
->tiling
,
131 irb
->draw_x
+ x
, irb
->draw_y
+ y
,
132 image_x
+ dstx
, image_y
+ dsty
,
139 if (copy_supported_with_alpha_override
)
140 intel_set_teximage_alpha_to_one(ctx
, intelImage
);
147 intelCopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
148 struct gl_texture_image
*texImage
,
149 GLint xoffset
, GLint yoffset
, GLint zoffset
,
150 struct gl_renderbuffer
*rb
,
152 GLsizei width
, GLsizei height
)
154 if (dims
== 3 || !intel_copy_texsubimage(intel_context(ctx
),
155 intel_texture_image(texImage
),
157 intel_renderbuffer(rb
), x
, y
, width
, height
)) {
158 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
159 _mesa_meta_CopyTexSubImage(ctx
, dims
, texImage
,
160 xoffset
, yoffset
, zoffset
,
161 rb
, x
, y
, width
, height
);
167 intelInitTextureCopyImageFuncs(struct dd_function_table
*functions
)
169 functions
->CopyTexSubImage
= intelCopyTexSubImage
;