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
);
67 #if FEATURE_EXT_framebuffer_blit
69 st_BlitFramebuffer(GLcontext
*ctx
,
70 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
71 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
72 GLbitfield mask
, GLenum filter
)
74 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
75 GL_STENCIL_BUFFER_BIT
);
76 struct st_context
*st
= ctx
->st
;
77 const uint pFilter
= ((filter
== GL_NEAREST
)
78 ? PIPE_TEX_MIPFILTER_NEAREST
79 : PIPE_TEX_MIPFILTER_LINEAR
);
80 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
81 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
83 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
84 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
85 return; /* nothing to draw/blit */
88 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
89 /* invert Y for dest */
90 dstY0
= drawFB
->Height
- dstY0
;
91 dstY1
= drawFB
->Height
- dstY1
;
94 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
95 /* invert Y for src */
96 srcY0
= readFB
->Height
- srcY0
;
97 srcY1
= readFB
->Height
- srcY1
;
100 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
101 /* Both src and dst are upside down. Swap Y to make it
102 * right-side up to increase odds of using a fast path.
103 * Recall that all Gallium raster coords have Y=0=top.
114 if (mask
& GL_COLOR_BUFFER_BIT
) {
115 struct gl_renderbuffer_attachment
*srcAtt
=
116 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
118 if(srcAtt
->Type
== GL_TEXTURE
) {
119 struct pipe_screen
*screen
= ctx
->st
->pipe
->screen
;
120 const struct st_texture_object
*srcObj
=
121 st_texture_object(srcAtt
->Texture
);
122 struct st_renderbuffer
*dstRb
=
123 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
124 struct pipe_surface
*srcSurf
;
125 struct pipe_surface
*dstSurf
= dstRb
->surface
;
130 srcSurf
= screen
->get_tex_surface(screen
,
133 srcAtt
->TextureLevel
,
135 PIPE_BUFFER_USAGE_GPU_READ
);
139 util_blit_pixels(st
->blit
,
140 srcSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
141 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
144 pipe_surface_reference(&srcSurf
, NULL
);
147 struct st_renderbuffer
*srcRb
=
148 st_renderbuffer(readFB
->_ColorReadBuffer
);
149 struct st_renderbuffer
*dstRb
=
150 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
151 struct pipe_surface
*srcSurf
= srcRb
->surface
;
152 struct pipe_surface
*dstSurf
= dstRb
->surface
;
154 util_blit_pixels(st
->blit
,
155 srcSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
156 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
161 if (mask
& depthStencil
) {
162 /* depth and/or stencil blit */
164 /* get src/dst depth surfaces */
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
*srcDepthSurf
=
170 srcDepthRb
? srcDepthRb
->surface
: NULL
;
171 struct pipe_surface
*dstDepthSurf
=
172 dstDepthRb
? dstDepthRb
->surface
: NULL
;
174 /* get src/dst stencil surfaces */
175 struct st_renderbuffer
*srcStencilRb
=
176 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
177 struct st_renderbuffer
*dstStencilRb
=
178 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
179 struct pipe_surface
*srcStencilSurf
=
180 srcStencilRb
? srcStencilRb
->surface
: NULL
;
181 struct pipe_surface
*dstStencilSurf
=
182 dstStencilRb
? dstStencilRb
->surface
: NULL
;
184 if ((mask
& depthStencil
) == depthStencil
&&
185 srcDepthSurf
== srcStencilSurf
&&
186 dstDepthSurf
== dstStencilSurf
) {
187 /* Blitting depth and stencil values between combined
188 * depth/stencil buffers. This is the ideal case for such buffers.
190 util_blit_pixels(st
->blit
,
191 srcDepthSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
192 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
196 /* blitting depth and stencil separately */
198 if (mask
& GL_DEPTH_BUFFER_BIT
) {
200 _mesa_problem(ctx
, "st_BlitFramebuffer(DEPTH) not completed");
203 if (mask
& GL_STENCIL_BUFFER_BIT
) {
204 /* blit stencil only */
205 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
210 #endif /* FEATURE_EXT_framebuffer_blit */
215 st_init_blit_functions(struct dd_function_table
*functions
)
217 #if FEATURE_EXT_framebuffer_blit
218 functions
->BlitFramebuffer
= st_BlitFramebuffer
;