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"
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 cb
->code
.store
= NULL
;
57 cell_bind_blend_state(struct pipe_context
*pipe
, void *state
)
59 struct cell_context
*cell
= cell_context(pipe
);
60 struct cell_blend_state
*blend
= (struct cell_blend_state
*) state
;
63 draw_flush(cell
->draw
);
65 if ((blend
!= NULL
) && (blend
->code
.store
== NULL
)) {
66 cell_generate_alpha_blend(blend
, &cell
->blend_color
);
70 cell
->dirty
|= CELL_NEW_BLEND
;
75 cell_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
77 struct cell_blend_state
*cb
= (struct cell_blend_state
*) blend
;
79 spe_release_func(& cb
->code
);
85 cell_set_blend_color(struct pipe_context
*pipe
,
86 const struct pipe_blend_color
*blend_color
)
88 struct cell_context
*cell
= cell_context(pipe
);
90 draw_flush(cell
->draw
);
92 cell
->blend_color
= *blend_color
;
94 cell
->dirty
|= CELL_NEW_BLEND
;
101 cell_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
102 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
104 struct cell_depth_stencil_alpha_state
*cdsa
=
105 MALLOC(sizeof(struct cell_depth_stencil_alpha_state
));
107 (void) memcpy(cdsa
, depth_stencil
, sizeof(*depth_stencil
));
108 cdsa
->code
.store
= NULL
;
115 cell_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
,
118 struct cell_context
*cell
= cell_context(pipe
);
119 struct cell_depth_stencil_alpha_state
*cdsa
=
120 (struct cell_depth_stencil_alpha_state
*) depth_stencil
;
122 draw_flush(cell
->draw
);
124 if ((cdsa
!= NULL
) && (cdsa
->code
.store
== NULL
)) {
125 cell_generate_depth_stencil_test(cdsa
);
128 cell
->depth_stencil
= cdsa
;
129 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
134 cell_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *depth
)
136 struct cell_depth_stencil_alpha_state
*cdsa
=
137 (struct cell_depth_stencil_alpha_state
*) depth
;
139 spe_release_func(& cdsa
->code
);
144 static void cell_set_clip_state( struct pipe_context
*pipe
,
145 const struct pipe_clip_state
*clip
)
147 struct cell_context
*cell
= cell_context(pipe
);
149 /* pass the clip state to the draw module */
150 draw_set_clip_state(cell
->draw
, clip
);
155 /* Called when driver state tracker notices changes to the viewport
159 cell_set_viewport_state( struct pipe_context
*pipe
,
160 const struct pipe_viewport_state
*viewport
)
162 struct cell_context
*cell
= cell_context(pipe
);
164 cell
->viewport
= *viewport
; /* struct copy */
165 cell
->dirty
|= CELL_NEW_VIEWPORT
;
167 /* pass the viewport info to the draw module */
168 draw_set_viewport_state(cell
->draw
, viewport
);
170 /* Using tnl/ and vf/ modules is temporary while getting started.
171 * Full pipe will have vertex shader, vertex fetch of its own.
177 cell_set_scissor_state( struct pipe_context
*pipe
,
178 const struct pipe_scissor_state
*scissor
)
180 struct cell_context
*cell
= cell_context(pipe
);
182 memcpy( &cell
->scissor
, scissor
, sizeof(*scissor
) );
183 cell
->dirty
|= CELL_NEW_SCISSOR
;
188 cell_set_polygon_stipple( struct pipe_context
*pipe
,
189 const struct pipe_poly_stipple
*stipple
)
191 struct cell_context
*cell
= cell_context(pipe
);
193 memcpy( &cell
->poly_stipple
, stipple
, sizeof(*stipple
) );
194 cell
->dirty
|= CELL_NEW_STIPPLE
;
200 cell_create_rasterizer_state(struct pipe_context
*pipe
,
201 const struct pipe_rasterizer_state
*setup
)
203 struct pipe_rasterizer_state
*state
204 = MALLOC(sizeof(struct pipe_rasterizer_state
));
205 memcpy(state
, setup
, sizeof(struct pipe_rasterizer_state
));
211 cell_bind_rasterizer_state(struct pipe_context
*pipe
, void *setup
)
213 struct cell_context
*cell
= cell_context(pipe
);
215 /* pass-through to draw module */
216 draw_set_rasterizer_state(cell
->draw
, setup
);
218 cell
->rasterizer
= (struct pipe_rasterizer_state
*)setup
;
220 cell
->dirty
|= CELL_NEW_RASTERIZER
;
225 cell_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
233 cell_create_sampler_state(struct pipe_context
*pipe
,
234 const struct pipe_sampler_state
*sampler
)
236 return mem_dup(sampler
, sizeof(*sampler
));
241 cell_bind_sampler_states(struct pipe_context
*pipe
,
242 unsigned num
, void **samplers
)
244 struct cell_context
*cell
= cell_context(pipe
);
246 draw_flush(cell
->draw
);
248 assert(unit
< PIPE_MAX_SAMPLERS
);
250 memcpy(cell
->sampler
, samplers
, num
* sizeof(void *));
251 memset(&cell
->sampler
[num
], 0, (PIPE_MAX_SAMPLERS
- num
) *
253 cell
->num_samplers
= num
;
255 cell
->dirty
|= CELL_NEW_SAMPLER
;
260 cell_delete_sampler_state(struct pipe_context
*pipe
,
269 cell_set_sampler_textures(struct pipe_context
*pipe
,
270 unsigned num
, struct pipe_texture
**texture
)
272 struct cell_context
*cell
= cell_context(pipe
);
275 /* Check for no-op */
276 if (num
== cell
->num_textures
&&
277 !memcmp(cell
->texture
, texture
, num
* sizeof(struct pipe_texture
*)))
280 draw_flush(cell
->draw
);
282 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
283 struct pipe_texture
*tex
= i
< num
? texture
[i
] : NULL
;
285 pipe_texture_reference((struct pipe_texture
**) &cell
->texture
[i
], tex
);
288 cell_update_texture_mapping(cell
);
290 cell
->dirty
|= CELL_NEW_TEXTURE
;
296 cell_set_framebuffer_state(struct pipe_context
*pipe
,
297 const struct pipe_framebuffer_state
*fb
)
299 struct cell_context
*cell
= cell_context(pipe
);
301 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
302 struct pipe_surface
*csurf
= fb
->cbufs
[0];
303 struct pipe_surface
*zsurf
= fb
->zsbuf
;
306 /* unmap old surfaces */
307 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
308 if (cell
->framebuffer
.cbufs
[i
] && cell
->cbuf_map
[i
]) {
309 pipe_surface_unmap(cell
->framebuffer
.cbufs
[i
]);
310 cell
->cbuf_map
[i
] = NULL
;
314 if (cell
->framebuffer
.zsbuf
&& cell
->zsbuf_map
) {
315 pipe_surface_unmap(cell
->framebuffer
.zsbuf
);
316 cell
->zsbuf_map
= NULL
;
319 /* update my state */
320 cell
->framebuffer
= *fb
;
322 /* map new surfaces */
324 cell
->cbuf_map
[0] = pipe_surface_map(csurf
);
327 cell
->zsbuf_map
= pipe_surface_map(zsurf
);
329 cell
->dirty
|= CELL_NEW_FRAMEBUFFER
;
336 cell_init_state_functions(struct cell_context
*cell
)
338 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
339 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
340 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
342 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
343 cell
->pipe
.bind_sampler_states
= cell_bind_sampler_states
;
344 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
346 cell
->pipe
.set_sampler_textures
= cell_set_sampler_textures
;
348 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
349 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
350 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
352 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
353 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
354 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
356 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
357 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
359 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
361 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
362 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
363 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;