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"
46 st_init_blit(struct st_context
*st
)
48 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
53 st_destroy_blit(struct st_context
*st
)
55 util_destroy_blit(st
->blit
);
60 #if FEATURE_EXT_framebuffer_blit
63 st_BlitFramebuffer(GLcontext
*ctx
,
64 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
65 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
66 GLbitfield mask
, GLenum filter
)
68 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
69 GL_STENCIL_BUFFER_BIT
);
70 struct st_context
*st
= st_context(ctx
);
71 const uint pFilter
= ((filter
== GL_NEAREST
)
72 ? PIPE_TEX_MIPFILTER_NEAREST
73 : PIPE_TEX_MIPFILTER_LINEAR
);
74 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
75 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
77 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
78 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
79 return; /* nothing to draw/blit */
82 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
83 /* invert Y for dest */
84 dstY0
= drawFB
->Height
- dstY0
;
85 dstY1
= drawFB
->Height
- dstY1
;
88 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
89 /* invert Y for src */
90 srcY0
= readFB
->Height
- srcY0
;
91 srcY1
= readFB
->Height
- srcY1
;
94 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
95 /* Both src and dst are upside down. Swap Y to make it
96 * right-side up to increase odds of using a fast path.
97 * Recall that all Gallium raster coords have Y=0=top.
108 if (mask
& GL_COLOR_BUFFER_BIT
) {
109 struct gl_renderbuffer_attachment
*srcAtt
=
110 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
112 if(srcAtt
->Type
== GL_TEXTURE
) {
113 struct st_texture_object
*srcObj
=
114 st_texture_object(srcAtt
->Texture
);
115 struct st_renderbuffer
*dstRb
=
116 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
117 struct pipe_subresource srcSub
;
118 struct pipe_surface
*dstSurf
= dstRb
->surface
;
123 srcSub
.face
= srcAtt
->CubeMapFace
;
124 srcSub
.level
= srcAtt
->TextureLevel
;
126 util_blit_pixels(st
->blit
, srcObj
->pt
, srcSub
,
127 srcX0
, srcY0
, srcX1
, srcY1
, srcAtt
->Zoffset
,
128 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
132 struct st_renderbuffer
*srcRb
=
133 st_renderbuffer(readFB
->_ColorReadBuffer
);
134 struct st_renderbuffer
*dstRb
=
135 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
136 struct pipe_surface
*srcSurf
= srcRb
->surface
;
137 struct pipe_surface
*dstSurf
= dstRb
->surface
;
138 struct pipe_subresource srcSub
;
140 srcSub
.face
= srcSurf
->face
;
141 srcSub
.level
= srcSurf
->level
;
143 util_blit_pixels(st
->blit
,
144 srcRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
146 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
151 if (mask
& depthStencil
) {
152 /* depth and/or stencil blit */
154 /* get src/dst depth surfaces */
155 struct st_renderbuffer
*srcDepthRb
=
156 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
157 struct st_renderbuffer
*dstDepthRb
=
158 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
159 struct pipe_surface
*srcDepthSurf
=
160 srcDepthRb
? srcDepthRb
->surface
: NULL
;
161 struct pipe_surface
*dstDepthSurf
=
162 dstDepthRb
? dstDepthRb
->surface
: NULL
;
164 /* get src/dst stencil surfaces */
165 struct st_renderbuffer
*srcStencilRb
=
166 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
167 struct st_renderbuffer
*dstStencilRb
=
168 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
169 struct pipe_surface
*srcStencilSurf
=
170 srcStencilRb
? srcStencilRb
->surface
: NULL
;
171 struct pipe_surface
*dstStencilSurf
=
172 dstStencilRb
? dstStencilRb
->surface
: NULL
;
174 if ((mask
& depthStencil
) == depthStencil
&&
175 srcDepthSurf
== srcStencilSurf
&&
176 dstDepthSurf
== dstStencilSurf
) {
177 struct pipe_subresource srcSub
;
179 srcSub
.face
= srcDepthRb
->surface
->face
;
180 srcSub
.level
= srcDepthRb
->surface
->level
;
182 /* Blitting depth and stencil values between combined
183 * depth/stencil buffers. This is the ideal case for such buffers.
185 util_blit_pixels(st
->blit
,
186 srcDepthRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
187 srcDepthRb
->surface
->zslice
,
188 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
192 /* blitting depth and stencil separately */
194 if (mask
& GL_DEPTH_BUFFER_BIT
) {
196 _mesa_problem(ctx
, "st_BlitFramebuffer(DEPTH) not completed");
199 if (mask
& GL_STENCIL_BUFFER_BIT
) {
200 /* blit stencil only */
201 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
209 st_init_blit_functions(struct dd_function_table
*functions
)
211 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
214 #endif /* FEATURE_EXT_framebuffer_blit */