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"
37 #include "st_context.h"
38 #include "st_texture.h"
39 #include "st_cb_blit.h"
40 #include "st_cb_fbo.h"
42 #include "util/u_blit.h"
43 #include "util/u_inlines.h"
47 st_init_blit(struct st_context
*st
)
49 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
54 st_destroy_blit(struct st_context
*st
)
56 util_destroy_blit(st
->blit
);
61 #if FEATURE_EXT_framebuffer_blit
64 st_BlitFramebuffer(struct gl_context
*ctx
,
65 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
66 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
67 GLbitfield mask
, GLenum filter
)
69 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
70 GL_STENCIL_BUFFER_BIT
);
71 struct st_context
*st
= st_context(ctx
);
72 const uint pFilter
= ((filter
== GL_NEAREST
)
73 ? PIPE_TEX_MIPFILTER_NEAREST
74 : PIPE_TEX_MIPFILTER_LINEAR
);
75 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
76 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
78 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
79 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
80 return; /* nothing to draw/blit */
83 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
84 /* invert Y for dest */
85 dstY0
= drawFB
->Height
- dstY0
;
86 dstY1
= drawFB
->Height
- dstY1
;
89 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
90 /* invert Y for src */
91 srcY0
= readFB
->Height
- srcY0
;
92 srcY1
= readFB
->Height
- srcY1
;
95 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
96 /* Both src and dst are upside down. Swap Y to make it
97 * right-side up to increase odds of using a fast path.
98 * Recall that all Gallium raster coords have Y=0=top.
109 if (mask
& GL_COLOR_BUFFER_BIT
) {
110 struct gl_renderbuffer_attachment
*srcAtt
=
111 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
113 if(srcAtt
->Type
== GL_TEXTURE
) {
114 struct st_texture_object
*srcObj
=
115 st_texture_object(srcAtt
->Texture
);
116 struct st_renderbuffer
*dstRb
=
117 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
118 struct pipe_subresource srcSub
;
119 struct pipe_surface
*dstSurf
= dstRb
->surface
;
124 srcSub
.face
= srcAtt
->CubeMapFace
;
125 srcSub
.level
= srcAtt
->TextureLevel
;
127 util_blit_pixels(st
->blit
, srcObj
->pt
, srcSub
,
128 srcX0
, srcY0
, srcX1
, srcY1
, srcAtt
->Zoffset
,
129 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
133 struct st_renderbuffer
*srcRb
=
134 st_renderbuffer(readFB
->_ColorReadBuffer
);
135 struct st_renderbuffer
*dstRb
=
136 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
137 struct pipe_surface
*srcSurf
= srcRb
->surface
;
138 struct pipe_surface
*dstSurf
= dstRb
->surface
;
139 struct pipe_subresource srcSub
;
141 srcSub
.face
= srcSurf
->face
;
142 srcSub
.level
= srcSurf
->level
;
144 util_blit_pixels(st
->blit
,
145 srcRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
147 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
152 if (mask
& depthStencil
) {
153 /* depth and/or stencil blit */
155 /* get src/dst depth surfaces */
156 struct gl_renderbuffer_attachment
*srcDepth
=
157 &readFB
->Attachment
[BUFFER_DEPTH
];
158 struct gl_renderbuffer_attachment
*dstDepth
=
159 &drawFB
->Attachment
[BUFFER_DEPTH
];
160 struct gl_renderbuffer_attachment
*srcStencil
=
161 &readFB
->Attachment
[BUFFER_STENCIL
];
162 struct gl_renderbuffer_attachment
*dstStencil
=
163 &drawFB
->Attachment
[BUFFER_STENCIL
];
165 struct st_renderbuffer
*srcDepthRb
=
166 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
167 struct st_renderbuffer
*dstDepthRb
=
168 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
169 struct pipe_surface
*dstDepthSurf
=
170 dstDepthRb
? dstDepthRb
->surface
: NULL
;
172 if ((mask
& depthStencil
) == depthStencil
&&
173 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
174 st_is_depth_stencil_combined(dstDepth
, dstStencil
)) {
176 /* Blitting depth and stencil values between combined
177 * depth/stencil buffers. This is the ideal case for such buffers.
179 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
180 u_subresource(srcDepthRb
->surface
->face
,
181 srcDepthRb
->surface
->level
),
182 srcX0
, srcY0
, srcX1
, srcY1
,
183 srcDepthRb
->surface
->zslice
,
184 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
188 /* blitting depth and stencil separately */
190 if (mask
& GL_DEPTH_BUFFER_BIT
) {
191 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
192 u_subresource(srcDepthRb
->surface
->face
,
193 srcDepthRb
->surface
->level
),
194 srcX0
, srcY0
, srcX1
, srcY1
,
195 srcDepthRb
->surface
->zslice
,
196 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
200 if (mask
& GL_STENCIL_BUFFER_BIT
) {
201 /* blit stencil only */
202 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
210 st_init_blit_functions(struct dd_function_table
*functions
)
212 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
215 #endif /* FEATURE_EXT_framebuffer_blit */