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
64 st_BlitFramebuffer(GLcontext
*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 struct pipe_context
*pipe
= st
->pipe
;
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 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
80 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
81 return; /* nothing to draw/blit */
84 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
85 /* invert Y for dest */
86 dstY0
= drawFB
->Height
- dstY0
;
87 dstY1
= drawFB
->Height
- dstY1
;
90 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
91 /* invert Y for src */
92 srcY0
= readFB
->Height
- srcY0
;
93 srcY1
= readFB
->Height
- srcY1
;
96 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
97 /* Both src and dst are upside down. Swap Y to make it
98 * right-side up to increase odds of using a fast path.
99 * Recall that all Gallium raster coords have Y=0=top.
110 if (mask
& GL_COLOR_BUFFER_BIT
) {
111 struct gl_renderbuffer_attachment
*srcAtt
=
112 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
114 if(srcAtt
->Type
== GL_TEXTURE
) {
115 struct st_texture_object
*srcObj
=
116 st_texture_object(srcAtt
->Texture
);
117 struct st_renderbuffer
*dstRb
=
118 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
119 struct pipe_subresource srcSub
;
120 struct pipe_surface
*dstSurf
= dstRb
->surface
;
125 srcSub
.face
= srcAtt
->CubeMapFace
;
126 srcSub
.level
= srcAtt
->TextureLevel
;
128 util_blit_pixels(st
->blit
, srcObj
->pt
, srcSub
,
129 srcX0
, srcY0
, srcX1
, srcY1
, srcAtt
->Zoffset
,
130 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
134 struct st_renderbuffer
*srcRb
=
135 st_renderbuffer(readFB
->_ColorReadBuffer
);
136 struct st_renderbuffer
*dstRb
=
137 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
138 struct pipe_surface
*srcSurf
= srcRb
->surface
;
139 struct pipe_surface
*dstSurf
= dstRb
->surface
;
140 struct pipe_subresource srcSub
;
142 srcSub
.face
= srcSurf
->face
;
143 srcSub
.level
= srcSurf
->level
;
145 util_blit_pixels(st
->blit
,
146 srcRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
148 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
153 if (mask
& depthStencil
) {
154 /* depth and/or stencil blit */
156 /* get src/dst depth surfaces */
157 struct st_renderbuffer
*srcDepthRb
=
158 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
159 struct st_renderbuffer
*dstDepthRb
=
160 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
161 struct pipe_surface
*srcDepthSurf
=
162 srcDepthRb
? srcDepthRb
->surface
: NULL
;
163 struct pipe_surface
*dstDepthSurf
=
164 dstDepthRb
? dstDepthRb
->surface
: NULL
;
166 /* get src/dst stencil surfaces */
167 struct st_renderbuffer
*srcStencilRb
=
168 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
169 struct st_renderbuffer
*dstStencilRb
=
170 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
171 struct pipe_surface
*srcStencilSurf
=
172 srcStencilRb
? srcStencilRb
->surface
: NULL
;
173 struct pipe_surface
*dstStencilSurf
=
174 dstStencilRb
? dstStencilRb
->surface
: NULL
;
176 if ((mask
& depthStencil
) == depthStencil
&&
177 srcDepthSurf
== srcStencilSurf
&&
178 dstDepthSurf
== dstStencilSurf
) {
179 struct pipe_subresource srcSub
;
181 srcSub
.face
= srcDepthRb
->surface
->face
;
182 srcSub
.level
= srcDepthRb
->surface
->level
;
184 /* Blitting depth and stencil values between combined
185 * depth/stencil buffers. This is the ideal case for such buffers.
187 util_blit_pixels(st
->blit
,
188 srcDepthRb
->texture
, srcSub
, srcX0
, srcY0
, srcX1
, srcY1
,
189 srcDepthRb
->surface
->zslice
,
190 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
194 /* blitting depth and stencil separately */
196 if (mask
& GL_DEPTH_BUFFER_BIT
) {
198 _mesa_problem(ctx
, "st_BlitFramebuffer(DEPTH) not completed");
201 if (mask
& GL_STENCIL_BUFFER_BIT
) {
202 /* blit stencil only */
203 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
208 #endif /* FEATURE_EXT_framebuffer_blit */
213 st_init_blit_functions(struct dd_function_table
*functions
)
215 #if FEATURE_EXT_framebuffer_blit
216 functions
->BlitFramebuffer
= st_BlitFramebuffer
;