diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend.c | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/src/backend.c b/src/backend.c index db91647..f610905 100644 --- a/src/backend.c +++ b/src/backend.c | |||
@@ -3,8 +3,10 @@ | |||
3 | 3 | ||
4 | #include <gfx/core.h> | 4 | #include <gfx/core.h> |
5 | #include <gfx/gfx.h> | 5 | #include <gfx/gfx.h> |
6 | #include <gfx/llr/llr.h> | ||
7 | #include <gfx/llr/material.h> | ||
8 | #include <gfx/llr/mesh.h> | ||
6 | #include <gfx/renderer.h> | 9 | #include <gfx/renderer.h> |
7 | #include <gfx/scene.h> | ||
8 | #include <gfx/util/geometry.h> | 10 | #include <gfx/util/geometry.h> |
9 | #include <gfx/util/shader.h> | 11 | #include <gfx/util/shader.h> |
10 | 12 | ||
@@ -12,8 +14,8 @@ | |||
12 | #include <stdlib.h> | 14 | #include <stdlib.h> |
13 | 15 | ||
14 | typedef struct IsoBackend { | 16 | typedef struct IsoBackend { |
15 | Gfx* gfx; | 17 | Gfx* gfx; |
16 | Scene* scene; | 18 | Mesh* quad_mesh; |
17 | /// The screen or "iso screen" refers to the colour buffer of the iso graphics | 19 | /// The screen or "iso screen" refers to the colour buffer of the iso graphics |
18 | /// library. This texture is used to draw the iso screen onto the graphics | 20 | /// library. This texture is used to draw the iso screen onto the graphics |
19 | /// window. | 21 | /// window. |
@@ -46,14 +48,13 @@ IsoBackend* IsoBackendInit(const IsoGfx* iso) { | |||
46 | isogfx_get_screen_size(iso, &screen_width, &screen_height); | 48 | isogfx_get_screen_size(iso, &screen_width, &screen_height); |
47 | 49 | ||
48 | if (!(backend->screen_texture = gfx_make_texture( | 50 | if (!(backend->screen_texture = gfx_make_texture( |
49 | gfxcore, &(TextureDesc){ | 51 | gfxcore, &(TextureDesc){.width = screen_width, |
50 | .width = screen_width, | 52 | .height = screen_height, |
51 | .height = screen_height, | 53 | .dimension = Texture2D, |
52 | .dimension = Texture2D, | 54 | .format = TextureSRGBA8, |
53 | .format = TextureSRGBA8, | 55 | .filtering = NearestFiltering, |
54 | .filtering = NearestFiltering, | 56 | .wrap = ClampToEdge, |
55 | .wrap = ClampToEdge, | 57 | .mipmaps = false}))) { |
56 | .mipmaps = false}))) { | ||
57 | goto cleanup; | 58 | goto cleanup; |
58 | } | 59 | } |
59 | 60 | ||
@@ -68,10 +69,10 @@ IsoBackend* IsoBackendInit(const IsoGfx* iso) { | |||
68 | } | 69 | } |
69 | 70 | ||
70 | MaterialDesc material_desc = (MaterialDesc){.num_uniforms = 1}; | 71 | MaterialDesc material_desc = (MaterialDesc){.num_uniforms = 1}; |
71 | material_desc.uniforms[0] = (ShaderUniform){ | 72 | material_desc.uniforms[0] = |
72 | .type = UniformTexture, | 73 | (ShaderUniform){.type = UniformTexture, |
73 | .value.texture = backend->screen_texture, | 74 | .value.texture = backend->screen_texture, |
74 | .name = sstring_make("Texture")}; | 75 | .name = sstring_make("Texture")}; |
75 | Material* material = gfx_make_material(&material_desc); | 76 | Material* material = gfx_make_material(&material_desc); |
76 | if (!material) { | 77 | if (!material) { |
77 | return false; | 78 | return false; |
@@ -79,22 +80,11 @@ IsoBackend* IsoBackendInit(const IsoGfx* iso) { | |||
79 | 80 | ||
80 | const MeshDesc mesh_desc = | 81 | const MeshDesc mesh_desc = |
81 | (MeshDesc){.geometry = geometry, .material = material, .shader = shader}; | 82 | (MeshDesc){.geometry = geometry, .material = material, .shader = shader}; |
82 | Mesh* mesh = gfx_make_mesh(&mesh_desc); | 83 | backend->quad_mesh = gfx_make_mesh(&mesh_desc); |
83 | if (!mesh) { | 84 | if (!backend->quad_mesh) { |
84 | goto cleanup; | 85 | goto cleanup; |
85 | } | 86 | } |
86 | 87 | ||
87 | SceneObject* object = | ||
88 | gfx_make_object(&(ObjectDesc){.num_meshes = 1, .meshes = {mesh}}); | ||
89 | if (!object) { | ||
90 | goto cleanup; | ||
91 | } | ||
92 | |||
93 | backend->scene = gfx_make_scene(); | ||
94 | SceneNode* node = gfx_make_object_node(object); | ||
95 | SceneNode* root = gfx_get_scene_root(backend->scene); | ||
96 | gfx_set_node_parent(node, root); | ||
97 | |||
98 | return backend; | 88 | return backend; |
99 | 89 | ||
100 | cleanup: | 90 | cleanup: |
@@ -153,8 +143,8 @@ void IsoBackendRender(const IsoBackend* app, const IsoGfx* iso) { | |||
153 | assert(screen); | 143 | assert(screen); |
154 | gfx_update_texture(app->screen_texture, &(TextureDataDesc){.pixels = screen}); | 144 | gfx_update_texture(app->screen_texture, &(TextureDataDesc){.pixels = screen}); |
155 | 145 | ||
156 | GfxCore* gfxcore = gfx_get_core(app->gfx); | 146 | GfxCore* gfxcore = gfx_get_core(app->gfx); |
157 | Renderer* renderer = gfx_get_renderer(app->gfx); | 147 | LLR* renderer = gfx_get_llr(app->gfx); |
158 | 148 | ||
159 | // Clear the whole window. | 149 | // Clear the whole window. |
160 | gfx_set_viewport(gfxcore, 0, 0, app->window_width, app->window_height); | 150 | gfx_set_viewport(gfxcore, 0, 0, app->window_width, app->window_height); |
@@ -168,9 +158,7 @@ void IsoBackendRender(const IsoBackend* app, const IsoGfx* iso) { | |||
168 | 158 | ||
169 | // Render the iso screen. | 159 | // Render the iso screen. |
170 | gfx_start_frame(gfxcore); | 160 | gfx_start_frame(gfxcore); |
171 | gfx_render_scene( | 161 | gfx_llr_render_mesh(renderer, app->quad_mesh); |
172 | renderer, &(RenderSceneParams){ | ||
173 | .mode = RenderDefault, .scene = app->scene, .camera = 0}); | ||
174 | gfx_end_frame(gfxcore); | 162 | gfx_end_frame(gfxcore); |
175 | } | 163 | } |
176 | 164 | ||