Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / llvmpipe / lp_state_rasterizer.c
1 /**************************************************************************
2  * 
3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
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_rast_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
45 clear_flags(struct pipe_rasterizer_state *rast)
46 {
47    rast->light_twoside = 0;
48    rast->offset_tri = 0;
49 }
50
51
52
53 static void *
54 llvmpipe_create_rasterizer_state(struct pipe_context *pipe,
55                                  const struct pipe_rasterizer_state *rast)
56 {
57    boolean need_pipeline;
58
59    /* Partition rasterizer state into what we want the draw module to
60     * handle, and what we'll look after ourselves.
61     */
62    struct lp_rast_state *state = MALLOC_STRUCT(lp_rast_state);
63    if (state == NULL)
64       return NULL;
65
66    memcpy(&state->draw_state, rast, sizeof *rast);
67    memcpy(&state->lp_state, rast, sizeof *rast);
68
69    /* We rely on draw module to do unfilled polyons, AA lines and
70     * points and stipple.
71     * 
72     * Over time, reduce this list of conditions, and expand the list
73     * of flags which get cleared in clear_flags().
74     */
75    need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL ||
76                     rast->fill_back != PIPE_POLYGON_MODE_FILL ||
77                     rast->point_smooth ||
78                     rast->line_smooth ||
79                     rast->line_stipple_enable ||
80                     rast->poly_stipple_enable);
81
82    /* If not using the pipeline, clear out the flags which we can
83     * handle ourselves.  If we *are* using the pipeline, do everything
84     * on the pipeline and clear those flags on our internal copy of
85     * the state.
86     */
87    if (need_pipeline)
88       clear_flags(&state->lp_state);
89    else
90       clear_flags(&state->draw_state);
91
92    return state;
93 }
94
95
96
97 static void
98 llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle)
99 {
100    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
101    const struct lp_rast_state *state =
102       (const struct lp_rast_state *) handle;
103
104    if (state) {
105       llvmpipe->rasterizer = &state->lp_state;
106       draw_set_rasterizer_state(llvmpipe->draw, &state->draw_state, handle);
107
108       /* XXX: just pass lp_state directly to setup.
109        */
110       lp_setup_set_triangle_state( llvmpipe->setup,
111                                    state->lp_state.cull_face,
112                                    state->lp_state.front_ccw,
113                                    state->lp_state.scissor,
114                                    state->lp_state.gl_rasterization_rules);
115       lp_setup_set_flatshade_first( llvmpipe->setup,
116                                     state->lp_state.flatshade_first);
117       lp_setup_set_line_state( llvmpipe->setup,
118                                state->lp_state.line_width);
119       lp_setup_set_point_state( llvmpipe->setup,
120                                 state->lp_state.point_size,
121                                 state->lp_state.point_size_per_vertex,
122                                 state->lp_state.sprite_coord_enable,
123                                 state->lp_state.sprite_coord_mode);
124    }
125    else {
126       llvmpipe->rasterizer = NULL;
127       draw_set_rasterizer_state(llvmpipe->draw, NULL, handle);      
128    }
129
130    llvmpipe->dirty |= LP_NEW_RASTERIZER;
131 }
132
133
134 static void
135 llvmpipe_delete_rasterizer_state(struct pipe_context *pipe,
136                                  void *rasterizer)
137 {
138    FREE( rasterizer );
139 }
140
141
142
143 void
144 llvmpipe_init_rasterizer_funcs(struct llvmpipe_context *llvmpipe)
145 {
146    llvmpipe->pipe.create_rasterizer_state = llvmpipe_create_rasterizer_state;
147    llvmpipe->pipe.bind_rasterizer_state   = llvmpipe_bind_rasterizer_state;
148    llvmpipe->pipe.delete_rasterizer_state = llvmpipe_delete_rasterizer_state;
149 }