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/texformat.h"
37 #include "shader/program.h"
38 #include "shader/prog_parameter.h"
39 #include "shader/prog_print.h"
41 #include "st_context.h"
42 #include "st_texture.h"
43 #include "st_program.h"
44 #include "st_cb_blit.h"
45 #include "st_cb_fbo.h"
47 #include "util/u_blit.h"
49 #include "cso_cache/cso_context.h"
53 st_init_blit(struct st_context
*st
)
55 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
60 st_destroy_blit(struct st_context
*st
)
62 util_destroy_blit(st
->blit
);
68 st_BlitFramebuffer(GLcontext
*ctx
,
69 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
70 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
71 GLbitfield mask
, GLenum filter
)
73 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
74 GL_STENCIL_BUFFER_BIT
);
75 struct st_context
*st
= ctx
->st
;
76 const uint pFilter
= ((filter
== GL_NEAREST
)
77 ? PIPE_TEX_MIPFILTER_NEAREST
78 : PIPE_TEX_MIPFILTER_LINEAR
);
79 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
80 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
82 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
83 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
84 return; /* nothing to draw/blit */
87 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
88 /* invert Y for dest */
89 dstY0
= drawFB
->Height
- dstY0
;
90 dstY1
= drawFB
->Height
- dstY1
;
93 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
94 /* invert Y for src */
95 srcY0
= readFB
->Height
- srcY0
;
96 srcY1
= readFB
->Height
- srcY1
;
99 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
100 /* Both src and dst are upside down. Swap Y to make it
101 * right-side up to increase odds of using a fast path.
102 * Recall that all Gallium raster coords have Y=0=top.
113 if (mask
& GL_COLOR_BUFFER_BIT
) {
114 struct gl_renderbuffer_attachment
*srcAtt
=
115 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
117 if(srcAtt
->Type
== GL_TEXTURE
) {
118 struct pipe_screen
*screen
= ctx
->st
->pipe
->screen
;
119 const struct st_texture_object
*srcObj
=
120 st_texture_object(srcAtt
->Texture
);
121 struct st_renderbuffer
*dstRb
=
122 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
123 struct pipe_surface
*srcSurf
;
124 struct pipe_surface
*dstSurf
= dstRb
->surface
;
129 srcSurf
= screen
->get_tex_surface(screen
,
132 srcAtt
->TextureLevel
,
134 PIPE_BUFFER_USAGE_GPU_READ
);
138 util_blit_pixels(st
->blit
,
139 srcSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
140 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
143 pipe_surface_reference(&srcSurf
, NULL
);
146 struct st_renderbuffer
*srcRb
=
147 st_renderbuffer(readFB
->_ColorReadBuffer
);
148 struct st_renderbuffer
*dstRb
=
149 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
150 struct pipe_surface
*srcSurf
= srcRb
->surface
;
151 struct pipe_surface
*dstSurf
= dstRb
->surface
;
153 util_blit_pixels(st
->blit
,
154 srcSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
155 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
160 if (mask
& depthStencil
) {
161 /* depth and/or stencil blit */
163 /* get src/dst depth surfaces */
164 struct st_renderbuffer
*srcDepthRb
=
165 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
166 struct st_renderbuffer
*dstDepthRb
=
167 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
168 struct pipe_surface
*srcDepthSurf
=
169 srcDepthRb
? srcDepthRb
->surface
: NULL
;
170 struct pipe_surface
*dstDepthSurf
=
171 dstDepthRb
? dstDepthRb
->surface
: NULL
;
173 /* get src/dst stencil surfaces */
174 struct st_renderbuffer
*srcStencilRb
=
175 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
176 struct st_renderbuffer
*dstStencilRb
=
177 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
178 struct pipe_surface
*srcStencilSurf
=
179 srcStencilRb
? srcStencilRb
->surface
: NULL
;
180 struct pipe_surface
*dstStencilSurf
=
181 dstStencilRb
? dstStencilRb
->surface
: NULL
;
183 if ((mask
& depthStencil
) == depthStencil
&&
184 srcDepthSurf
== srcStencilSurf
&&
185 dstDepthSurf
== dstStencilSurf
) {
186 /* Blitting depth and stencil values between combined
187 * depth/stencil buffers. This is the ideal case for such buffers.
189 util_blit_pixels(st
->blit
,
190 srcDepthSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
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");
213 st_init_blit_functions(struct dd_function_table
*functions
)
215 #if FEATURE_EXT_framebuffer_blit
216 functions
->BlitFramebuffer
= st_BlitFramebuffer
;