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 * \brief A draw stage that drives our triangle setup routines from
30 * within the draw pipeline. One of two ways to drive setup, the
31 * other being in sp_prim_vbuf.c.
33 * \author Keith Whitwell <keith@tungstengraphics.com>
38 #include "sp_context.h"
41 #include "sp_prim_setup.h"
42 #include "draw/draw_pipe.h"
43 #include "draw/draw_vertex.h"
44 #include "pipe/p_util.h"
47 * Triangle setup info (derived from draw_stage).
48 * Also used for line drawing (taking some liberties).
51 struct draw_stage stage
; /**< This must be first (base class) */
53 struct setup_context
*setup
;
59 * Basically a cast wrapper.
61 static INLINE
struct setup_stage
*setup_stage( struct draw_stage
*stage
)
63 return (struct setup_stage
*)stage
;
69 do_tri(struct draw_stage
*stage
, struct prim_header
*prim
)
71 struct setup_stage
*setup
= setup_stage( stage
);
73 setup_tri( setup
->setup
,
80 do_line(struct draw_stage
*stage
, struct prim_header
*prim
)
82 struct setup_stage
*setup
= setup_stage( stage
);
84 setup_line( setup
->setup
,
90 do_point(struct draw_stage
*stage
, struct prim_header
*prim
)
92 struct setup_stage
*setup
= setup_stage( stage
);
94 setup_point( setup
->setup
,
101 static void setup_begin( struct draw_stage
*stage
)
103 struct setup_stage
*setup
= setup_stage(stage
);
105 setup_prepare( setup
->setup
);
107 stage
->point
= do_point
;
108 stage
->line
= do_line
;
113 static void setup_first_point( struct draw_stage
*stage
,
114 struct prim_header
*header
)
117 stage
->point( stage
, header
);
120 static void setup_first_line( struct draw_stage
*stage
,
121 struct prim_header
*header
)
124 stage
->line( stage
, header
);
128 static void setup_first_tri( struct draw_stage
*stage
,
129 struct prim_header
*header
)
132 stage
->tri( stage
, header
);
137 static void setup_flush( struct draw_stage
*stage
,
140 stage
->point
= setup_first_point
;
141 stage
->line
= setup_first_line
;
142 stage
->tri
= setup_first_tri
;
146 static void reset_stipple_counter( struct draw_stage
*stage
)
151 static void render_destroy( struct draw_stage
*stage
)
153 struct setup_stage
*ssetup
= setup_stage(stage
);
154 setup_destroy_context(ssetup
->setup
);
160 * Create a new primitive setup/render stage.
162 struct draw_stage
*sp_draw_render_stage( struct softpipe_context
*softpipe
)
164 struct setup_stage
*sstage
= CALLOC_STRUCT(setup_stage
);
166 sstage
->setup
= setup_create_context(softpipe
);
167 sstage
->stage
.draw
= softpipe
->draw
;
168 sstage
->stage
.point
= setup_first_point
;
169 sstage
->stage
.line
= setup_first_line
;
170 sstage
->stage
.tri
= setup_first_tri
;
171 sstage
->stage
.flush
= setup_flush
;
172 sstage
->stage
.reset_stipple_counter
= reset_stipple_counter
;
173 sstage
->stage
.destroy
= render_destroy
;
175 return (struct draw_stage
*)sstage
;
178 struct setup_context
*
179 sp_draw_setup_context( struct draw_stage
*stage
)
181 struct setup_stage
*ssetup
= setup_stage(stage
);
182 return ssetup
->setup
;
186 sp_draw_flush( struct draw_stage
*stage
)
188 stage
->flush( stage
, 0 );