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(struct gl_context
*ctx
,
66 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
67 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
68 GLbitfield mask
, GLenum filter
)
70 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
71 GL_STENCIL_BUFFER_BIT
);
72 struct st_context
*st
= st_context(ctx
);
73 const uint pFilter
= ((filter
== GL_NEAREST
)
74 ? PIPE_TEX_MIPFILTER_NEAREST
75 : PIPE_TEX_MIPFILTER_LINEAR
);
76 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
77 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
79 st_validate_state(st
);
81 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
82 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
83 return; /* nothing to draw/blit */
86 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
87 /* invert Y for dest */
88 dstY0
= drawFB
->Height
- dstY0
;
89 dstY1
= drawFB
->Height
- dstY1
;
92 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
93 /* invert Y for src */
94 srcY0
= readFB
->Height
- srcY0
;
95 srcY1
= readFB
->Height
- srcY1
;
98 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
99 /* Both src and dst are upside down. Swap Y to make it
100 * right-side up to increase odds of using a fast path.
101 * Recall that all Gallium raster coords have Y=0=top.
112 /* Disable conditional rendering. */
113 if (st
->render_condition
) {
114 st
->pipe
->render_condition(st
->pipe
, NULL
, 0);
117 if (mask
& GL_COLOR_BUFFER_BIT
) {
118 struct gl_renderbuffer_attachment
*srcAtt
=
119 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
121 if(srcAtt
->Type
== GL_TEXTURE
) {
122 struct st_texture_object
*srcObj
=
123 st_texture_object(srcAtt
->Texture
);
124 struct st_renderbuffer
*dstRb
=
125 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
126 struct pipe_surface
*dstSurf
= dstRb
->surface
;
131 util_blit_pixels(st
->blit
, srcObj
->pt
, srcAtt
->TextureLevel
,
132 srcX0
, srcY0
, srcX1
, srcY1
,
133 srcAtt
->Zoffset
+ srcAtt
->CubeMapFace
,
134 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
138 struct st_renderbuffer
*srcRb
=
139 st_renderbuffer(readFB
->_ColorReadBuffer
);
140 struct st_renderbuffer
*dstRb
=
141 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
142 struct pipe_surface
*srcSurf
= srcRb
->surface
;
143 struct pipe_surface
*dstSurf
= dstRb
->surface
;
145 util_blit_pixels(st
->blit
,
146 srcRb
->texture
, srcSurf
->u
.tex
.level
,
147 srcX0
, srcY0
, srcX1
, srcY1
,
148 srcSurf
->u
.tex
.first_layer
,
149 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
154 if (mask
& depthStencil
) {
155 /* depth and/or stencil blit */
157 /* get src/dst depth surfaces */
158 struct gl_renderbuffer_attachment
*srcDepth
=
159 &readFB
->Attachment
[BUFFER_DEPTH
];
160 struct gl_renderbuffer_attachment
*dstDepth
=
161 &drawFB
->Attachment
[BUFFER_DEPTH
];
162 struct gl_renderbuffer_attachment
*srcStencil
=
163 &readFB
->Attachment
[BUFFER_STENCIL
];
164 struct gl_renderbuffer_attachment
*dstStencil
=
165 &drawFB
->Attachment
[BUFFER_STENCIL
];
167 struct st_renderbuffer
*srcDepthRb
=
168 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
169 struct st_renderbuffer
*dstDepthRb
=
170 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
171 struct pipe_surface
*dstDepthSurf
=
172 dstDepthRb
? dstDepthRb
->surface
: NULL
;
174 if ((mask
& depthStencil
) == depthStencil
&&
175 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
176 st_is_depth_stencil_combined(dstDepth
, dstStencil
)) {
178 /* Blitting depth and stencil values between combined
179 * depth/stencil buffers. This is the ideal case for such buffers.
181 util_blit_pixels(st
->blit
,
183 srcDepthRb
->surface
->u
.tex
.level
,
184 srcX0
, srcY0
, srcX1
, srcY1
,
185 srcDepthRb
->surface
->u
.tex
.first_layer
,
186 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
190 /* blitting depth and stencil separately */
192 if (mask
& GL_DEPTH_BUFFER_BIT
) {
193 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
194 srcDepthRb
->surface
->u
.tex
.level
,
195 srcX0
, srcY0
, srcX1
, srcY1
,
196 srcDepthRb
->surface
->u
.tex
.first_layer
,
197 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
201 if (mask
& GL_STENCIL_BUFFER_BIT
) {
202 /* blit stencil only */
203 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
209 /* Restore conditional rendering state. */
210 if (st
->render_condition
) {
211 st
->pipe
->render_condition(st
->pipe
, st
->render_condition
,
218 st_init_blit_functions(struct dd_function_table
*functions
)
220 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
223 #endif /* FEATURE_EXT_framebuffer_blit */