Merge branch 'master' of git+ssh://git.freedesktop.org/git/mesa/mesa into gallium-0.2
[mesa.git] / src / gallium / drivers / softpipe / sp_state_surface.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 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30 #include "pipe/p_inlines.h"
31
32 #include "sp_context.h"
33 #include "sp_state.h"
34 #include "sp_surface.h"
35 #include "sp_tile_cache.h"
36
37
38 /**
39 * XXX this might get moved someday
40 * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer.
41 * Here, we flush the old surfaces and update the tile cache to point to the new
42 * surfaces.
43 */
44 void
45 softpipe_set_framebuffer_state(struct pipe_context *pipe,
46 const struct pipe_framebuffer_state *fb)
47 {
48 struct softpipe_context *sp = softpipe_context(pipe);
49 uint i;
50
51 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
52 /* check if changing cbuf */
53 if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
54 /* flush old */
55 sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
56
57 /* assign new */
58 sp->framebuffer.cbufs[i] = fb->cbufs[i];
59
60 /* update cache */
61 sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
62 }
63 }
64
65 sp->framebuffer.num_cbufs = fb->num_cbufs;
66
67 /* zbuf changing? */
68 if (sp->framebuffer.zsbuf != fb->zsbuf) {
69 /* flush old */
70 sp_flush_tile_cache(sp, sp->zsbuf_cache);
71
72 /* assign new */
73 sp->framebuffer.zsbuf = fb->zsbuf;
74
75 /* update cache */
76 sp_tile_cache_set_surface(sp->zsbuf_cache, fb->zsbuf);
77 }
78
79 #if 0
80 /* XXX combined depth/stencil here */
81
82 /* sbuf changing? */
83 if (sp->framebuffer.sbuf != fb->sbuf) {
84 /* flush old */
85 sp_flush_tile_cache(sp, sp->sbuf_cache_sep);
86
87 /* assign new */
88 sp->framebuffer.sbuf = fb->sbuf;
89
90 /* update cache */
91 if (fb->sbuf != fb->zbuf) {
92 /* separate stencil buf */
93 sp->sbuf_cache = sp->sbuf_cache_sep;
94 sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
95 }
96 else {
97 /* combined depth/stencil */
98 sp->sbuf_cache = sp->zbuf_cache;
99 sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
100 }
101 }
102 #endif
103
104 sp->framebuffer.width = fb->width;
105 sp->framebuffer.height = fb->height;
106
107 sp->dirty |= SP_NEW_FRAMEBUFFER;
108 }