Merge branch 'nouveau-gallium-0.1' into darktama-gallium-0.1
[mesa.git] / src / mesa / pipe / 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 "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 map the 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 struct pipe_surface *ps;
50 uint i;
51
52 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
53 /* check if changing cbuf */
54 if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
55 /* flush old */
56 sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
57 /* unmap old */
58 ps = sp->framebuffer.cbufs[i];
59 if (ps && ps->map)
60 pipe_surface_unmap(ps);
61 /* map new */
62 ps = fb->cbufs[i];
63 if (ps)
64 pipe_surface_map(ps);
65 /* assign new */
66 sp->framebuffer.cbufs[i] = fb->cbufs[i];
67
68 /* update cache */
69 sp_tile_cache_set_surface(sp->cbuf_cache[i], ps);
70 }
71 }
72
73 sp->framebuffer.num_cbufs = fb->num_cbufs;
74
75 /* zbuf changing? */
76 if (sp->framebuffer.zbuf != fb->zbuf) {
77 /* flush old */
78 sp_flush_tile_cache(sp, sp->zbuf_cache);
79 /* unmap old */
80 ps = sp->framebuffer.zbuf;
81 if (ps && ps->map)
82 pipe_surface_unmap(ps);
83 if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) {
84 /* combined z/stencil */
85 sp->framebuffer.sbuf = NULL;
86 }
87 /* map new */
88 ps = fb->zbuf;
89 if (ps)
90 pipe_surface_map(ps);
91 /* assign new */
92 sp->framebuffer.zbuf = fb->zbuf;
93
94 /* update cache */
95 sp_tile_cache_set_surface(sp->zbuf_cache, ps);
96 }
97
98 /* XXX combined depth/stencil here */
99
100 /* sbuf changing? */
101 if (sp->framebuffer.sbuf != fb->sbuf) {
102 /* flush old */
103 sp_flush_tile_cache(sp, sp->sbuf_cache_sep);
104 /* unmap old */
105 ps = sp->framebuffer.sbuf;
106 if (ps && ps->map)
107 pipe_surface_unmap(ps);
108 /* map new */
109 ps = fb->sbuf;
110 if (ps && fb->sbuf != fb->zbuf)
111 pipe_surface_map(ps);
112 /* assign new */
113 sp->framebuffer.sbuf = fb->sbuf;
114
115 /* update cache */
116 if (fb->sbuf != fb->zbuf) {
117 /* separate stencil buf */
118 sp->sbuf_cache = sp->sbuf_cache_sep;
119 sp_tile_cache_set_surface(sp->sbuf_cache, ps);
120 }
121 else {
122 /* combined depth/stencil */
123 sp->sbuf_cache = sp->zbuf_cache;
124 sp_tile_cache_set_surface(sp->sbuf_cache, ps);
125 }
126 }
127
128 sp->dirty |= SP_NEW_FRAMEBUFFER;
129 }
130
131
132
133
134 void
135 softpipe_set_clear_color_state(struct pipe_context *pipe,
136 const struct pipe_clear_color_state *clear)
137 {
138 struct softpipe_context *softpipe = softpipe_context(pipe);
139
140 softpipe->clear_color = *clear; /* struct copy */
141 }