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 "util/u_math.h"
29 #include "util/u_memory.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_private.h"
33 #include "draw/draw_pt.h"
36 #define DRAW_MAX (FETCH_MAX+8)
38 struct varray_frontend
{
39 struct draw_pt_front_end base
;
40 struct draw_context
*draw
;
42 ushort draw_elts
[DRAW_MAX
];
43 unsigned fetch_elts
[FETCH_MAX
];
45 unsigned driver_fetch_max
;
48 struct draw_pt_middle_end
*middle
;
55 static void varray_flush_linear(struct varray_frontend
*varray
,
56 unsigned start
, unsigned count
)
59 assert(varray
->middle
->run_linear
);
60 varray
->middle
->run_linear(varray
->middle
, start
, count
);
64 static void varray_line_loop_segment(struct varray_frontend
*varray
,
66 unsigned segment_start
,
67 unsigned segment_count
,
70 assert(segment_count
< varray
->fetch_max
);
71 if (segment_count
>= 1) {
74 for (i
= 0; i
< segment_count
; i
++)
75 varray
->fetch_elts
[nr
++] = start
+ segment_start
+ i
;
78 varray
->fetch_elts
[nr
++] = start
;
80 assert(nr
<= FETCH_MAX
);
82 varray
->middle
->run(varray
->middle
,
85 varray
->draw_elts
, /* ie. linear */
92 static void varray_fan_segment(struct varray_frontend
*varray
,
94 unsigned segment_start
,
95 unsigned segment_count
)
97 assert(segment_count
< varray
->fetch_max
);
98 if (segment_count
>= 2) {
101 if (segment_start
!= 0)
102 varray
->fetch_elts
[nr
++] = start
;
104 for (i
= 0 ; i
< segment_count
; i
++)
105 varray
->fetch_elts
[nr
++] = start
+ segment_start
+ i
;
107 assert(nr
<= FETCH_MAX
);
109 varray
->middle
->run(varray
->middle
,
112 varray
->draw_elts
, /* ie. linear */
120 #define FUNC varray_run
121 #include "draw_pt_varray_tmp_linear.h"
123 static unsigned decompose_prim
[PIPE_PRIM_POLYGON
+ 1] = {
126 PIPE_PRIM_LINE_STRIP
, /* decomposed LINELOOP */
127 PIPE_PRIM_LINE_STRIP
,
129 PIPE_PRIM_TRIANGLE_STRIP
,
130 PIPE_PRIM_TRIANGLE_FAN
,
132 PIPE_PRIM_QUAD_STRIP
,
138 static void varray_prepare(struct draw_pt_front_end
*frontend
,
140 struct draw_pt_middle_end
*middle
,
143 struct varray_frontend
*varray
= (struct varray_frontend
*)frontend
;
145 varray
->base
.run
= varray_run
;
147 varray
->input_prim
= prim
;
148 varray
->output_prim
= decompose_prim
[prim
];
150 varray
->middle
= middle
;
151 middle
->prepare(middle
, varray
->output_prim
, opt
, &varray
->driver_fetch_max
);
153 /* check that the max is even */
154 assert((varray
->driver_fetch_max
& 1) == 0);
156 varray
->fetch_max
= MIN2(FETCH_MAX
, varray
->driver_fetch_max
);
162 static void varray_finish(struct draw_pt_front_end
*frontend
)
164 struct varray_frontend
*varray
= (struct varray_frontend
*)frontend
;
165 varray
->middle
->finish(varray
->middle
);
166 varray
->middle
= NULL
;
169 static void varray_destroy(struct draw_pt_front_end
*frontend
)
175 struct draw_pt_front_end
*draw_pt_varray(struct draw_context
*draw
)
178 struct varray_frontend
*varray
= CALLOC_STRUCT(varray_frontend
);
182 varray
->base
.prepare
= varray_prepare
;
183 varray
->base
.run
= NULL
;
184 varray
->base
.finish
= varray_finish
;
185 varray
->base
.destroy
= varray_destroy
;
188 for (i
= 0; i
< DRAW_MAX
; i
++) {
189 varray
->draw_elts
[i
] = i
;
192 return &varray
->base
;