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_flush.h"
38 #include "cell_state.h"
39 #include "cell_texture.h"
44 cell_create_blend_state(struct pipe_context
*pipe
,
45 const struct pipe_blend_state
*blend
)
47 return mem_dup(blend
, sizeof(*blend
));
52 cell_bind_blend_state(struct pipe_context
*pipe
, void *blend
)
54 struct cell_context
*cell
= cell_context(pipe
);
56 draw_flush(cell
->draw
);
58 cell
->blend
= (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
*dsa
)
90 return mem_dup(dsa
, sizeof(*dsa
));
95 cell_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
,
98 struct cell_context
*cell
= cell_context(pipe
);
100 draw_flush(cell
->draw
);
102 cell
->depth_stencil
= (struct pipe_depth_stencil_alpha_state
*) dsa
;
103 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
108 cell_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *dsa
)
115 cell_set_clip_state(struct pipe_context
*pipe
,
116 const struct pipe_clip_state
*clip
)
118 struct cell_context
*cell
= cell_context(pipe
);
120 /* pass the clip state to the draw module */
121 draw_set_clip_state(cell
->draw
, clip
);
126 /* Called when driver state tracker notices changes to the viewport
130 cell_set_viewport_state( struct pipe_context
*pipe
,
131 const struct pipe_viewport_state
*viewport
)
133 struct cell_context
*cell
= cell_context(pipe
);
135 cell
->viewport
= *viewport
; /* struct copy */
136 cell
->dirty
|= CELL_NEW_VIEWPORT
;
138 /* pass the viewport info to the draw module */
139 draw_set_viewport_state(cell
->draw
, viewport
);
141 /* Using tnl/ and vf/ modules is temporary while getting started.
142 * Full pipe will have vertex shader, vertex fetch of its own.
148 cell_set_scissor_state( struct pipe_context
*pipe
,
149 const struct pipe_scissor_state
*scissor
)
151 struct cell_context
*cell
= cell_context(pipe
);
153 memcpy( &cell
->scissor
, scissor
, sizeof(*scissor
) );
154 cell
->dirty
|= CELL_NEW_SCISSOR
;
159 cell_set_polygon_stipple( struct pipe_context
*pipe
,
160 const struct pipe_poly_stipple
*stipple
)
162 struct cell_context
*cell
= cell_context(pipe
);
164 memcpy( &cell
->poly_stipple
, stipple
, sizeof(*stipple
) );
165 cell
->dirty
|= CELL_NEW_STIPPLE
;
171 cell_create_rasterizer_state(struct pipe_context
*pipe
,
172 const struct pipe_rasterizer_state
*rasterizer
)
174 return mem_dup(rasterizer
, sizeof(*rasterizer
));
179 cell_bind_rasterizer_state(struct pipe_context
*pipe
, void *rast
)
181 struct pipe_rasterizer_state
*rasterizer
=
182 (struct pipe_rasterizer_state
*) rast
;
183 struct cell_context
*cell
= cell_context(pipe
);
185 /* pass-through to draw module */
186 draw_set_rasterizer_state(cell
->draw
, rasterizer
);
188 cell
->rasterizer
= rasterizer
;
190 cell
->dirty
|= CELL_NEW_RASTERIZER
;
195 cell_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
203 cell_create_sampler_state(struct pipe_context
*pipe
,
204 const struct pipe_sampler_state
*sampler
)
206 return mem_dup(sampler
, sizeof(*sampler
));
211 cell_bind_sampler_states(struct pipe_context
*pipe
,
212 unsigned num
, void **samplers
)
214 struct cell_context
*cell
= cell_context(pipe
);
216 assert(num
<= CELL_MAX_SAMPLERS
);
218 draw_flush(cell
->draw
);
220 memcpy(cell
->sampler
, samplers
, num
* sizeof(void *));
221 memset(&cell
->sampler
[num
], 0, (CELL_MAX_SAMPLERS
- num
) *
223 cell
->num_samplers
= num
;
225 cell
->dirty
|= CELL_NEW_SAMPLER
;
230 cell_delete_sampler_state(struct pipe_context
*pipe
,
239 cell_set_sampler_textures(struct pipe_context
*pipe
,
240 unsigned num
, struct pipe_texture
**texture
)
242 struct cell_context
*cell
= cell_context(pipe
);
245 assert(num
<= CELL_MAX_SAMPLERS
);
247 /* Check for no-op */
248 if (num
== cell
->num_textures
&&
249 !memcmp(cell
->texture
, texture
, num
* sizeof(struct pipe_texture
*)))
252 draw_flush(cell
->draw
);
254 for (i
= 0; i
< CELL_MAX_SAMPLERS
; i
++) {
255 struct pipe_texture
*tex
= i
< num
? texture
[i
] : NULL
;
257 pipe_texture_reference((struct pipe_texture
**) &cell
->texture
[i
], tex
);
259 cell
->num_textures
= num
;
261 cell_update_texture_mapping(cell
);
263 cell
->dirty
|= CELL_NEW_TEXTURE
;
269 cell_set_framebuffer_state(struct pipe_context
*pipe
,
270 const struct pipe_framebuffer_state
*fb
)
272 struct cell_context
*cell
= cell_context(pipe
);
274 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
275 struct pipe_surface
*csurf
= fb
->cbufs
[0];
276 struct pipe_surface
*zsurf
= fb
->zsbuf
;
278 uint flags
= (PIPE_BUFFER_USAGE_GPU_WRITE
|
279 PIPE_BUFFER_USAGE_GPU_READ
);
281 /* unmap old surfaces */
282 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
283 if (cell
->framebuffer
.cbufs
[i
] && cell
->cbuf_map
[i
]) {
284 pipe_surface_unmap(cell
->framebuffer
.cbufs
[i
]);
285 cell
->cbuf_map
[i
] = NULL
;
289 if (cell
->framebuffer
.zsbuf
&& cell
->zsbuf_map
) {
290 pipe_surface_unmap(cell
->framebuffer
.zsbuf
);
291 cell
->zsbuf_map
= NULL
;
294 /* Finish any pending rendering to the current surface before
295 * installing a new surface!
297 cell_flush_int(cell
, CELL_FLUSH_WAIT
);
300 * (this is also where old surfaces will finally get freed)
302 cell
->framebuffer
.width
= fb
->width
;
303 cell
->framebuffer
.height
= fb
->height
;
304 cell
->framebuffer
.num_cbufs
= fb
->num_cbufs
;
305 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
306 pipe_surface_reference(&cell
->framebuffer
.cbufs
[i
], fb
->cbufs
[i
]);
308 pipe_surface_reference(&cell
->framebuffer
.zsbuf
, fb
->zsbuf
);
310 /* map new surfaces */
312 cell
->cbuf_map
[0] = pipe_surface_map(csurf
, flags
);
315 cell
->zsbuf_map
= pipe_surface_map(zsurf
, flags
);
317 cell
->dirty
|= CELL_NEW_FRAMEBUFFER
;
324 cell_init_state_functions(struct cell_context
*cell
)
326 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
327 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
328 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
330 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
331 cell
->pipe
.bind_sampler_states
= cell_bind_sampler_states
;
332 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
334 cell
->pipe
.set_sampler_textures
= cell_set_sampler_textures
;
336 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
337 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
338 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
340 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
341 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
342 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
344 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
345 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
347 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
349 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
350 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
351 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;