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>
31 #include "fo_context.h"
34 /* This looks like a lot of work at the moment - we're keeping a
35 * duplicate copy of the state up-to-date.
37 * This can change in two ways:
38 * - With constant state objects we would only need to save a pointer,
39 * not the whole object.
40 * - By adding a callback in the state tracker to re-emit state. The
41 * state tracker knows the current state already and can re-emit it
42 * without additional complexity.
44 * This works as a proof-of-concept, but a final version will have
49 failover_set_alpha_test_state(struct pipe_context
*pipe
,
50 const struct pipe_alpha_test_state
*alpha
)
52 struct failover_context
*failover
= failover_context(pipe
);
54 failover
->alpha_test
= *alpha
;
55 failover
->dirty
|= FO_NEW_ALPHA_TEST
;
56 failover
->hw
->set_alpha_test_state( failover
->hw
, alpha
);
61 failover_bind_blend_state( struct pipe_context
*pipe
,
62 const struct pipe_blend_state
*blend
)
64 struct failover_context
*failover
= failover_context(pipe
);
66 failover
->blend
= blend
;
67 failover
->dirty
|= FO_NEW_BLEND
;
68 failover
->hw
->bind_blend_state( failover
->hw
, blend
);
73 failover_set_blend_color( struct pipe_context
*pipe
,
74 const struct pipe_blend_color
*blend_color
)
76 struct failover_context
*failover
= failover_context(pipe
);
78 failover
->blend_color
= *blend_color
;
79 failover
->dirty
|= FO_NEW_BLEND_COLOR
;
80 failover
->hw
->set_blend_color( failover
->hw
, blend_color
);
84 failover_set_clip_state( struct pipe_context
*pipe
,
85 const struct pipe_clip_state
*clip
)
87 struct failover_context
*failover
= failover_context(pipe
);
89 failover
->clip
= *clip
;
90 failover
->dirty
|= FO_NEW_CLIP
;
91 failover
->hw
->set_clip_state( failover
->hw
, clip
);
95 failover_set_clear_color_state( struct pipe_context
*pipe
,
96 const struct pipe_clear_color_state
*clear_color
)
98 struct failover_context
*failover
= failover_context(pipe
);
100 failover
->clear_color
= *clear_color
;
101 failover
->dirty
|= FO_NEW_CLEAR_COLOR
;
102 failover
->hw
->set_clear_color_state( failover
->hw
, clear_color
);
106 failover_bind_depth_stencil_state(struct pipe_context
*pipe
,
107 const struct pipe_depth_stencil_state
*depth_stencil
)
109 struct failover_context
*failover
= failover_context(pipe
);
111 failover
->depth_stencil
= depth_stencil
;
112 failover
->dirty
|= FO_NEW_DEPTH_STENCIL
;
113 failover
->hw
->bind_depth_stencil_state( failover
->hw
, depth_stencil
);
117 failover_set_framebuffer_state(struct pipe_context
*pipe
,
118 const struct pipe_framebuffer_state
*framebuffer
)
120 struct failover_context
*failover
= failover_context(pipe
);
122 failover
->framebuffer
= *framebuffer
;
123 failover
->dirty
|= FO_NEW_FRAMEBUFFER
;
124 failover
->hw
->set_framebuffer_state( failover
->hw
, framebuffer
);
128 failover_set_fs_state(struct pipe_context
*pipe
,
129 const struct pipe_shader_state
*fs
)
131 struct failover_context
*failover
= failover_context(pipe
);
133 failover
->fragment_shader
= *fs
;
134 failover
->dirty
|= FO_NEW_FRAGMENT_SHADER
;
135 failover
->hw
->set_fs_state( failover
->hw
, fs
);
139 failover_set_vs_state(struct pipe_context
*pipe
,
140 const struct pipe_shader_state
*vs
)
142 struct failover_context
*failover
= failover_context(pipe
);
144 failover
->vertex_shader
= *vs
;
145 failover
->dirty
|= FO_NEW_VERTEX_SHADER
;
146 failover
->hw
->set_vs_state( failover
->hw
, vs
);
151 failover_set_polygon_stipple( struct pipe_context
*pipe
,
152 const struct pipe_poly_stipple
*stipple
)
154 struct failover_context
*failover
= failover_context(pipe
);
156 failover
->poly_stipple
= *stipple
;
157 failover
->dirty
|= FO_NEW_STIPPLE
;
158 failover
->hw
->set_polygon_stipple( failover
->hw
, stipple
);
164 failover_set_setup_state( struct pipe_context
*pipe
,
165 const struct pipe_setup_state
*setup
)
167 struct failover_context
*failover
= failover_context(pipe
);
169 failover
->setup
= *setup
;
170 failover
->dirty
|= FO_NEW_SETUP
;
171 failover
->hw
->set_setup_state( failover
->hw
, setup
);
176 failover_set_scissor_state( struct pipe_context
*pipe
,
177 const struct pipe_scissor_state
*scissor
)
179 struct failover_context
*failover
= failover_context(pipe
);
181 failover
->scissor
= *scissor
;
182 failover
->dirty
|= FO_NEW_SCISSOR
;
183 failover
->hw
->set_scissor_state( failover
->hw
, scissor
);
187 failover_bind_sampler_state(struct pipe_context
*pipe
,
189 const struct pipe_sampler_state
*sampler
)
191 struct failover_context
*failover
= failover_context(pipe
);
193 failover
->sampler
[unit
] = sampler
;
194 failover
->dirty
|= FO_NEW_SAMPLER
;
195 failover
->dirty_sampler
|= (1<<unit
);
196 failover
->hw
->bind_sampler_state( failover
->hw
, unit
, sampler
);
201 failover_set_texture_state(struct pipe_context
*pipe
,
203 struct pipe_mipmap_tree
*texture
)
205 struct failover_context
*failover
= failover_context(pipe
);
207 failover
->texture
[unit
] = texture
;
208 failover
->dirty
|= FO_NEW_TEXTURE
;
209 failover
->dirty_texture
|= (1<<unit
);
210 failover
->hw
->set_texture_state( failover
->hw
, unit
, texture
);
215 failover_set_viewport_state( struct pipe_context
*pipe
,
216 const struct pipe_viewport_state
*viewport
)
218 struct failover_context
*failover
= failover_context(pipe
);
220 failover
->viewport
= *viewport
;
221 failover
->dirty
|= FO_NEW_VIEWPORT
;
222 failover
->hw
->set_viewport_state( failover
->hw
, viewport
);
227 failover_set_vertex_buffer(struct pipe_context
*pipe
,
229 const struct pipe_vertex_buffer
*vertex_buffer
)
231 struct failover_context
*failover
= failover_context(pipe
);
233 failover
->vertex_buffer
[unit
] = *vertex_buffer
;
234 failover
->dirty
|= FO_NEW_VERTEX_BUFFER
;
235 failover
->dirty_vertex_buffer
|= (1<<unit
);
236 failover
->hw
->set_vertex_buffer( failover
->hw
, unit
, vertex_buffer
);
241 failover_set_vertex_element(struct pipe_context
*pipe
,
243 const struct pipe_vertex_element
*vertex_element
)
245 struct failover_context
*failover
= failover_context(pipe
);
247 failover
->vertex_element
[unit
] = *vertex_element
;
248 failover
->dirty
|= FO_NEW_VERTEX_ELEMENT
;
249 failover
->dirty_vertex_element
|= (1<<unit
);
250 failover
->hw
->set_vertex_element( failover
->hw
, unit
, vertex_element
);
255 failover_init_state_functions( struct failover_context
*failover
)
257 failover
->pipe
.bind_blend_state
= failover_bind_blend_state
;
258 failover
->pipe
.bind_sampler_state
= failover_bind_sampler_state
;
259 failover
->pipe
.bind_depth_stencil_state
= failover_bind_depth_stencil_state
;
261 failover
->pipe
.set_alpha_test_state
= failover_set_alpha_test_state
;
262 failover
->pipe
.set_blend_color
= failover_set_blend_color
;
263 failover
->pipe
.set_clip_state
= failover_set_clip_state
;
264 failover
->pipe
.set_clear_color_state
= failover_set_clear_color_state
;
265 failover
->pipe
.set_framebuffer_state
= failover_set_framebuffer_state
;
266 failover
->pipe
.set_fs_state
= failover_set_fs_state
;
267 failover
->pipe
.set_vs_state
= failover_set_vs_state
;
268 failover
->pipe
.set_polygon_stipple
= failover_set_polygon_stipple
;
269 failover
->pipe
.set_scissor_state
= failover_set_scissor_state
;
270 failover
->pipe
.set_setup_state
= failover_set_setup_state
;
271 failover
->pipe
.set_texture_state
= failover_set_texture_state
;
272 failover
->pipe
.set_viewport_state
= failover_set_viewport_state
;
273 failover
->pipe
.set_vertex_buffer
= failover_set_vertex_buffer
;
274 failover
->pipe
.set_vertex_element
= failover_set_vertex_element
;