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 mask
&= ~GL_STENCIL_BUFFER_BIT
;
112 info
->mask
|= PIPE_MASK_S
;
115 info
->src
.res
= srcRb
->texture
;
116 info
->src
.layer
= srcRb
->surface
->u
.tex
.first_layer
;
117 info
->dst
.res
= dstRb
->texture
;
118 info
->dst
.level
= dstRb
->surface
->u
.tex
.level
;
119 info
->dst
.layer
= dstRb
->surface
->u
.tex
.first_layer
;
121 st
->pipe
->resource_resolve(st
->pipe
, info
);
124 if (mask
& GL_STENCIL_BUFFER_BIT
) {
125 /* resolve separate stencil buffer */
126 srcRb
= st_renderbuffer(srcStencil
->Renderbuffer
);
127 dstRb
= st_renderbuffer(dstStencil
->Renderbuffer
);
129 info
->mask
= PIPE_MASK_S
;
131 info
->src
.res
= srcRb
->texture
;
132 info
->src
.layer
= srcRb
->surface
->u
.tex
.first_layer
;
133 info
->dst
.res
= dstRb
->texture
;
134 info
->dst
.level
= dstRb
->surface
->u
.tex
.level
;
135 info
->dst
.layer
= dstRb
->surface
->u
.tex
.first_layer
;
137 st
->pipe
->resource_resolve(st
->pipe
, info
);
143 st_BlitFramebuffer(struct gl_context
*ctx
,
144 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
145 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
146 GLbitfield mask
, GLenum filter
)
148 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
149 GL_STENCIL_BUFFER_BIT
);
150 struct st_context
*st
= st_context(ctx
);
151 const uint pFilter
= ((filter
== GL_NEAREST
)
152 ? PIPE_TEX_MIPFILTER_NEAREST
153 : PIPE_TEX_MIPFILTER_LINEAR
);
154 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
155 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
157 st_validate_state(st
);
159 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
160 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
161 return; /* nothing to draw/blit */
164 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
165 /* invert Y for dest */
166 dstY0
= drawFB
->Height
- dstY0
;
167 dstY1
= drawFB
->Height
- dstY1
;
170 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
171 /* invert Y for src */
172 srcY0
= readFB
->Height
- srcY0
;
173 srcY1
= readFB
->Height
- srcY1
;
176 /* Disable conditional rendering. */
177 if (st
->render_condition
) {
178 st
->pipe
->render_condition(st
->pipe
, NULL
, 0);
181 if (readFB
->Visual
.sampleBuffers
> drawFB
->Visual
.sampleBuffers
) {
182 struct pipe_resolve_info info
;
207 st_BlitFramebuffer_resolve(ctx
, mask
, &info
); /* filter doesn't apply */
212 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
213 /* Both src and dst are upside down. Swap Y to make it
214 * right-side up to increase odds of using a fast path.
215 * Recall that all Gallium raster coords have Y=0=top.
226 if (mask
& GL_COLOR_BUFFER_BIT
) {
227 struct gl_renderbuffer_attachment
*srcAtt
=
228 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
230 if(srcAtt
->Type
== GL_TEXTURE
) {
231 struct st_texture_object
*srcObj
=
232 st_texture_object(srcAtt
->Texture
);
233 struct st_renderbuffer
*dstRb
=
234 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
235 struct pipe_surface
*dstSurf
= dstRb
->surface
;
240 util_blit_pixels(st
->blit
, srcObj
->pt
, srcAtt
->TextureLevel
,
241 srcX0
, srcY0
, srcX1
, srcY1
,
242 srcAtt
->Zoffset
+ srcAtt
->CubeMapFace
,
243 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
247 struct st_renderbuffer
*srcRb
=
248 st_renderbuffer(readFB
->_ColorReadBuffer
);
249 struct st_renderbuffer
*dstRb
=
250 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
251 struct pipe_surface
*srcSurf
= srcRb
->surface
;
252 struct pipe_surface
*dstSurf
= dstRb
->surface
;
254 util_blit_pixels(st
->blit
,
255 srcRb
->texture
, srcSurf
->u
.tex
.level
,
256 srcX0
, srcY0
, srcX1
, srcY1
,
257 srcSurf
->u
.tex
.first_layer
,
258 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
263 if (mask
& depthStencil
) {
264 /* depth and/or stencil blit */
266 /* get src/dst depth surfaces */
267 struct gl_renderbuffer_attachment
*srcDepth
=
268 &readFB
->Attachment
[BUFFER_DEPTH
];
269 struct gl_renderbuffer_attachment
*dstDepth
=
270 &drawFB
->Attachment
[BUFFER_DEPTH
];
271 struct gl_renderbuffer_attachment
*srcStencil
=
272 &readFB
->Attachment
[BUFFER_STENCIL
];
273 struct gl_renderbuffer_attachment
*dstStencil
=
274 &drawFB
->Attachment
[BUFFER_STENCIL
];
276 struct st_renderbuffer
*srcDepthRb
=
277 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
278 struct st_renderbuffer
*dstDepthRb
=
279 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
280 struct pipe_surface
*dstDepthSurf
=
281 dstDepthRb
? dstDepthRb
->surface
: NULL
;
283 if ((mask
& depthStencil
) == depthStencil
&&
284 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
285 st_is_depth_stencil_combined(dstDepth
, dstStencil
)) {
287 /* Blitting depth and stencil values between combined
288 * depth/stencil buffers. This is the ideal case for such buffers.
290 util_blit_pixels(st
->blit
,
292 srcDepthRb
->surface
->u
.tex
.level
,
293 srcX0
, srcY0
, srcX1
, srcY1
,
294 srcDepthRb
->surface
->u
.tex
.first_layer
,
295 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
299 /* blitting depth and stencil separately */
301 if (mask
& GL_DEPTH_BUFFER_BIT
) {
302 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
303 srcDepthRb
->surface
->u
.tex
.level
,
304 srcX0
, srcY0
, srcX1
, srcY1
,
305 srcDepthRb
->surface
->u
.tex
.first_layer
,
306 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
310 if (mask
& GL_STENCIL_BUFFER_BIT
) {
311 /* blit stencil only */
312 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
318 /* Restore conditional rendering state. */
319 if (st
->render_condition
) {
320 st
->pipe
->render_condition(st
->pipe
, st
->render_condition
,
327 st_init_blit_functions(struct dd_function_table
*functions
)
329 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
332 #endif /* FEATURE_EXT_framebuffer_blit */