1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
30 #include "p_inlines.h"
32 #include "sp_context.h"
34 #include "sp_surface.h"
35 #include "sp_tile_cache.h"
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
45 softpipe_set_framebuffer_state(struct pipe_context
*pipe
,
46 const struct pipe_framebuffer_state
*fb
)
48 struct softpipe_context
*sp
= softpipe_context(pipe
);
49 struct pipe_surface
*ps
;
52 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
53 /* check if changing cbuf */
54 if (sp
->framebuffer
.cbufs
[i
] != fb
->cbufs
[i
]) {
56 sp_flush_tile_cache(sp
, sp
->cbuf_cache
[i
]);
58 ps
= sp
->framebuffer
.cbufs
[i
];
60 pipe_surface_unmap(ps
);
66 sp
->framebuffer
.cbufs
[i
] = fb
->cbufs
[i
];
69 sp_tile_cache_set_surface(sp
->cbuf_cache
[i
], ps
);
73 sp
->framebuffer
.num_cbufs
= fb
->num_cbufs
;
76 if (sp
->framebuffer
.zbuf
!= fb
->zbuf
) {
78 sp_flush_tile_cache(sp
, sp
->zbuf_cache
);
80 ps
= sp
->framebuffer
.zbuf
;
82 pipe_surface_unmap(ps
);
83 if (sp
->framebuffer
.sbuf
== sp
->framebuffer
.zbuf
) {
84 /* combined z/stencil */
85 sp
->framebuffer
.sbuf
= NULL
;
92 sp
->framebuffer
.zbuf
= fb
->zbuf
;
95 sp_tile_cache_set_surface(sp
->zbuf_cache
, ps
);
98 /* XXX combined depth/stencil here */
101 if (sp
->framebuffer
.sbuf
!= fb
->sbuf
) {
103 sp_flush_tile_cache(sp
, sp
->sbuf_cache_sep
);
105 ps
= sp
->framebuffer
.sbuf
;
107 pipe_surface_unmap(ps
);
110 if (ps
&& fb
->sbuf
!= fb
->zbuf
)
111 pipe_surface_map(ps
);
113 sp
->framebuffer
.sbuf
= fb
->sbuf
;
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
);
122 /* combined depth/stencil */
123 sp
->sbuf_cache
= sp
->zbuf_cache
;
124 sp_tile_cache_set_surface(sp
->sbuf_cache
, ps
);
128 sp
->dirty
|= SP_NEW_FRAMEBUFFER
;
135 softpipe_set_clear_color_state(struct pipe_context
*pipe
,
136 const struct pipe_clear_color_state
*clear
)
138 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
140 softpipe
->clear_color
= *clear
; /* struct copy */