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 "util/u_memory.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"
39 #include "cell_state_per_fragment.h"
44 cell_create_blend_state(struct pipe_context
*pipe
,
45 const struct pipe_blend_state
*blend
)
47 struct cell_blend_state
*cb
= MALLOC(sizeof(struct cell_blend_state
));
49 (void) memcpy(cb
, blend
, sizeof(*blend
));
50 cell_generate_alpha_blend(cb
);
57 cell_bind_blend_state(struct pipe_context
*pipe
, void *state
)
59 struct cell_context
*cell
= cell_context(pipe
);
61 draw_flush(cell
->draw
);
63 cell
->blend
= (struct cell_blend_state
*) state
;
64 cell
->dirty
|= CELL_NEW_BLEND
;
69 cell_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
71 struct cell_blend_state
*cb
= (struct cell_blend_state
*) blend
;
73 spe_release_func(& cb
->code
);
79 cell_set_blend_color(struct pipe_context
*pipe
,
80 const struct pipe_blend_color
*blend_color
)
82 struct cell_context
*cell
= cell_context(pipe
);
84 draw_flush(cell
->draw
);
86 cell
->blend_color
= *blend_color
;
88 cell
->dirty
|= CELL_NEW_BLEND
;
95 cell_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
96 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
98 struct cell_depth_stencil_alpha_state
*cdsa
=
99 MALLOC(sizeof(struct cell_depth_stencil_alpha_state
));
101 (void) memcpy(cdsa
, depth_stencil
, sizeof(*depth_stencil
));
102 cell_generate_depth_stencil_test(cdsa
);
109 cell_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
,
112 struct cell_context
*cell
= cell_context(pipe
);
114 draw_flush(cell
->draw
);
116 cell
->depth_stencil
=
117 (struct cell_depth_stencil_alpha_state
*) depth_stencil
;
118 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
123 cell_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *depth
)
125 struct cell_depth_stencil_alpha_state
*cdsa
=
126 (struct cell_depth_stencil_alpha_state
*) depth
;
128 spe_release_func(& cdsa
->code
);
133 static void cell_set_clip_state( struct pipe_context
*pipe
,
134 const struct pipe_clip_state
*clip
)
136 struct cell_context
*cell
= cell_context(pipe
);
138 /* pass the clip state to the draw module */
139 draw_set_clip_state(cell
->draw
, clip
);
144 /* Called when driver state tracker notices changes to the viewport
148 cell_set_viewport_state( struct pipe_context
*pipe
,
149 const struct pipe_viewport_state
*viewport
)
151 struct cell_context
*cell
= cell_context(pipe
);
153 cell
->viewport
= *viewport
; /* struct copy */
154 cell
->dirty
|= CELL_NEW_VIEWPORT
;
156 /* pass the viewport info to the draw module */
157 draw_set_viewport_state(cell
->draw
, viewport
);
159 /* Using tnl/ and vf/ modules is temporary while getting started.
160 * Full pipe will have vertex shader, vertex fetch of its own.
166 cell_set_scissor_state( struct pipe_context
*pipe
,
167 const struct pipe_scissor_state
*scissor
)
169 struct cell_context
*cell
= cell_context(pipe
);
171 memcpy( &cell
->scissor
, scissor
, sizeof(*scissor
) );
172 cell
->dirty
|= CELL_NEW_SCISSOR
;
177 cell_set_polygon_stipple( struct pipe_context
*pipe
,
178 const struct pipe_poly_stipple
*stipple
)
180 struct cell_context
*cell
= cell_context(pipe
);
182 memcpy( &cell
->poly_stipple
, stipple
, sizeof(*stipple
) );
183 cell
->dirty
|= CELL_NEW_STIPPLE
;
189 cell_create_rasterizer_state(struct pipe_context
*pipe
,
190 const struct pipe_rasterizer_state
*setup
)
192 struct pipe_rasterizer_state
*state
193 = MALLOC(sizeof(struct pipe_rasterizer_state
));
194 memcpy(state
, setup
, sizeof(struct pipe_rasterizer_state
));
200 cell_bind_rasterizer_state(struct pipe_context
*pipe
, void *setup
)
202 struct cell_context
*cell
= cell_context(pipe
);
204 /* pass-through to draw module */
205 draw_set_rasterizer_state(cell
->draw
, setup
);
207 cell
->rasterizer
= (struct pipe_rasterizer_state
*)setup
;
209 cell
->dirty
|= CELL_NEW_RASTERIZER
;
214 cell_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
222 cell_create_sampler_state(struct pipe_context
*pipe
,
223 const struct pipe_sampler_state
*sampler
)
225 return mem_dup(sampler
, sizeof(*sampler
));
230 cell_bind_sampler_states(struct pipe_context
*pipe
,
231 unsigned num
, void **samplers
)
233 struct cell_context
*cell
= cell_context(pipe
);
235 assert(num
<= CELL_MAX_SAMPLERS
);
237 draw_flush(cell
->draw
);
239 memcpy(cell
->sampler
, samplers
, num
* sizeof(void *));
240 memset(&cell
->sampler
[num
], 0, (CELL_MAX_SAMPLERS
- num
) *
242 cell
->num_samplers
= num
;
244 cell
->dirty
|= CELL_NEW_SAMPLER
;
249 cell_delete_sampler_state(struct pipe_context
*pipe
,
258 cell_set_sampler_textures(struct pipe_context
*pipe
,
259 unsigned num
, struct pipe_texture
**texture
)
261 struct cell_context
*cell
= cell_context(pipe
);
264 assert(num
<= CELL_MAX_SAMPLERS
);
266 /* Check for no-op */
267 if (num
== cell
->num_textures
&&
268 !memcmp(cell
->texture
, texture
, num
* sizeof(struct pipe_texture
*)))
271 draw_flush(cell
->draw
);
273 for (i
= 0; i
< CELL_MAX_SAMPLERS
; i
++) {
274 struct pipe_texture
*tex
= i
< num
? texture
[i
] : NULL
;
276 pipe_texture_reference((struct pipe_texture
**) &cell
->texture
[i
], tex
);
278 cell
->num_textures
= num
;
280 cell_update_texture_mapping(cell
);
282 cell
->dirty
|= CELL_NEW_TEXTURE
;
288 cell_set_framebuffer_state(struct pipe_context
*pipe
,
289 const struct pipe_framebuffer_state
*fb
)
291 struct cell_context
*cell
= cell_context(pipe
);
293 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
294 struct pipe_surface
*csurf
= fb
->cbufs
[0];
295 struct pipe_surface
*zsurf
= fb
->zsbuf
;
298 /* unmap old surfaces */
299 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
300 if (cell
->framebuffer
.cbufs
[i
] && cell
->cbuf_map
[i
]) {
301 pipe_surface_unmap(cell
->framebuffer
.cbufs
[i
]);
302 cell
->cbuf_map
[i
] = NULL
;
306 if (cell
->framebuffer
.zsbuf
&& cell
->zsbuf_map
) {
307 pipe_surface_unmap(cell
->framebuffer
.zsbuf
);
308 cell
->zsbuf_map
= NULL
;
311 /* update my state */
312 cell
->framebuffer
= *fb
;
314 /* map new surfaces */
316 cell
->cbuf_map
[0] = pipe_surface_map(csurf
);
319 cell
->zsbuf_map
= pipe_surface_map(zsurf
);
321 cell
->dirty
|= CELL_NEW_FRAMEBUFFER
;
328 cell_init_state_functions(struct cell_context
*cell
)
330 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
331 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
332 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
334 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
335 cell
->pipe
.bind_sampler_states
= cell_bind_sampler_states
;
336 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
338 cell
->pipe
.set_sampler_textures
= cell_set_sampler_textures
;
340 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
341 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
342 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
344 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
345 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
346 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
348 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
349 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
351 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
353 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
354 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
355 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;