foo
[regis] / rgl.c
1 #include "rgl.h"
2 #include "regis.h"
3
4 struct vec2 {
5         int x, y;
6 };
7
8 static void flush_verts(void);
9 static void draw_lines(struct vec2 *v, int nverts);
10
11 static int cur_mode = -1;
12 #define VBUF_SIZE       64
13 static struct vec2 vbuf[VBUF_SIZE];
14 static int nverts;
15
16 void rgl_begin(int mode)
17 {
18         cur_mode = mode;
19         nverts = 0;
20 }
21
22 void rgl_end(void)
23 {
24         flush_verts();
25         cur_mode = -1;
26 }
27
28 void rgl_vertex(int x, int y)
29 {
30         vbuf[nverts].x = x;
31         vbuf[nverts].y = y;
32
33         if(++nverts >= VBUF_SIZE) {
34                 flush_verts();
35         }
36 }
37
38 static void flush_verts(void)
39 {
40         switch(cur_mode) {
41         case REGIS_LINES:
42                 draw_lines(vbuf, nverts);
43                 break;
44
45         default:
46                 break;
47         }
48         nverts = 0;
49 }
50
51 static void draw_lines(struct vec2 *v, int nverts)
52 {
53         if(nverts <= 0) return;
54
55         regis_enter();
56
57         regis_leave();
58 }