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 "sp_context.h"
32 #include "sp_surface.h"
33 #include "sp_tile_cache.h"
37 * XXX this might get moved someday
38 * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer.
39 * Here, we map the surfaces and update the tile cache to point to the new
43 softpipe_set_framebuffer_state(struct pipe_context
*pipe
,
44 const struct pipe_framebuffer_state
*fb
)
46 struct softpipe_context
*sp
= softpipe_context(pipe
);
47 struct pipe_surface
*ps
;
50 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
51 /* check if changing cbuf */
52 if (sp
->framebuffer
.cbufs
[i
] != fb
->cbufs
[i
]) {
54 sp_flush_tile_cache(sp
, sp
->cbuf_cache
[i
]);
56 ps
= sp
->framebuffer
.cbufs
[i
];
58 pipe
->region_unmap(pipe
, ps
->region
);
62 pipe
->region_map(pipe
, ps
->region
);
64 sp
->framebuffer
.cbufs
[i
] = fb
->cbufs
[i
];
67 sp_tile_cache_set_surface(sp
->cbuf_cache
[i
], ps
);
71 sp
->framebuffer
.num_cbufs
= fb
->num_cbufs
;
74 if (sp
->framebuffer
.zbuf
!= fb
->zbuf
) {
76 sp_flush_tile_cache(sp
, sp
->zbuf_cache
);
78 ps
= sp
->framebuffer
.zbuf
;
80 pipe
->region_unmap(pipe
, ps
->region
);
81 if (sp
->framebuffer
.sbuf
== sp
->framebuffer
.zbuf
) {
82 /* combined z/stencil */
83 sp
->framebuffer
.sbuf
= NULL
;
88 pipe
->region_map(pipe
, ps
->region
);
90 sp
->framebuffer
.zbuf
= fb
->zbuf
;
93 sp_tile_cache_set_surface(sp
->zbuf_cache
, ps
);
96 /* XXX combined depth/stencil here */
99 if (sp
->framebuffer
.sbuf
!= fb
->sbuf
) {
101 sp_flush_tile_cache(sp
, sp
->sbuf_cache_sep
);
103 ps
= sp
->framebuffer
.sbuf
;
104 if (ps
&& ps
->region
)
105 pipe
->region_unmap(pipe
, ps
->region
);
108 if (ps
&& fb
->sbuf
!= fb
->zbuf
)
109 pipe
->region_map(pipe
, ps
->region
);
111 sp
->framebuffer
.sbuf
= fb
->sbuf
;
114 if (fb
->sbuf
!= fb
->zbuf
) {
115 /* separate stencil buf */
116 sp
->sbuf_cache
= sp
->sbuf_cache_sep
;
117 sp_tile_cache_set_surface(sp
->sbuf_cache
, ps
);
120 /* combined depth/stencil */
121 sp
->sbuf_cache
= sp
->zbuf_cache
;
122 sp_tile_cache_set_surface(sp
->sbuf_cache
, ps
);
126 sp
->dirty
|= SP_NEW_FRAMEBUFFER
;
133 softpipe_set_clear_color_state(struct pipe_context
*pipe
,
134 const struct pipe_clear_color_state
*clear
)
136 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
138 softpipe
->clear_color
= *clear
; /* struct copy */