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"
37 #include "st_context.h"
38 #include "st_texture.h"
39 #include "st_cb_blit.h"
40 #include "st_cb_fbo.h"
42 #include "util/u_blit.h"
46 st_init_blit(struct st_context
*st
)
48 st
->blit
= util_create_blit(st
->pipe
, st
->cso_context
);
53 st_destroy_blit(struct st_context
*st
)
55 util_destroy_blit(st
->blit
);
60 #if FEATURE_EXT_framebuffer_blit
63 st_BlitFramebuffer(struct gl_context
*ctx
,
64 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
65 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
66 GLbitfield mask
, GLenum filter
)
68 const GLbitfield depthStencil
= (GL_DEPTH_BUFFER_BIT
|
69 GL_STENCIL_BUFFER_BIT
);
70 struct st_context
*st
= st_context(ctx
);
71 const uint pFilter
= ((filter
== GL_NEAREST
)
72 ? PIPE_TEX_MIPFILTER_NEAREST
73 : PIPE_TEX_MIPFILTER_LINEAR
);
74 struct gl_framebuffer
*readFB
= ctx
->ReadBuffer
;
75 struct gl_framebuffer
*drawFB
= ctx
->DrawBuffer
;
77 if (!_mesa_clip_blit(ctx
, &srcX0
, &srcY0
, &srcX1
, &srcY1
,
78 &dstX0
, &dstY0
, &dstX1
, &dstY1
)) {
79 return; /* nothing to draw/blit */
82 if (st_fb_orientation(drawFB
) == Y_0_TOP
) {
83 /* invert Y for dest */
84 dstY0
= drawFB
->Height
- dstY0
;
85 dstY1
= drawFB
->Height
- dstY1
;
88 if (st_fb_orientation(readFB
) == Y_0_TOP
) {
89 /* invert Y for src */
90 srcY0
= readFB
->Height
- srcY0
;
91 srcY1
= readFB
->Height
- srcY1
;
94 if (srcY0
> srcY1
&& dstY0
> dstY1
) {
95 /* Both src and dst are upside down. Swap Y to make it
96 * right-side up to increase odds of using a fast path.
97 * Recall that all Gallium raster coords have Y=0=top.
108 if (mask
& GL_COLOR_BUFFER_BIT
) {
109 struct gl_renderbuffer_attachment
*srcAtt
=
110 &readFB
->Attachment
[readFB
->_ColorReadBufferIndex
];
112 if(srcAtt
->Type
== GL_TEXTURE
) {
113 struct st_texture_object
*srcObj
=
114 st_texture_object(srcAtt
->Texture
);
115 struct st_renderbuffer
*dstRb
=
116 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
117 struct pipe_surface
*dstSurf
= dstRb
->surface
;
122 util_blit_pixels(st
->blit
, srcObj
->pt
, srcAtt
->TextureLevel
,
123 srcX0
, srcY0
, srcX1
, srcY1
,
124 srcAtt
->Zoffset
+ srcAtt
->CubeMapFace
,
125 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
129 struct st_renderbuffer
*srcRb
=
130 st_renderbuffer(readFB
->_ColorReadBuffer
);
131 struct st_renderbuffer
*dstRb
=
132 st_renderbuffer(drawFB
->_ColorDrawBuffers
[0]);
133 struct pipe_surface
*srcSurf
= srcRb
->surface
;
134 struct pipe_surface
*dstSurf
= dstRb
->surface
;
136 util_blit_pixels(st
->blit
,
137 srcRb
->texture
, srcSurf
->u
.tex
.level
,
138 srcX0
, srcY0
, srcX1
, srcY1
,
139 srcSurf
->u
.tex
.first_layer
,
140 dstSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
145 if (mask
& depthStencil
) {
146 /* depth and/or stencil blit */
148 /* get src/dst depth surfaces */
149 struct gl_renderbuffer_attachment
*srcDepth
=
150 &readFB
->Attachment
[BUFFER_DEPTH
];
151 struct gl_renderbuffer_attachment
*dstDepth
=
152 &drawFB
->Attachment
[BUFFER_DEPTH
];
153 struct gl_renderbuffer_attachment
*srcStencil
=
154 &readFB
->Attachment
[BUFFER_STENCIL
];
155 struct gl_renderbuffer_attachment
*dstStencil
=
156 &drawFB
->Attachment
[BUFFER_STENCIL
];
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
*dstDepthSurf
=
163 dstDepthRb
? dstDepthRb
->surface
: NULL
;
165 if ((mask
& depthStencil
) == depthStencil
&&
166 st_is_depth_stencil_combined(srcDepth
, srcStencil
) &&
167 st_is_depth_stencil_combined(dstDepth
, dstStencil
)) {
169 /* Blitting depth and stencil values between combined
170 * depth/stencil buffers. This is the ideal case for such buffers.
172 util_blit_pixels(st
->blit
,
174 srcDepthRb
->surface
->u
.tex
.level
,
175 srcX0
, srcY0
, srcX1
, srcY1
,
176 srcDepthRb
->surface
->u
.tex
.first_layer
,
177 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
181 /* blitting depth and stencil separately */
183 if (mask
& GL_DEPTH_BUFFER_BIT
) {
184 util_blit_pixels(st
->blit
, srcDepthRb
->texture
,
185 srcDepthRb
->surface
->u
.tex
.level
,
186 srcX0
, srcY0
, srcX1
, srcY1
,
187 srcDepthRb
->surface
->u
.tex
.first_layer
,
188 dstDepthSurf
, dstX0
, dstY0
, dstX1
, dstY1
,
192 if (mask
& GL_STENCIL_BUFFER_BIT
) {
193 /* blit stencil only */
194 _mesa_problem(ctx
, "st_BlitFramebuffer(STENCIL) not completed");
202 st_init_blit_functions(struct dd_function_table
*functions
)
204 functions
->BlitFramebuffer
= st_BlitFramebuffer
;
207 #endif /* FEATURE_EXT_framebuffer_blit */