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 "shader/program.h"
38 #include "st_context.h"
39 #include "st_texture.h"
40 #include "st_cb_blit.h"
41 #include "st_cb_fbo.h"
43 #include "util/u_blit.h"
44 #include "util/u_inlines.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(GLcontext
*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 struct pipe_context
*pipe
= st
->pipe
;
74 const uint pFilter
= ((filter
== GL_NEAREST
)
75 ? PIPE_TEX_MIPFILTER_NEAREST
76 : PIPE_TEX_MIPFILTER_LINEAR
);
77 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
78 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
80 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
81 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
82 return; /* nothing to draw/blit */
85 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
86 /* invert Y for dest */
87 dstY0
= drawFB
->Height
- dstY0
;
88 dstY1
= drawFB
->Height
- dstY1
;
91 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
92 /* invert Y for src */
93 srcY0
= readFB
->Height
- srcY0
;
94 srcY1
= readFB
->Height
- srcY1
;
97 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
98 /* Both src and dst are upside down. Swap Y to make it
99 * right-side up to increase odds of using a fast path.
100 * Recall that all Gallium raster coords have Y=0=top.
111 if (mask
& GL_COLOR_BUFFER_BIT
) {
112 struct gl_renderbuffer_attachment
*srcAtt
=
113 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
115 if(srcAtt
->Type
== GL_TEXTURE
) {
116 struct st_texture_object
*srcObj
=
117 st_texture_object(srcAtt
->Texture
);
118 struct st_renderbuffer
*dstRb
=
119 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
120 struct pipe_subresource srcSub
;
121 struct pipe_surface
*dstSurf
= dstRb
->surface
;
126 srcSub
.face
= srcAtt
->CubeMapFace
;
127 srcSub
.level
= srcAtt
->TextureLevel
;
129 util_blit_pixels(st
->blit
, srcObj
->pt
, srcSub
,
130 srcX0
, srcY0
, srcX1
, srcY1
, srcAtt
->Zoffset
,
131 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
135 struct st_renderbuffer
*srcRb
=
136 st_renderbuffer(readFB
->_ColorReadBuffer
);
137 struct st_renderbuffer
*dstRb
=
138 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
139 struct pipe_surface
*srcSurf
= srcRb
->surface
;
140 struct pipe_surface
*dstSurf
= dstRb
->surface
;
141 struct pipe_subresource srcSub
;
143 srcSub
.face
= srcSurf
->face
;
144 srcSub
.level
= srcSurf
->level
;
146 util_blit_pixels(st
->blit
,
147 srcRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
149 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
154 if (mask
& depthStencil
) {
155 /* depth and/or stencil blit */
157 /* get src/dst depth surfaces */
158 struct st_renderbuffer
*srcDepthRb
=
159 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
160 struct st_renderbuffer
*dstDepthRb
=
161 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
162 struct pipe_surface
*srcDepthSurf
=
163 srcDepthRb
? srcDepthRb
->surface
: NULL
;
164 struct pipe_surface
*dstDepthSurf
=
165 dstDepthRb
? dstDepthRb
->surface
: NULL
;
167 /* get src/dst stencil surfaces */
168 struct st_renderbuffer
*srcStencilRb
=
169 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
170 struct st_renderbuffer
*dstStencilRb
=
171 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
172 struct pipe_surface
*srcStencilSurf
=
173 srcStencilRb
? srcStencilRb
->surface
: NULL
;
174 struct pipe_surface
*dstStencilSurf
=
175 dstStencilRb
? dstStencilRb
->surface
: NULL
;
177 if ((mask
& depthStencil
) == depthStencil
&&
178 srcDepthSurf
== srcStencilSurf
&&
179 dstDepthSurf
== dstStencilSurf
) {
180 struct pipe_subresource srcSub
;
182 srcSub
.face
= srcDepthRb
->surface
->face
;
183 srcSub
.level
= srcDepthRb
->surface
->level
;
185 /* Blitting depth and stencil values between combined
186 * depth/stencil buffers. This is the ideal case for such buffers.
188 util_blit_pixels(st
->blit
,
189 srcDepthRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
190 srcDepthRb
->surface
->zslice
,
191 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
195 /* blitting depth and stencil separately */
197 if (mask
& GL_DEPTH_BUFFER_BIT
) {
199 _mesa_problem(ctx
, "st_BlitFramebuffer(DEPTH) not completed");
202 if (mask
& GL_STENCIL_BUFFER_BIT
) {
203 /* blit stencil only */
204 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
212 st_init_blit_functions(struct dd_function_table
*functions
)
214 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
217 #endif /* FEATURE_EXT_framebuffer_blit */