1 /**************************************************************************
3 * Copyright 2008 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 **************************************************************************/
28 #include "pipe/p_util.h"
29 #include "draw/draw_context.h"
30 #include "draw/draw_private.h"
31 #include "draw/draw_pt.h"
34 #define DRAW_MAX (16*FETCH_MAX)
36 struct varray_frontend
{
37 struct draw_pt_front_end base
;
38 struct draw_context
*draw
;
40 ushort draw_elts
[DRAW_MAX
];
41 unsigned fetch_elts
[FETCH_MAX
];
48 struct draw_pt_middle_end
*middle
;
54 static void varray_flush(struct varray_frontend
*varray
)
56 if (varray
->draw_count
) {
58 debug_printf("FLUSH fc = %d, dc = %d\n",
61 debug_printf("\telt0 = %d, eltx = %d, draw0 = %d, drawx = %d\n",
62 varray
->fetch_elts
[0],
63 varray
->fetch_elts
[varray
->fetch_count
-1],
65 varray
->draw_elts
[varray
->draw_count
-1]);
67 varray
->middle
->run(varray
->middle
,
74 varray
->fetch_count
= 0;
75 varray
->draw_count
= 0;
78 static INLINE
void fetch_init(struct varray_frontend
*varray
,
83 debug_printf("FETCH INIT c = %d, fs = %d\n",
87 for (idx
= 0; idx
< count
; ++idx
) {
88 varray
->fetch_elts
[idx
] = varray
->fetch_start
+ idx
;
90 varray
->fetch_start
+= idx
;
91 varray
->fetch_count
= idx
;
95 static boolean
split_prim_inplace(unsigned prim
, unsigned *first
, unsigned *incr
)
98 case PIPE_PRIM_POINTS
:
102 case PIPE_PRIM_LINES
:
106 case PIPE_PRIM_LINE_STRIP
:
110 case PIPE_PRIM_TRIANGLES
:
114 case PIPE_PRIM_TRIANGLE_STRIP
:
118 case PIPE_PRIM_TRIANGLE_FAN
:
122 case PIPE_PRIM_QUADS
:
126 case PIPE_PRIM_QUAD_STRIP
:
130 case PIPE_PRIM_POLYGON
:
136 *incr
= 1; /* set to one so that count % incr works */
142 static INLINE
void add_draw_el(struct varray_frontend
*varray
,
143 int idx
, ushort flags
)
145 varray
->draw_elts
[varray
->draw_count
++] = idx
| flags
;
149 static INLINE
void varray_triangle( struct varray_frontend
*varray
,
154 add_draw_el(varray
, i0
, 0);
155 add_draw_el(varray
, i1
, 0);
156 add_draw_el(varray
, i2
, 0);
159 static INLINE
void varray_triangle_flags( struct varray_frontend
*varray
,
165 add_draw_el(varray
, i0
, flags
);
166 add_draw_el(varray
, i1
, 0);
167 add_draw_el(varray
, i2
, 0);
170 static INLINE
void varray_line( struct varray_frontend
*varray
,
174 add_draw_el(varray
, i0
, 0);
175 add_draw_el(varray
, i1
, 0);
179 static INLINE
void varray_line_flags( struct varray_frontend
*varray
,
184 add_draw_el(varray
, i0
, flags
);
185 add_draw_el(varray
, i1
, 0);
189 static INLINE
void varray_point( struct varray_frontend
*varray
,
192 add_draw_el(varray
, i0
, 0);
195 static INLINE
void varray_quad( struct varray_frontend
*varray
,
201 varray_triangle( varray
, i0
, i1
, i3
);
202 varray_triangle( varray
, i1
, i2
, i3
);
205 static INLINE
void varray_ef_quad( struct varray_frontend
*varray
,
211 const unsigned omitEdge1
= DRAW_PIPE_EDGE_FLAG_0
| DRAW_PIPE_EDGE_FLAG_2
;
212 const unsigned omitEdge2
= DRAW_PIPE_EDGE_FLAG_0
| DRAW_PIPE_EDGE_FLAG_1
;
214 varray_triangle_flags( varray
,
215 DRAW_PIPE_RESET_STIPPLE
| omitEdge1
,
218 varray_triangle_flags( varray
,
223 /* At least for now, we're back to using a template include file for
224 * this. The two paths aren't too different though - it may be
225 * possible to reunify them.
227 #define TRIANGLE(vc,flags,i0,i1,i2) varray_triangle_flags(vc,flags,i0,i1,i2)
228 #define QUAD(vc,i0,i1,i2,i3) varray_ef_quad(vc,i0,i1,i2,i3)
229 #define LINE(vc,flags,i0,i1) varray_line_flags(vc,flags,i0,i1)
230 #define POINT(vc,i0) varray_point(vc,i0)
231 #define FUNC varray_run_extras
232 #include "draw_pt_varray_tmp.h"
234 #define TRIANGLE(vc,flags,i0,i1,i2) varray_triangle(vc,i0,i1,i2)
235 #define QUAD(vc,i0,i1,i2,i3) varray_quad(vc,i0,i1,i2,i3)
236 #define LINE(vc,flags,i0,i1) varray_line(vc,i0,i1)
237 #define POINT(vc,i0) varray_point(vc,i0)
238 #define FUNC varray_run
239 #include "draw_pt_varray_tmp.h"
243 static unsigned reduced_prim
[PIPE_PRIM_POLYGON
+ 1] = {
258 static void varray_prepare(struct draw_pt_front_end
*frontend
,
260 struct draw_pt_middle_end
*middle
,
263 struct varray_frontend
*varray
= (struct varray_frontend
*)frontend
;
265 if (opt
& PT_PIPELINE
)
267 varray
->base
.run
= varray_run_extras
;
271 varray
->base
.run
= varray_run
;
274 varray
->input_prim
= prim
;
275 varray
->output_prim
= reduced_prim
[prim
];
277 varray
->middle
= middle
;
278 middle
->prepare(middle
, varray
->output_prim
, opt
);
284 static void varray_finish(struct draw_pt_front_end
*frontend
)
286 struct varray_frontend
*varray
= (struct varray_frontend
*)frontend
;
287 varray
->middle
->finish(varray
->middle
);
288 varray
->middle
= NULL
;
291 static void varray_destroy(struct draw_pt_front_end
*frontend
)
297 struct draw_pt_front_end
*draw_pt_varray(struct draw_context
*draw
)
299 struct varray_frontend
*varray
= CALLOC_STRUCT(varray_frontend
);
303 varray
->base
.prepare
= varray_prepare
;
304 varray
->base
.run
= NULL
;
305 varray
->base
.finish
= varray_finish
;
306 varray
->base
.destroy
= varray_destroy
;
309 return &varray
->base
;