diff options
Diffstat (limited to 'src/gfx.c')
-rw-r--r-- | src/gfx.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/gfx.c b/src/gfx.c new file mode 100644 index 0000000..4291ae7 --- /dev/null +++ b/src/gfx.c | |||
@@ -0,0 +1,83 @@ | |||
1 | #include <gfx/gfx.h> | ||
2 | |||
3 | #include "asset/asset_cache.h" | ||
4 | #include "core/core_impl.h" | ||
5 | #include "llr/llr_impl.h" | ||
6 | #include "renderer/imm_renderer_impl.h" | ||
7 | #include "renderer/renderer_impl.h" | ||
8 | #include "scene/scene_memory.h" | ||
9 | |||
10 | #include <assert.h> | ||
11 | #include <stdlib.h> | ||
12 | |||
13 | typedef struct Gfx { | ||
14 | AssetCache asset_cache; | ||
15 | GfxCore gfxcore; | ||
16 | LLR llr; | ||
17 | ImmRenderer imm_renderer; | ||
18 | Renderer renderer; | ||
19 | } Gfx; | ||
20 | |||
21 | Gfx* gfx_init(void) { | ||
22 | Gfx* gfx = calloc(1, sizeof(Gfx)); | ||
23 | if (!gfx) { | ||
24 | return 0; | ||
25 | } | ||
26 | gfx_init_gfxcore(&gfx->gfxcore); | ||
27 | if (!gfx_llr_make(&gfx->llr, &gfx->gfxcore)) { | ||
28 | gfx_destroy(&gfx); | ||
29 | return 0; | ||
30 | } | ||
31 | if (!gfx_imm_make(&gfx->imm_renderer, &gfx->gfxcore, &gfx->llr)) { | ||
32 | // TODO: Add error logs to the initialization failure cases here and inside | ||
33 | // the renderers. | ||
34 | gfx_destroy(&gfx); | ||
35 | return 0; | ||
36 | } | ||
37 | if (!gfx_renderer_make(&gfx->renderer, &gfx->llr, &gfx->gfxcore)) { | ||
38 | gfx_destroy(&gfx); | ||
39 | return 0; | ||
40 | } | ||
41 | gfx_init_asset_cache(&gfx->asset_cache); | ||
42 | scene_mem_init(); | ||
43 | return gfx; | ||
44 | } | ||
45 | |||
46 | void gfx_destroy(Gfx** gfx) { | ||
47 | if (!gfx) { | ||
48 | return; | ||
49 | } | ||
50 | scene_mem_destroy(); | ||
51 | gfx_destroy_asset_cache(&(*gfx)->asset_cache); | ||
52 | gfx_renderer_destroy(&(*gfx)->renderer); | ||
53 | gfx_imm_destroy(&(*gfx)->imm_renderer); | ||
54 | gfx_llr_destroy(&(*gfx)->llr); | ||
55 | gfx_del_gfxcore(&(*gfx)->gfxcore); | ||
56 | free(*gfx); | ||
57 | *gfx = 0; | ||
58 | } | ||
59 | |||
60 | GfxCore* gfx_get_core(Gfx* gfx) { | ||
61 | assert(gfx); | ||
62 | return &gfx->gfxcore; | ||
63 | } | ||
64 | |||
65 | Renderer* gfx_get_renderer(Gfx* gfx) { | ||
66 | assert(gfx); | ||
67 | return &gfx->renderer; | ||
68 | } | ||
69 | |||
70 | ImmRenderer* gfx_get_imm_renderer(Gfx* gfx) { | ||
71 | assert(gfx); | ||
72 | return &gfx->imm_renderer; | ||
73 | } | ||
74 | |||
75 | LLR* gfx_get_llr(Gfx* gfx) { | ||
76 | assert(gfx); | ||
77 | return &gfx->llr; | ||
78 | } | ||
79 | |||
80 | AssetCache* gfx_get_asset_cache(Gfx* gfx) { | ||
81 | assert(gfx); | ||
82 | return &gfx->asset_cache; | ||
83 | } | ||