1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/macros.h"
36 #include "main/mfeatures.h"
38 #include "st_context.h"
39 #include "st_texture.h"
40 #include "st_cb_blit.h"
41 #include "st_cb_fbo.h"
44 #include "util/u_blit.h"
48 st_init_blit(struct st_context
*st
)
50 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
55 st_destroy_blit(struct st_context
*st
)
57 util_destroy_blit(st
->blit
);
62 #if FEATURE_EXT_framebuffer_blit
65 st_BlitFramebuffer_resolve(struct gl_context
*ctx
,
67 struct pipe_resolve_info
*info
)
69 const GLbitfield depthStencil
= GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
;
71 struct st_context
*st
= st_context(ctx
);
73 struct st_renderbuffer
*srcRb
, *dstRb
;
75 if (mask
& GL_COLOR_BUFFER_BIT
) {
76 srcRb
= st_renderbuffer(ctx
->ReadBuffer
->_ColorReadBuffer
);
77 dstRb
= st_renderbuffer(ctx
->DrawBuffer
->_ColorDrawBuffers
[0]);
79 info
->mask
= PIPE_MASK_RGBA
;
81 info
->src
.res
= srcRb
->texture
;
82 info
->src
.layer
= srcRb
->surface
->u
.tex
.first_layer
;
83 info
->dst
.res
= dstRb
->texture
;
84 info
->dst
.level
= dstRb
->surface
->u
.tex
.level
;
85 info
->dst
.layer
= dstRb
->surface
->u
.tex
.first_layer
;
87 st
->pipe
->resource_resolve(st
->pipe
, info
);
90 if (mask
& depthStencil
) {
91 struct gl_renderbuffer_attachment
*srcDepth
, *srcStencil
;
92 struct gl_renderbuffer_attachment
*dstDepth
, *dstStencil
;
95 srcDepth
= &ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
];
96 dstDepth
= &ctx
->DrawBuffer
->Attachment
[BUFFER_DEPTH
];
97 srcStencil
= &ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
];
98 dstStencil
= &ctx
->DrawBuffer
->Attachment
[BUFFER_STENCIL
];
101 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
102 st_is_depth_stencil_combined(dstDepth
, dstStencil
);
104 if ((mask
& GL_DEPTH_BUFFER_BIT
) || combined
) {
105 /* resolve depth and, if combined and requested, stencil as well */
106 srcRb
= st_renderbuffer(srcDepth
->Renderbuffer
);
107 dstRb
= st_renderbuffer(dstDepth
->Renderbuffer
);
109 info
->mask
= (mask
& GL_DEPTH_BUFFER_BIT
) ? PIPE_MASK_Z
: 0;
110 if (combined
&& (mask
& GL_STENCIL_BUFFER_BIT
))
111 info
->mask
|= PIPE_MASK_S
;
113 info
->src
.res
= srcRb
->texture
;
114 info
->src
.layer
= srcRb
->surface
->u
.tex
.first_layer
;
115 info
->dst
.res
= dstRb
->texture
;
116 info
->dst
.level
= dstRb
->surface
->u
.tex
.level
;
117 info
->dst
.layer
= dstRb
->surface
->u
.tex
.first_layer
;
119 st
->pipe
->resource_resolve(st
->pipe
, info
);
122 if (mask
& GL_STENCIL_BUFFER_BIT
) {
123 /* resolve separate stencil buffer */
124 srcRb
= st_renderbuffer(srcStencil
->Renderbuffer
);
125 dstRb
= st_renderbuffer(dstStencil
->Renderbuffer
);
127 info
->mask
= PIPE_MASK_S
;
129 info
->src
.res
= srcRb
->texture
;
130 info
->src
.layer
= srcRb
->surface
->u
.tex
.first_layer
;
131 info
->dst
.res
= dstRb
->texture
;
132 info
->dst
.level
= dstRb
->surface
->u
.tex
.level
;
133 info
->dst
.layer
= dstRb
->surface
->u
.tex
.first_layer
;
135 st
->pipe
->resource_resolve(st
->pipe
, info
);
141 st_BlitFramebuffer(struct gl_context
*ctx
,
142 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
143 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
144 GLbitfield mask
, GLenum filter
)
146 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
147 GL_STENCIL_BUFFER_BIT
);
148 struct st_context
*st
= st_context(ctx
);
149 const uint pFilter
= ((filter
== GL_NEAREST
)
150 ? PIPE_TEX_MIPFILTER_NEAREST
151 : PIPE_TEX_MIPFILTER_LINEAR
);
152 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
153 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
155 st_validate_state(st
);
157 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
158 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
159 return; /* nothing to draw/blit */
162 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
163 /* invert Y for dest */
164 dstY0
= drawFB
->Height
- dstY0
;
165 dstY1
= drawFB
->Height
- dstY1
;
168 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
169 /* invert Y for src */
170 srcY0
= readFB
->Height
- srcY0
;
171 srcY1
= readFB
->Height
- srcY1
;
174 /* Disable conditional rendering. */
175 if (st
->render_condition
) {
176 st
->pipe
->render_condition(st
->pipe
, NULL
, 0);
179 if (readFB
->Visual
.sampleBuffers
> drawFB
->Visual
.sampleBuffers
) {
180 struct pipe_resolve_info info
;
205 st_BlitFramebuffer_resolve(ctx
, mask
, &info
); /* filter doesn't apply */
210 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
211 /* Both src and dst are upside down. Swap Y to make it
212 * right-side up to increase odds of using a fast path.
213 * Recall that all Gallium raster coords have Y=0=top.
224 if (mask
& GL_COLOR_BUFFER_BIT
) {
225 struct gl_renderbuffer_attachment
*srcAtt
=
226 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
228 if(srcAtt
->Type
== GL_TEXTURE
) {
229 struct st_texture_object
*srcObj
=
230 st_texture_object(srcAtt
->Texture
);
231 struct st_renderbuffer
*dstRb
=
232 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
233 struct pipe_surface
*dstSurf
= dstRb
->surface
;
238 util_blit_pixels(st
->blit
, srcObj
->pt
, srcAtt
->TextureLevel
,
239 srcX0
, srcY0
, srcX1
, srcY1
,
240 srcAtt
->Zoffset
+ srcAtt
->CubeMapFace
,
241 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
245 struct st_renderbuffer
*srcRb
=
246 st_renderbuffer(readFB
->_ColorReadBuffer
);
247 struct st_renderbuffer
*dstRb
=
248 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
249 struct pipe_surface
*srcSurf
= srcRb
->surface
;
250 struct pipe_surface
*dstSurf
= dstRb
->surface
;
252 util_blit_pixels(st
->blit
,
253 srcRb
->texture
, srcSurf
->u
.tex
.level
,
254 srcX0
, srcY0
, srcX1
, srcY1
,
255 srcSurf
->u
.tex
.first_layer
,
256 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
261 if (mask
& depthStencil
) {
262 /* depth and/or stencil blit */
264 /* get src/dst depth surfaces */
265 struct gl_renderbuffer_attachment
*srcDepth
=
266 &readFB
->Attachment
[BUFFER_DEPTH
];
267 struct gl_renderbuffer_attachment
*dstDepth
=
268 &drawFB
->Attachment
[BUFFER_DEPTH
];
269 struct gl_renderbuffer_attachment
*srcStencil
=
270 &readFB
->Attachment
[BUFFER_STENCIL
];
271 struct gl_renderbuffer_attachment
*dstStencil
=
272 &drawFB
->Attachment
[BUFFER_STENCIL
];
274 struct st_renderbuffer
*srcDepthRb
=
275 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
276 struct st_renderbuffer
*dstDepthRb
=
277 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
278 struct pipe_surface
*dstDepthSurf
=
279 dstDepthRb
? dstDepthRb
->surface
: NULL
;
281 if ((mask
& depthStencil
) == depthStencil
&&
282 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
283 st_is_depth_stencil_combined(dstDepth
, dstStencil
)) {
285 /* Blitting depth and stencil values between combined
286 * depth/stencil buffers. This is the ideal case for such buffers.
288 util_blit_pixels(st
->blit
,
290 srcDepthRb
->surface
->u
.tex
.level
,
291 srcX0
, srcY0
, srcX1
, srcY1
,
292 srcDepthRb
->surface
->u
.tex
.first_layer
,
293 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
297 /* blitting depth and stencil separately */
299 if (mask
& GL_DEPTH_BUFFER_BIT
) {
300 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
301 srcDepthRb
->surface
->u
.tex
.level
,
302 srcX0
, srcY0
, srcX1
, srcY1
,
303 srcDepthRb
->surface
->u
.tex
.first_layer
,
304 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
308 if (mask
& GL_STENCIL_BUFFER_BIT
) {
309 /* blit stencil only */
310 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
316 /* Restore conditional rendering state. */
317 if (st
->render_condition
) {
318 st
->pipe
->render_condition(st
->pipe
, st
->render_condition
,
325 st_init_blit_functions(struct dd_function_table
*functions
)
327 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
330 #endif /* FEATURE_EXT_framebuffer_blit */