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 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "pipe/p_util.h"
34 #include "pipe/p_inlines.h"
35 #include "draw/draw_context.h"
36 #include "cell_context.h"
37 #include "cell_state.h"
38 #include "cell_texture.h"
43 cell_create_blend_state(struct pipe_context
*pipe
,
44 const struct pipe_blend_state
*blend
)
46 return mem_dup(blend
, sizeof(*blend
));
51 cell_bind_blend_state(struct pipe_context
*pipe
, void *blend
)
53 struct cell_context
*cell
= cell_context(pipe
);
55 draw_flush(cell
->draw
);
57 cell
->blend
= (const struct pipe_blend_state
*)blend
;
59 cell
->dirty
|= CELL_NEW_BLEND
;
64 cell_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
71 cell_set_blend_color(struct pipe_context
*pipe
,
72 const struct pipe_blend_color
*blend_color
)
74 struct cell_context
*cell
= cell_context(pipe
);
76 draw_flush(cell
->draw
);
78 cell
->blend_color
= *blend_color
;
80 cell
->dirty
|= CELL_NEW_BLEND
;
87 cell_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
88 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
90 return mem_dup(depth_stencil
, sizeof(*depth_stencil
));
95 cell_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
,
98 struct cell_context
*cell
= cell_context(pipe
);
100 draw_flush(cell
->draw
);
103 = (const struct pipe_depth_stencil_alpha_state
*) depth_stencil
;
105 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
110 cell_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *depth
)
116 static void cell_set_clip_state( struct pipe_context
*pipe
,
117 const struct pipe_clip_state
*clip
)
119 struct cell_context
*cell
= cell_context(pipe
);
121 /* pass the clip state to the draw module */
122 draw_set_clip_state(cell
->draw
, clip
);
127 /* Called when driver state tracker notices changes to the viewport
131 cell_set_viewport_state( struct pipe_context
*pipe
,
132 const struct pipe_viewport_state
*viewport
)
134 struct cell_context
*cell
= cell_context(pipe
);
136 cell
->viewport
= *viewport
; /* struct copy */
137 cell
->dirty
|= CELL_NEW_VIEWPORT
;
139 /* pass the viewport info to the draw module */
140 draw_set_viewport_state(cell
->draw
, viewport
);
142 /* Using tnl/ and vf/ modules is temporary while getting started.
143 * Full pipe will have vertex shader, vertex fetch of its own.
149 cell_set_scissor_state( struct pipe_context
*pipe
,
150 const struct pipe_scissor_state
*scissor
)
152 struct cell_context
*cell
= cell_context(pipe
);
154 memcpy( &cell
->scissor
, scissor
, sizeof(*scissor
) );
155 cell
->dirty
|= CELL_NEW_SCISSOR
;
160 cell_set_polygon_stipple( struct pipe_context
*pipe
,
161 const struct pipe_poly_stipple
*stipple
)
163 struct cell_context
*cell
= cell_context(pipe
);
165 memcpy( &cell
->poly_stipple
, stipple
, sizeof(*stipple
) );
166 cell
->dirty
|= CELL_NEW_STIPPLE
;
172 cell_create_rasterizer_state(struct pipe_context
*pipe
,
173 const struct pipe_rasterizer_state
*setup
)
175 struct pipe_rasterizer_state
*state
176 = MALLOC(sizeof(struct pipe_rasterizer_state
));
177 memcpy(state
, setup
, sizeof(struct pipe_rasterizer_state
));
183 cell_bind_rasterizer_state(struct pipe_context
*pipe
, void *setup
)
185 struct cell_context
*cell
= cell_context(pipe
);
187 /* pass-through to draw module */
188 draw_set_rasterizer_state(cell
->draw
, setup
);
190 cell
->rasterizer
= (struct pipe_rasterizer_state
*)setup
;
192 cell
->dirty
|= CELL_NEW_RASTERIZER
;
197 cell_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
205 cell_create_sampler_state(struct pipe_context
*pipe
,
206 const struct pipe_sampler_state
*sampler
)
208 return mem_dup(sampler
, sizeof(*sampler
));
213 cell_bind_sampler_state(struct pipe_context
*pipe
,
214 unsigned unit
, void *sampler
)
216 struct cell_context
*cell
= cell_context(pipe
);
218 draw_flush(cell
->draw
);
220 assert(unit
< PIPE_MAX_SAMPLERS
);
221 cell
->sampler
[unit
] = (struct pipe_sampler_state
*)sampler
;
223 cell
->dirty
|= CELL_NEW_SAMPLER
;
228 cell_delete_sampler_state(struct pipe_context
*pipe
,
237 cell_set_sampler_texture(struct pipe_context
*pipe
,
239 struct pipe_texture
*texture
)
241 struct cell_context
*cell
= cell_context(pipe
);
243 draw_flush(cell
->draw
);
245 cell
->texture
[sampler
] = cell_texture(texture
);
247 cell_update_texture_mapping(cell
);
249 cell
->dirty
|= CELL_NEW_TEXTURE
;
255 cell_set_framebuffer_state(struct pipe_context
*pipe
,
256 const struct pipe_framebuffer_state
*fb
)
258 struct cell_context
*cell
= cell_context(pipe
);
260 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
261 struct pipe_surface
*csurf
= fb
->cbufs
[0];
262 struct pipe_surface
*zsurf
= fb
->zsbuf
;
265 /* unmap old surfaces */
266 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
267 if (cell
->framebuffer
.cbufs
[i
] && cell
->cbuf_map
[i
]) {
268 pipe_surface_unmap(cell
->framebuffer
.cbufs
[i
]);
269 cell
->cbuf_map
[i
] = NULL
;
273 if (cell
->framebuffer
.zsbuf
&& cell
->zsbuf_map
) {
274 pipe_surface_unmap(cell
->framebuffer
.zsbuf
);
275 cell
->zsbuf_map
= NULL
;
278 /* update my state */
279 cell
->framebuffer
= *fb
;
281 /* map new surfaces */
283 cell
->cbuf_map
[0] = pipe_surface_map(csurf
);
286 cell
->zsbuf_map
= pipe_surface_map(zsurf
);
288 cell
->dirty
|= CELL_NEW_FRAMEBUFFER
;
295 cell_init_state_functions(struct cell_context
*cell
)
297 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
298 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
299 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
301 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
302 cell
->pipe
.bind_sampler_state
= cell_bind_sampler_state
;
303 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
305 cell
->pipe
.set_sampler_texture
= cell_set_sampler_texture
;
307 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
308 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
309 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
311 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
312 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
313 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
315 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
316 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
318 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
320 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
321 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
322 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;