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_program.h"
43 #include "st_cb_blit.h"
44 #include "st_cb_fbo.h"
46 #include "util/u_blit.h"
48 #include "cso_cache/cso_context.h"
52 st_init_blit(struct st_context
*st
)
54 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
59 st_destroy_blit(struct st_context
*st
)
61 util_destroy_blit(st
->blit
);
67 st_BlitFramebuffer(GLcontext
*ctx
,
68 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
69 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
70 GLbitfield mask
, GLenum filter
)
72 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
73 GL_STENCIL_BUFFER_BIT
);
74 struct st_context
*st
= ctx
->st
;
75 const uint pFilter
= ((filter
== GL_NEAREST
)
76 ? PIPE_TEX_MIPFILTER_NEAREST
77 : PIPE_TEX_MIPFILTER_LINEAR
);
78 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
79 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
81 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
82 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
83 return; /* nothing to draw/blit */
86 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
87 /* invert Y for dest */
88 dstY0
= drawFB
->Height
- dstY0
;
89 dstY1
= drawFB
->Height
- dstY1
;
92 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
93 /* invert Y for src */
94 srcY0
= readFB
->Height
- srcY0
;
95 srcY1
= readFB
->Height
- srcY1
;
98 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
99 /* Both src and dst are upside down. Swap Y to make it
100 * right-side up to increase odds of using a fast path.
101 * Recall that all Gallium raster coords have Y=0=top.
112 if (mask
& GL_COLOR_BUFFER_BIT
) {
113 struct st_renderbuffer
*srcRb
=
114 st_renderbuffer(readFB
->_ColorReadBuffer
);
115 struct st_renderbuffer
*dstRb
=
116 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
117 struct pipe_surface
*srcSurf
= srcRb
->surface
;
118 struct pipe_surface
*dstSurf
= dstRb
->surface
;
120 util_blit_pixels(st
->blit
,
121 srcSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
122 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
126 if (mask
& depthStencil
) {
127 /* depth and/or stencil blit */
129 /* get src/dst depth surfaces */
130 struct st_renderbuffer
*srcDepthRb
=
131 st_renderbuffer(readFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
132 struct st_renderbuffer
*dstDepthRb
=
133 st_renderbuffer(drawFB
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
134 struct pipe_surface
*srcDepthSurf
=
135 srcDepthRb
? srcDepthRb
->surface
: NULL
;
136 struct pipe_surface
*dstDepthSurf
=
137 dstDepthRb
? dstDepthRb
->surface
: NULL
;
139 /* get src/dst stencil surfaces */
140 struct st_renderbuffer
*srcStencilRb
=
141 st_renderbuffer(readFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
142 struct st_renderbuffer
*dstStencilRb
=
143 st_renderbuffer(drawFB
->Attachment
[BUFFER_STENCIL
].Renderbuffer
);
144 struct pipe_surface
*srcStencilSurf
=
145 srcStencilRb
? srcStencilRb
->surface
: NULL
;
146 struct pipe_surface
*dstStencilSurf
=
147 dstStencilRb
? dstStencilRb
->surface
: NULL
;
149 if ((mask
& depthStencil
) == depthStencil
&&
150 srcDepthSurf
== srcStencilSurf
&&
151 dstDepthSurf
== dstStencilSurf
) {
152 /* Blitting depth and stencil values between combined
153 * depth/stencil buffers. This is the ideal case for such buffers.
155 util_blit_pixels(st
->blit
,
156 srcDepthSurf
, srcX0
, srcY0
, srcX1
, srcY1
,
157 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
161 /* blitting depth and stencil separately */
163 if (mask
& GL_DEPTH_BUFFER_BIT
) {
165 _mesa_problem(ctx
, "st_BlitFramebuffer(DEPTH) not completed");
168 if (mask
& GL_STENCIL_BUFFER_BIT
) {
169 /* blit stencil only */
170 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
179 st_init_blit_functions(struct dd_function_table
*functions
)
181 #if FEATURE_EXT_framebuffer_blit
182 functions
->BlitFramebuffer
= st_BlitFramebuffer
;