1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 VMWARE 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.
25 *
26 **************************************************************************/
27
28 #include "pipe/p_defines.h"
29 #include "util/u_memory.h"
30 #include "lp_context.h"
31 #include "lp_state.h"
32 #include "lp_setup.h"
33 #include "draw/draw_context.h"
34
35 struct lp_rasterizer_state {
36 struct pipe_rasterizer_state lp_state;
37 struct pipe_rasterizer_state draw_state;
38 };
39
40 /* State which might be handled in either the draw module or locally.
41 * This function is used to turn that state off in one of the two
42 * places.
43 */
44 static void
clear_flags(struct pipe_rasterizer_state * rast)45 clear_flags(struct pipe_rasterizer_state *rast)
46 {
47 rast->light_twoside = 0;
48 rast->offset_tri = 0;
49 rast->offset_line = 0;
50 rast->offset_point = 0;
51 rast->offset_units = 0.0f;
52 rast->offset_scale = 0.0f;
53 }
54
55
56
57 static void *
llvmpipe_create_rasterizer_state(struct pipe_context * pipe,const struct pipe_rasterizer_state * rast)58 llvmpipe_create_rasterizer_state(struct pipe_context *pipe,
59 const struct pipe_rasterizer_state *rast)
60 {
61 boolean need_pipeline;
62
63 /* Partition rasterizer state into what we want the draw module to
64 * handle, and what we'll look after ourselves.
65 */
66 struct lp_rasterizer_state *state = MALLOC_STRUCT(lp_rasterizer_state);
67 if (!state)
68 return NULL;
69
70 memcpy(&state->draw_state, rast, sizeof *rast);
71 memcpy(&state->lp_state, rast, sizeof *rast);
72
73 /* We rely on draw module to do unfilled polygons, AA lines and
74 * points and stipple.
75 *
76 * Over time, reduce this list of conditions, and expand the list
77 * of flags which get cleared in clear_flags().
78 */
79 need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL ||
80 rast->fill_back != PIPE_POLYGON_MODE_FILL ||
81 rast->point_smooth ||
82 rast->line_smooth ||
83 rast->line_stipple_enable ||
84 rast->poly_stipple_enable);
85
86 /* If not using the pipeline, clear out the flags which we can
87 * handle ourselves. If we *are* using the pipeline, do everything
88 * on the pipeline and clear those flags on our internal copy of
89 * the state.
90 */
91 if (need_pipeline)
92 clear_flags(&state->lp_state);
93 else
94 clear_flags(&state->draw_state);
95
96 return state;
97 }
98
99
100
101 static void
llvmpipe_bind_rasterizer_state(struct pipe_context * pipe,void * handle)102 llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle)
103 {
104 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
105 const struct lp_rasterizer_state *state =
106 (const struct lp_rasterizer_state *) handle;
107
108 if (state) {
109 llvmpipe->rasterizer = &state->lp_state;
110 draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle);
111
112 /* XXX: just pass lp_state directly to setup.
113 */
114 lp_setup_set_triangle_state( llvmpipe->setup,
115 state->lp_state.cull_face,
116 state->lp_state.front_ccw,
117 state->lp_state.scissor,
118 state->lp_state.half_pixel_center,
119 state->lp_state.bottom_edge_rule,
120 state->lp_state.multisample);
121 lp_setup_set_flatshade_first( llvmpipe->setup,
122 state->lp_state.flatshade_first);
123 lp_setup_set_line_state( llvmpipe->setup,
124 state->lp_state.line_width,
125 state->lp_state.line_rectangular);
126 lp_setup_set_point_state( llvmpipe->setup,
127 state->lp_state.point_size,
128 state->lp_state.point_tri_clip,
129 state->lp_state.point_size_per_vertex,
130 state->lp_state.sprite_coord_enable,
131 state->lp_state.sprite_coord_mode,
132 state->lp_state.point_quad_rasterization);
133 }
134 else {
135 llvmpipe->rasterizer = NULL;
136 draw_set_rasterizer_state(llvmpipe->draw, NULL, handle);
137 }
138
139 llvmpipe->dirty |= LP_NEW_RASTERIZER;
140 }
141
142
143 static void
llvmpipe_delete_rasterizer_state(struct pipe_context * pipe,void * rasterizer)144 llvmpipe_delete_rasterizer_state(struct pipe_context *pipe,
145 void *rasterizer)
146 {
147 FREE( rasterizer );
148 }
149
150
151
152 void
llvmpipe_init_rasterizer_funcs(struct llvmpipe_context * llvmpipe)153 llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe)
154 {
155 llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state;
156 llvmpipe->pipe.bind_rasterizer_state = llvmpipe_bind_rasterizer_state;
157 llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state;
158 }
159