mesa: Fix compilation errors and warnings when features are disabled.
[mesa.git] / src / mesa / state_tracker / st_cb_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Brian Paul
31 */
32
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"
40
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"
46
47 #include "util/u_blit.h"
48
49 #include "cso_cache/cso_context.h"
50
51
52 void
53 st_init_blit(struct st_context *st)
54 {
55 st->blit = util_create_blit(st->pipe, st->cso_context);
56 }
57
58
59 void
60 st_destroy_blit(struct st_context *st)
61 {
62 util_destroy_blit(st->blit);
63 st->blit = NULL;
64 }
65
66
67 #if FEATURE_EXT_framebuffer_blit
68 static void
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)
73 {
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;
82
83 if (!_mesa_clip_blit(ctx, &srcX0, &srcY0, &srcX1, &srcY1,
84 &dstX0, &dstY0, &dstX1, &dstY1)) {
85 return; /* nothing to draw/blit */
86 }
87
88 if (st_fb_orientation(drawFB) == Y_0_TOP) {
89 /* invert Y for dest */
90 dstY0 = drawFB->Height - dstY0;
91 dstY1 = drawFB->Height - dstY1;
92 }
93
94 if (st_fb_orientation(readFB) == Y_0_TOP) {
95 /* invert Y for src */
96 srcY0 = readFB->Height - srcY0;
97 srcY1 = readFB->Height - srcY1;
98 }
99
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.
104 */
105 GLint tmp;
106 tmp = srcY0;
107 srcY0 = srcY1;
108 srcY1 = tmp;
109 tmp = dstY0;
110 dstY0 = dstY1;
111 dstY1 = tmp;
112 }
113
114 if (mask & GL_COLOR_BUFFER_BIT) {
115 struct gl_renderbuffer_attachment *srcAtt =
116 &readFB->Attachment[readFB->_ColorReadBufferIndex];
117
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;
126
127 if (!srcObj->pt)
128 return;
129
130 srcSurf = screen->get_tex_surface(screen,
131 srcObj->pt,
132 srcAtt->CubeMapFace,
133 srcAtt->TextureLevel,
134 srcAtt->Zoffset,
135 PIPE_BUFFER_USAGE_GPU_READ);
136 if(!srcSurf)
137 return;
138
139 util_blit_pixels(st->blit,
140 srcSurf, srcX0, srcY0, srcX1, srcY1,
141 dstSurf, dstX0, dstY0, dstX1, dstY1,
142 0.0, pFilter);
143
144 pipe_surface_reference(&srcSurf, NULL);
145 }
146 else {
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;
153
154 util_blit_pixels(st->blit,
155 srcSurf, srcX0, srcY0, srcX1, srcY1,
156 dstSurf, dstX0, dstY0, dstX1, dstY1,
157 0.0, pFilter);
158 }
159 }
160
161 if (mask & depthStencil) {
162 /* depth and/or stencil blit */
163
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;
173
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;
183
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.
189 */
190 util_blit_pixels(st->blit,
191 srcDepthSurf, srcX0, srcY0, srcX1, srcY1,
192 dstDepthSurf, dstX0, dstY0, dstX1, dstY1,
193 0.0, pFilter);
194 }
195 else {
196 /* blitting depth and stencil separately */
197
198 if (mask & GL_DEPTH_BUFFER_BIT) {
199 /* blit Z only */
200 _mesa_problem(ctx, "st_BlitFramebuffer(DEPTH) not completed");
201 }
202
203 if (mask & GL_STENCIL_BUFFER_BIT) {
204 /* blit stencil only */
205 _mesa_problem(ctx, "st_BlitFramebuffer(STENCIL) not completed");
206 }
207 }
208 }
209 }
210 #endif /* FEATURE_EXT_framebuffer_blit */
211
212
213
214 void
215 st_init_blit_functions(struct dd_function_table *functions)
216 {
217 #if FEATURE_EXT_framebuffer_blit
218 functions->BlitFramebuffer = st_BlitFramebuffer;
219 #endif
220 }