util: Remove unnecessary headers.
[mesa.git] / src / gallium / auxiliary / util / u_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2008 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 * @file
30 * Copy/blit pixel rect between surfaces
31 *
32 * @author Brian Paul
33 */
34
35
36 #include "pipe/p_context.h"
37 #include "util/u_debug.h"
38 #include "pipe/p_defines.h"
39 #include "util/u_inlines.h"
40 #include "pipe/p_shader_tokens.h"
41 #include "pipe/p_state.h"
42
43 #include "util/u_blit.h"
44 #include "util/u_draw_quad.h"
45 #include "util/u_format.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
48 #include "util/u_sampler.h"
49 #include "util/u_simple_shaders.h"
50 #include "util/u_surface.h"
51
52 #include "cso_cache/cso_context.h"
53
54
55 struct blit_state
56 {
57 struct pipe_context *pipe;
58 struct cso_context *cso;
59
60 struct pipe_blend_state blend;
61 struct pipe_depth_stencil_alpha_state depthstencil;
62 struct pipe_rasterizer_state rasterizer;
63 struct pipe_sampler_state sampler;
64 struct pipe_viewport_state viewport;
65 struct pipe_clip_state clip;
66 struct pipe_vertex_element velem[2];
67
68 void *vs;
69 void *fs[TGSI_WRITEMASK_XYZW + 1];
70
71 struct pipe_resource *vbuf; /**< quad vertices */
72 unsigned vbuf_slot;
73
74 float vertices[4][2][4]; /**< vertex/texcoords for quad */
75 };
76
77
78 /**
79 * Create state object for blit.
80 * Intended to be created once and re-used for many blit() calls.
81 */
82 struct blit_state *
83 util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
84 {
85 struct blit_state *ctx;
86 uint i;
87
88 ctx = CALLOC_STRUCT(blit_state);
89 if (!ctx)
90 return NULL;
91
92 ctx->pipe = pipe;
93 ctx->cso = cso;
94
95 /* disabled blending/masking */
96 memset(&ctx->blend, 0, sizeof(ctx->blend));
97 ctx->blend.rt[0].colormask = PIPE_MASK_RGBA;
98
99 /* no-op depth/stencil/alpha */
100 memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
101
102 /* rasterizer */
103 memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
104 ctx->rasterizer.front_winding = PIPE_WINDING_CW;
105 ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
106 ctx->rasterizer.gl_rasterization_rules = 1;
107
108 /* samplers */
109 memset(&ctx->sampler, 0, sizeof(ctx->sampler));
110 ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
111 ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
112 ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
113 ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
114 ctx->sampler.min_img_filter = 0; /* set later */
115 ctx->sampler.mag_img_filter = 0; /* set later */
116 ctx->sampler.normalized_coords = 1;
117
118 /* vertex elements state */
119 memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2);
120 for (i = 0; i < 2; i++) {
121 ctx->velem[i].src_offset = i * 4 * sizeof(float);
122 ctx->velem[i].instance_divisor = 0;
123 ctx->velem[i].vertex_buffer_index = 0;
124 ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
125 }
126
127 /* vertex shader - still required to provide the linkage between
128 * fragment shader input semantics and vertex_element/buffers.
129 */
130 {
131 const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
132 TGSI_SEMANTIC_GENERIC };
133 const uint semantic_indexes[] = { 0, 0 };
134 ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
135 semantic_indexes);
136 }
137
138 /* fragment shader */
139 ctx->fs[TGSI_WRITEMASK_XYZW] =
140 util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
141 ctx->vbuf = NULL;
142
143 /* init vertex data that doesn't change */
144 for (i = 0; i < 4; i++) {
145 ctx->vertices[i][0][3] = 1.0f; /* w */
146 ctx->vertices[i][1][2] = 0.0f; /* r */
147 ctx->vertices[i][1][3] = 1.0f; /* q */
148 }
149
150 return ctx;
151 }
152
153
154 /**
155 * Destroy a blit context
156 */
157 void
158 util_destroy_blit(struct blit_state *ctx)
159 {
160 struct pipe_context *pipe = ctx->pipe;
161 unsigned i;
162
163 pipe->delete_vs_state(pipe, ctx->vs);
164
165 for (i = 0; i < Elements(ctx->fs); i++)
166 if (ctx->fs[i])
167 pipe->delete_fs_state(pipe, ctx->fs[i]);
168
169 pipe_resource_reference(&ctx->vbuf, NULL);
170
171 FREE(ctx);
172 }
173
174
175 /**
176 * Get offset of next free slot in vertex buffer for quad vertices.
177 */
178 static unsigned
179 get_next_slot( struct blit_state *ctx )
180 {
181 const unsigned max_slots = 4096 / sizeof ctx->vertices;
182
183 if (ctx->vbuf_slot >= max_slots)
184 util_blit_flush( ctx );
185
186 if (!ctx->vbuf) {
187 ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
188 PIPE_BIND_VERTEX_BUFFER,
189 max_slots * sizeof ctx->vertices);
190 }
191
192 return ctx->vbuf_slot++ * sizeof ctx->vertices;
193 }
194
195
196
197
198
199 /**
200 * Setup vertex data for the textured quad we'll draw.
201 * Note: y=0=top
202 */
203 static unsigned
204 setup_vertex_data_tex(struct blit_state *ctx,
205 float x0, float y0, float x1, float y1,
206 float s0, float t0, float s1, float t1,
207 float z)
208 {
209 unsigned offset;
210
211 ctx->vertices[0][0][0] = x0;
212 ctx->vertices[0][0][1] = y0;
213 ctx->vertices[0][0][2] = z;
214 ctx->vertices[0][1][0] = s0; /*s*/
215 ctx->vertices[0][1][1] = t0; /*t*/
216
217 ctx->vertices[1][0][0] = x1;
218 ctx->vertices[1][0][1] = y0;
219 ctx->vertices[1][0][2] = z;
220 ctx->vertices[1][1][0] = s1; /*s*/
221 ctx->vertices[1][1][1] = t0; /*t*/
222
223 ctx->vertices[2][0][0] = x1;
224 ctx->vertices[2][0][1] = y1;
225 ctx->vertices[2][0][2] = z;
226 ctx->vertices[2][1][0] = s1;
227 ctx->vertices[2][1][1] = t1;
228
229 ctx->vertices[3][0][0] = x0;
230 ctx->vertices[3][0][1] = y1;
231 ctx->vertices[3][0][2] = z;
232 ctx->vertices[3][1][0] = s0;
233 ctx->vertices[3][1][1] = t1;
234
235 offset = get_next_slot( ctx );
236
237 pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
238 offset, sizeof(ctx->vertices), ctx->vertices);
239
240 return offset;
241 }
242
243
244 /**
245 * \return TRUE if two regions overlap, FALSE otherwise
246 */
247 static boolean
248 regions_overlap(int srcX0, int srcY0,
249 int srcX1, int srcY1,
250 int dstX0, int dstY0,
251 int dstX1, int dstY1)
252 {
253 if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1))
254 return FALSE; /* src completely left of dst */
255
256 if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1))
257 return FALSE; /* dst completely left of src */
258
259 if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1))
260 return FALSE; /* src completely above dst */
261
262 if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1))
263 return FALSE; /* dst completely above src */
264
265 return TRUE; /* some overlap */
266 }
267
268
269 /**
270 * Copy pixel block from src surface to dst surface.
271 * Overlapping regions are acceptable.
272 * Flipping and stretching are supported.
273 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
274 * \param writemask controls which channels in the dest surface are sourced
275 * from the src surface. Disabled channels are sourced
276 * from (0,0,0,1).
277 * XXX need some control over blitting Z and/or stencil.
278 */
279 void
280 util_blit_pixels_writemask(struct blit_state *ctx,
281 struct pipe_surface *src,
282 struct pipe_sampler_view *src_sampler_view,
283 int srcX0, int srcY0,
284 int srcX1, int srcY1,
285 struct pipe_surface *dst,
286 int dstX0, int dstY0,
287 int dstX1, int dstY1,
288 float z, uint filter,
289 uint writemask)
290 {
291 struct pipe_context *pipe = ctx->pipe;
292 struct pipe_screen *screen = pipe->screen;
293 struct pipe_sampler_view *sampler_view = NULL;
294 struct pipe_framebuffer_state fb;
295 const int srcW = abs(srcX1 - srcX0);
296 const int srcH = abs(srcY1 - srcY0);
297 unsigned offset;
298 boolean overlap;
299 float s0, t0, s1, t1;
300
301 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
302 filter == PIPE_TEX_MIPFILTER_LINEAR);
303
304 assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
305 PIPE_BIND_SAMPLER_VIEW, 0));
306 assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
307 PIPE_BIND_RENDER_TARGET, 0));
308
309 /* do the regions overlap? */
310 overlap = util_same_surface(src, dst) &&
311 regions_overlap(srcX0, srcY0, srcX1, srcY1,
312 dstX0, dstY0, dstX1, dstY1);
313
314 /*
315 * Check for simple case: no format conversion, no flipping, no stretching,
316 * no overlapping.
317 * Filter mode should not matter since there's no stretching.
318 */
319 if (pipe->surface_copy &&
320 dst->format == src->format &&
321 srcX0 < srcX1 &&
322 dstX0 < dstX1 &&
323 srcY0 < srcY1 &&
324 dstY0 < dstY1 &&
325 (dstX1 - dstX0) == (srcX1 - srcX0) &&
326 (dstY1 - dstY0) == (srcY1 - srcY0) &&
327 !overlap) {
328 pipe->surface_copy(pipe,
329 dst, dstX0, dstY0, /* dest */
330 src, srcX0, srcY0, /* src */
331 srcW, srcH); /* size */
332 return;
333 }
334
335 assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
336 PIPE_BIND_RENDER_TARGET, 0));
337
338 /* Create a temporary texture when src and dest alias or when src
339 * is anything other than a single-level 2d texture.
340 *
341 * This can still be improved upon.
342 */
343 if (util_same_surface(src, dst) ||
344 src->texture->target != PIPE_TEXTURE_2D ||
345 src->texture->last_level != 0)
346 {
347 struct pipe_resource texTemp;
348 struct pipe_resource *tex;
349 struct pipe_sampler_view sv_templ;
350 struct pipe_surface *texSurf;
351 const int srcLeft = MIN2(srcX0, srcX1);
352 const int srcTop = MIN2(srcY0, srcY1);
353
354 if (srcLeft != srcX0) {
355 /* left-right flip */
356 int tmp = dstX0;
357 dstX0 = dstX1;
358 dstX1 = tmp;
359 }
360
361 if (srcTop != srcY0) {
362 /* up-down flip */
363 int tmp = dstY0;
364 dstY0 = dstY1;
365 dstY1 = tmp;
366 }
367
368 /* create temp texture */
369 memset(&texTemp, 0, sizeof(texTemp));
370 texTemp.target = PIPE_TEXTURE_2D;
371 texTemp.format = src->format;
372 texTemp.last_level = 0;
373 texTemp.width0 = srcW;
374 texTemp.height0 = srcH;
375 texTemp.depth0 = 1;
376 texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
377
378 tex = screen->resource_create(screen, &texTemp);
379 if (!tex)
380 return;
381
382 u_sampler_view_default_template(&sv_templ, tex, tex->format);
383
384 sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, tex, &sv_templ);
385 if (!sampler_view) {
386 pipe_resource_reference(&tex, NULL);
387 return;
388 }
389
390 texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
391 PIPE_BIND_BLIT_DESTINATION);
392
393 /* load temp texture */
394 if (pipe->surface_copy) {
395 pipe->surface_copy(pipe,
396 texSurf, 0, 0, /* dest */
397 src, srcLeft, srcTop, /* src */
398 srcW, srcH); /* size */
399 } else {
400 util_surface_copy(pipe, FALSE,
401 texSurf, 0, 0, /* dest */
402 src, srcLeft, srcTop, /* src */
403 srcW, srcH); /* size */
404 }
405
406 /* free the surface, update the texture if necessary.
407 */
408 pipe_surface_reference(&texSurf, NULL);
409 s0 = 0.0f;
410 s1 = 1.0f;
411 t0 = 0.0f;
412 t1 = 1.0f;
413
414 pipe_resource_reference(&tex, NULL);
415 }
416 else {
417 pipe_sampler_view_reference(&sampler_view, src_sampler_view);
418 s0 = srcX0 / (float)src->texture->width0;
419 s1 = srcX1 / (float)src->texture->width0;
420 t0 = srcY0 / (float)src->texture->height0;
421 t1 = srcY1 / (float)src->texture->height0;
422 }
423
424
425
426 /* save state (restored below) */
427 cso_save_blend(ctx->cso);
428 cso_save_depth_stencil_alpha(ctx->cso);
429 cso_save_rasterizer(ctx->cso);
430 cso_save_samplers(ctx->cso);
431 cso_save_fragment_sampler_views(ctx->cso);
432 cso_save_viewport(ctx->cso);
433 cso_save_framebuffer(ctx->cso);
434 cso_save_fragment_shader(ctx->cso);
435 cso_save_vertex_shader(ctx->cso);
436 cso_save_clip(ctx->cso);
437 cso_save_vertex_elements(ctx->cso);
438
439 /* set misc state we care about */
440 cso_set_blend(ctx->cso, &ctx->blend);
441 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
442 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
443 cso_set_clip(ctx->cso, &ctx->clip);
444 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
445
446 /* sampler */
447 ctx->sampler.min_img_filter = filter;
448 ctx->sampler.mag_img_filter = filter;
449 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
450 cso_single_sampler_done(ctx->cso);
451
452 /* viewport */
453 ctx->viewport.scale[0] = 0.5f * dst->width;
454 ctx->viewport.scale[1] = 0.5f * dst->height;
455 ctx->viewport.scale[2] = 0.5f;
456 ctx->viewport.scale[3] = 1.0f;
457 ctx->viewport.translate[0] = 0.5f * dst->width;
458 ctx->viewport.translate[1] = 0.5f * dst->height;
459 ctx->viewport.translate[2] = 0.5f;
460 ctx->viewport.translate[3] = 0.0f;
461 cso_set_viewport(ctx->cso, &ctx->viewport);
462
463 /* texture */
464 cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
465
466 if (ctx->fs[writemask] == NULL)
467 ctx->fs[writemask] =
468 util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
469 writemask);
470
471 /* shaders */
472 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
473 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
474
475 /* drawing dest */
476 memset(&fb, 0, sizeof(fb));
477 fb.width = dst->width;
478 fb.height = dst->height;
479 fb.nr_cbufs = 1;
480 fb.cbufs[0] = dst;
481 cso_set_framebuffer(ctx->cso, &fb);
482
483 /* draw quad */
484 offset = setup_vertex_data_tex(ctx,
485 (float) dstX0 / dst->width * 2.0f - 1.0f,
486 (float) dstY0 / dst->height * 2.0f - 1.0f,
487 (float) dstX1 / dst->width * 2.0f - 1.0f,
488 (float) dstY1 / dst->height * 2.0f - 1.0f,
489 s0, t0,
490 s1, t1,
491 z);
492
493 util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset,
494 PIPE_PRIM_TRIANGLE_FAN,
495 4, /* verts */
496 2); /* attribs/vert */
497
498 /* restore state we changed */
499 cso_restore_blend(ctx->cso);
500 cso_restore_depth_stencil_alpha(ctx->cso);
501 cso_restore_rasterizer(ctx->cso);
502 cso_restore_samplers(ctx->cso);
503 cso_restore_fragment_sampler_views(ctx->cso);
504 cso_restore_viewport(ctx->cso);
505 cso_restore_framebuffer(ctx->cso);
506 cso_restore_fragment_shader(ctx->cso);
507 cso_restore_vertex_shader(ctx->cso);
508 cso_restore_clip(ctx->cso);
509 cso_restore_vertex_elements(ctx->cso);
510
511 pipe_sampler_view_reference(&sampler_view, NULL);
512 }
513
514
515 void
516 util_blit_pixels(struct blit_state *ctx,
517 struct pipe_surface *src,
518 struct pipe_sampler_view *src_sampler_view,
519 int srcX0, int srcY0,
520 int srcX1, int srcY1,
521 struct pipe_surface *dst,
522 int dstX0, int dstY0,
523 int dstX1, int dstY1,
524 float z, uint filter )
525 {
526 util_blit_pixels_writemask( ctx, src, src_sampler_view,
527 srcX0, srcY0,
528 srcX1, srcY1,
529 dst,
530 dstX0, dstY0,
531 dstX1, dstY1,
532 z, filter,
533 TGSI_WRITEMASK_XYZW );
534 }
535
536
537 /* Release vertex buffer at end of frame to avoid synchronous
538 * rendering.
539 */
540 void util_blit_flush( struct blit_state *ctx )
541 {
542 pipe_resource_reference(&ctx->vbuf, NULL);
543 ctx->vbuf_slot = 0;
544 }
545
546
547
548 /**
549 * Copy pixel block from src texture to dst surface.
550 * Overlapping regions are acceptable.
551 *
552 * XXX Should support selection of level.
553 * XXX need some control over blitting Z and/or stencil.
554 */
555 void
556 util_blit_pixels_tex(struct blit_state *ctx,
557 struct pipe_sampler_view *src_sampler_view,
558 int srcX0, int srcY0,
559 int srcX1, int srcY1,
560 struct pipe_surface *dst,
561 int dstX0, int dstY0,
562 int dstX1, int dstY1,
563 float z, uint filter)
564 {
565 struct pipe_framebuffer_state fb;
566 float s0, t0, s1, t1;
567 unsigned offset;
568 struct pipe_resource *tex = src_sampler_view->texture;
569
570 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
571 filter == PIPE_TEX_MIPFILTER_LINEAR);
572
573 assert(tex);
574 assert(tex->width0 != 0);
575 assert(tex->height0 != 0);
576
577 s0 = srcX0 / (float)tex->width0;
578 s1 = srcX1 / (float)tex->width0;
579 t0 = srcY0 / (float)tex->height0;
580 t1 = srcY1 / (float)tex->height0;
581
582 assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
583 PIPE_TEXTURE_2D,
584 PIPE_BIND_RENDER_TARGET,
585 0));
586
587 /* save state (restored below) */
588 cso_save_blend(ctx->cso);
589 cso_save_depth_stencil_alpha(ctx->cso);
590 cso_save_rasterizer(ctx->cso);
591 cso_save_samplers(ctx->cso);
592 cso_save_fragment_sampler_views(ctx->cso);
593 cso_save_framebuffer(ctx->cso);
594 cso_save_fragment_shader(ctx->cso);
595 cso_save_vertex_shader(ctx->cso);
596 cso_save_clip(ctx->cso);
597 cso_save_vertex_elements(ctx->cso);
598
599 /* set misc state we care about */
600 cso_set_blend(ctx->cso, &ctx->blend);
601 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
602 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
603 cso_set_clip(ctx->cso, &ctx->clip);
604 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
605
606 /* sampler */
607 ctx->sampler.min_img_filter = filter;
608 ctx->sampler.mag_img_filter = filter;
609 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
610 cso_single_sampler_done(ctx->cso);
611
612 /* viewport */
613 ctx->viewport.scale[0] = 0.5f * dst->width;
614 ctx->viewport.scale[1] = 0.5f * dst->height;
615 ctx->viewport.scale[2] = 0.5f;
616 ctx->viewport.scale[3] = 1.0f;
617 ctx->viewport.translate[0] = 0.5f * dst->width;
618 ctx->viewport.translate[1] = 0.5f * dst->height;
619 ctx->viewport.translate[2] = 0.5f;
620 ctx->viewport.translate[3] = 0.0f;
621 cso_set_viewport(ctx->cso, &ctx->viewport);
622
623 /* texture */
624 cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
625
626 /* shaders */
627 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
628 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
629
630 /* drawing dest */
631 memset(&fb, 0, sizeof(fb));
632 fb.width = dst->width;
633 fb.height = dst->height;
634 fb.nr_cbufs = 1;
635 fb.cbufs[0] = dst;
636 cso_set_framebuffer(ctx->cso, &fb);
637
638 /* draw quad */
639 offset = setup_vertex_data_tex(ctx,
640 (float) dstX0 / dst->width * 2.0f - 1.0f,
641 (float) dstY0 / dst->height * 2.0f - 1.0f,
642 (float) dstX1 / dst->width * 2.0f - 1.0f,
643 (float) dstY1 / dst->height * 2.0f - 1.0f,
644 s0, t0, s1, t1,
645 z);
646
647 util_draw_vertex_buffer(ctx->pipe,
648 ctx->vbuf, offset,
649 PIPE_PRIM_TRIANGLE_FAN,
650 4, /* verts */
651 2); /* attribs/vert */
652
653 /* restore state we changed */
654 cso_restore_blend(ctx->cso);
655 cso_restore_depth_stencil_alpha(ctx->cso);
656 cso_restore_rasterizer(ctx->cso);
657 cso_restore_samplers(ctx->cso);
658 cso_restore_fragment_sampler_views(ctx->cso);
659 cso_restore_framebuffer(ctx->cso);
660 cso_restore_fragment_shader(ctx->cso);
661 cso_restore_vertex_shader(ctx->cso);
662 cso_restore_clip(ctx->cso);
663 cso_restore_vertex_elements(ctx->cso);
664 }