Merge commit 'origin/gallium-master-merge'
[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 #include "draw/draw_context.h"
38
39
40 /**
41 * XXX this might get moved someday
42 * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer.
43 * Here, we flush the old surfaces and update the tile cache to point to the new
44 * surfaces.
45 */
46 void
47 softpipe_set_framebuffer_state(struct pipe_context *pipe,
48 const struct pipe_framebuffer_state *fb)
49 {
50 struct softpipe_context *sp = softpipe_context(pipe);
51 uint i;
52
53 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
54 /* check if changing cbuf */
55 if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
56 /* flush old */
57 sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
58
59 /* assign new */
60 sp->framebuffer.cbufs[i] = fb->cbufs[i];
61
62 /* update cache */
63 sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
64 }
65 }
66
67 sp->framebuffer.nr_cbufs = fb->nr_cbufs;
68
69 /* zbuf changing? */
70 if (sp->framebuffer.zsbuf != fb->zsbuf) {
71 /* flush old */
72 sp_flush_tile_cache(sp, sp->zsbuf_cache);
73
74 /* assign new */
75 sp->framebuffer.zsbuf = fb->zsbuf;
76
77 /* update cache */
78 sp_tile_cache_set_surface(sp->zsbuf_cache, fb->zsbuf);
79 }
80
81 #if 0
82 /* XXX combined depth/stencil here */
83
84 /* sbuf changing? */
85 if (sp->framebuffer.sbuf != fb->sbuf) {
86 /* flush old */
87 sp_flush_tile_cache(sp, sp->sbuf_cache_sep);
88
89 /* assign new */
90 sp->framebuffer.sbuf = fb->sbuf;
91
92 /* update cache */
93 if (fb->sbuf != fb->zbuf) {
94 /* separate stencil buf */
95 sp->sbuf_cache = sp->sbuf_cache_sep;
96 sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
97 }
98 else {
99 /* combined depth/stencil */
100 sp->sbuf_cache = sp->zbuf_cache;
101 sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
102 }
103 }
104 #endif
105
106 /* Tell draw module how deep the Z/depth buffer is */
107 {
108 int depth_bits;
109 double mrd;
110 if (sp->framebuffer.zsbuf) {
111 depth_bits = pf_get_component_bits(sp->framebuffer.zsbuf->format,
112 PIPE_FORMAT_COMP_Z);
113 }
114 else {
115 depth_bits = 0;
116 }
117 if (depth_bits > 16) {
118 mrd = 0.0000001;
119 }
120 else {
121 mrd = 0.00002;
122 }
123 draw_set_mrd(sp->draw, mrd);
124 }
125
126 sp->framebuffer.width = fb->width;
127 sp->framebuffer.height = fb->height;
128
129 sp->dirty |= SP_NEW_FRAMEBUFFER;
130 }