diff options
Diffstat (limited to 'src/util/geometry.c')
-rw-r--r-- | src/util/geometry.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/util/geometry.c b/src/util/geometry.c new file mode 100644 index 0000000..afe0109 --- /dev/null +++ b/src/util/geometry.c | |||
@@ -0,0 +1,44 @@ | |||
1 | #include <gfx/util/geometry.h> | ||
2 | |||
3 | #include <math/vec2.h> | ||
4 | |||
5 | static void make_quad_11_positions(vec2 positions[4]) { | ||
6 | positions[0] = vec2_make(-1, +1); | ||
7 | positions[1] = vec2_make(-1, -1); | ||
8 | positions[2] = vec2_make(+1, +1); | ||
9 | positions[3] = vec2_make(+1, -1); | ||
10 | } | ||
11 | |||
12 | static void make_quad_01_positions(vec2 positions[4]) { | ||
13 | positions[0] = vec2_make(0, 0); | ||
14 | positions[1] = vec2_make(1, 0); | ||
15 | positions[2] = vec2_make(1, 1); | ||
16 | positions[3] = vec2_make(0, 1); | ||
17 | } | ||
18 | |||
19 | static GeometryDesc make_quad_desc(vec2 positions[4]) { | ||
20 | GeometryDesc desc = (GeometryDesc){0}; | ||
21 | desc.positions2d.data = positions; | ||
22 | desc.positions2d.size_bytes = 4 * sizeof(vec2); | ||
23 | desc.num_verts = 4; | ||
24 | desc.type = TriangleStrip; | ||
25 | return desc; | ||
26 | } | ||
27 | |||
28 | Geometry* gfx_make_quad_11(GfxCore* gfxcore) { | ||
29 | assert(gfxcore); | ||
30 | |||
31 | vec2 positions[4]; | ||
32 | make_quad_11_positions(positions); | ||
33 | const GeometryDesc geometry_desc = make_quad_desc(positions); | ||
34 | return gfx_make_geometry(gfxcore, &geometry_desc); | ||
35 | } | ||
36 | |||
37 | Geometry* gfx_make_quad_01(GfxCore* gfxcore) { | ||
38 | assert(gfxcore); | ||
39 | |||
40 | vec2 positions[4]; | ||
41 | make_quad_01_positions(positions); | ||
42 | const GeometryDesc geometry_desc = make_quad_desc(positions); | ||
43 | return gfx_make_geometry(gfxcore, &geometry_desc); | ||
44 | } | ||