diff options
-rw-r--r-- | Makefile | 30 | ||||
-rw-r--r-- | c2.cpp | 147 | ||||
-rw-r--r-- | camera.cpp | 25 | ||||
-rw-r--r-- | camera.hpp | 16 | ||||
-rw-r--r-- | configure.lua | 11 | ||||
-rw-r--r-- | debugdraw.cpp | 119 | ||||
-rw-r--r-- | debugdraw.hpp | 42 | ||||
-rw-r--r-- | editor.cpp | 61 | ||||
-rw-r--r-- | editor.hpp | 13 | ||||
-rw-r--r-- | maths.cpp | 12 | ||||
-rw-r--r-- | maths.hpp | 4 | ||||
-rw-r--r-- | model.cpp | 19 | ||||
-rw-r--r-- | model.hpp | 10 |
13 files changed, 321 insertions, 188 deletions
@@ -42,22 +42,28 @@ shadercompiler: sc/sc.o sc/includer.o libqstd.a libcfg.a app.o: app.cpp g++ -std=c++20 $(opt_com) $(cflags) -c app.cpp -o app.o -c2.o: c2.cpp - g++ -std=c++20 $(opt_com) $(cflags) -c c2.cpp -o c2.o -video.o: video.cpp - g++ -std=c++20 $(opt_com) $(cflags) -c video.cpp -o video.o -pipeline.o: pipeline.cpp - g++ -std=c++20 $(opt_com) $(cflags) -c pipeline.cpp -o pipeline.o asset.o: asset.cpp g++ -std=c++20 $(opt_com) $(cflags) -c asset.cpp -o asset.o -ui.o: ui.cpp - g++ -std=c++20 $(opt_com) $(cflags) -c ui.cpp -o ui.o +c2.o: c2.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c c2.cpp -o c2.o +camera.o: camera.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c camera.cpp -o camera.o +debugdraw.o: debugdraw.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c debugdraw.cpp -o debugdraw.o +editor.o: editor.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c editor.cpp -o editor.o maths.o: maths.cpp g++ -std=c++20 $(opt_com) $(cflags) -c maths.cpp -o maths.o model.o: model.cpp g++ -std=c++20 $(opt_com) $(cflags) -c model.cpp -o model.o -c2: app.o c2.o video.o pipeline.o asset.o ui.o maths.o model.o libqstd.a - g++ $(opt_lnk) $(lflags) -o c2 app.o c2.o video.o pipeline.o asset.o ui.o maths.o model.o libqstd.a -lX11 -lm +pipeline.o: pipeline.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c pipeline.cpp -o pipeline.o +ui.o: ui.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c ui.cpp -o ui.o +video.o: video.cpp + g++ -std=c++20 $(opt_com) $(cflags) -c video.cpp -o video.o +c2: app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o pipeline.o ui.o video.o libqstd.a + g++ $(opt_lnk) $(lflags) -o c2 app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o pipeline.o ui.o video.o libqstd.a -lX11 -lm c2: pack @@ -123,10 +129,10 @@ pack: packer data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data data: mkdir -p data --include qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d c2.d video.d pipeline.d asset.d ui.d maths.d model.d convtexture.d convmodel.d convmaterial.d packer.d +-include qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d maths.d model.d pipeline.d ui.d video.d convtexture.d convmodel.d convmaterial.d packer.d clean: - rm -f qstd/memory.o qstd/plat.o qstd/str.o qstd/pack.o cfg/cfgparse.o sc/sc.o sc/includer.o app.o c2.o video.o pipeline.o asset.o ui.o maths.o model.o convtexture.o convmodel.o convmaterial.o packer.o qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d c2.d video.d pipeline.d asset.d ui.d maths.d model.d convtexture.d convmodel.d convmaterial.d packer.d data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/triangle.csh data/ui.csh data/monkey.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat + rm -f qstd/memory.o qstd/plat.o qstd/str.o qstd/pack.o cfg/cfgparse.o sc/sc.o sc/includer.o app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o pipeline.o ui.o video.o convtexture.o convmodel.o convmaterial.o packer.o qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d maths.d model.d pipeline.d ui.d video.d convtexture.d convmodel.d convmaterial.d packer.d data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/triangle.csh data/ui.csh data/monkey.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat rm -f shadercompiler rmdir data rm -f c2 @@ -1,4 +1,7 @@ #include "app.hpp" +#include "camera.hpp" +#include "debugdraw.hpp" +#include "editor.hpp" #include "model.hpp" #include "ui.hpp" #include "video.hpp" @@ -108,7 +111,7 @@ struct Orbit_Cam : public Camera { ); } - void update(const App& app) { + void update_orbit(const App& app) { float dx = ((float)(px - app.mx) / (float)app.w) * sense; float dy = ((float)(py - app.my) / (float)app.h) * sense; int dscroll = pscroll - app.scrolly; @@ -534,134 +537,6 @@ struct Env_Probe { } }; -struct Line_Renderer { - static constexpr int max_lines = 1024; - Staged_Buffer vb, cb; - Shader* shader; - int vert_binding, cbuffer_binding; - int cur; - int w, h; - v3f cur_col; - - struct Vertex { - float x, y, z; - float r, g, b; - }* verts; - - struct CBuffer { - m4f vp; - }; - - void init(Device* dev, Asset_Arena* assets) { - vb.init( - dev, - "Line Renderer mesh", - max_lines * sizeof(Vertex) * 2, - Buffer_Flags::vertex_buffer - ); - cb.init( - dev, - "Line Renderer cbuffer", - sizeof(CBuffer), - Buffer_Flags::constant_buffer - ); - shader = (Shader*)assets->load("debug.csh"); - vert_binding = shader->binding_index("verts"); - cbuffer_binding = shader->descriptor_binding("cbuf"); - assert(vert_binding >= 0); - assert(cbuffer_binding >= 0); - verts = (Vertex*)vb.map(dev); - cur = 0; - } - - void destroy(Device* dev) { - vb.unmap(dev); - vb.destroy(dev); - cb.destroy(dev); - } - - void begin(int wi, int he) { - cur = 0; - w = wi; - h = he; - cur_col = v3f(1.0f, 1.0f, 1.0f); - } - - void colour(const v3f& c) { - cur_col = c; - } - - void add_line(const v3f& s, const v3f& e) { - if (cur >= max_lines) { - assert(0); - return; - } - Vertex& a = verts[cur * 2]; - Vertex& b = verts[cur * 2 + 1]; - a.x = s.x; - a.y = s.y; - a.z = s.z; - b.x = e.x; - b.y = e.y; - b.z = e.z; - a.r = cur_col.x; - a.g = cur_col.y; - a.b = cur_col.z; - b.r = cur_col.x; - b.g = cur_col.y; - b.b = cur_col.z; - cur++; - } - - void add_box(const AABB& b) { - add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.max.x, b.max.y, b.min.z)); - add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.max.x, b.min.y, b.max.z)); - add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.min.x, b.max.y, b.max.z)); - add_line(v3f(b.max.x, b.min.y, b.min.z), v3f(b.max.x, b.max.y, b.min.z)); - add_line(v3f(b.max.x, b.min.y, b.min.z), v3f(b.max.x, b.min.y, b.max.z)); - add_line(v3f(b.min.x, b.max.y, b.max.z), v3f(b.min.x, b.min.y, b.max.z)); - add_line(v3f(b.min.x, b.max.y, b.min.z), v3f(b.max.x, b.max.y, b.min.z)); - add_line(v3f(b.min.x, b.max.y, b.min.z), v3f(b.min.x, b.max.y, b.max.z)); - add_line(v3f(b.min.x, b.min.y, b.max.z), v3f(b.max.x, b.min.y, b.max.z)); - add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.max.x, b.min.y, b.min.z)); - add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.min.x, b.max.y, b.min.z)); - add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.min.x, b.min.y, b.max.z)); - } - - void flush( - const Camera& cam, - Device* dev, - Arena* a, - Render_Pass& rp - ) { - if (!cur) return; - CBuffer* c = (CBuffer*)cb.map(dev); - c->vp = cam.get_proj() * cam.get_view(); - cb.unmap(dev); - Pipeline_Builder pb(a, dev); - Context& ctx = dev->get_ctx(); - cb.update(ctx); - vb.update(ctx); - pb.begin(); - pb.shader(shader->id); - pb.cbuffer(cbuffer_binding, cb.gpuonly); - pb.vertex_format(shader->vf); - pb.geo(Geo_Type::lines); - Pipeline& pip = pb.build(); - Vertex_Buffer_Binding binding[] = {{ - .id = vb.gpuonly, - .offset = 0, - .target = vert_binding - }, {}}; - Draw d{}; - d.verts = binding; - d.vertex_count = cur * 2; - d.instance_count = 1; - ctx.submit(d, pip, rp); - cur = 0; - } -}; - struct Config_Buffer { float offset[2]; }; @@ -744,6 +619,7 @@ struct C2 : public App { ); clamped_linear = create_clamped_linear(dev); ui = UI::create(dev, this, &ui_arena, ui_shader->id); + init_editor(ui); lr.init(dev, &assets); assert(per_frame != 0); vbo = upload_verts(dev); @@ -862,7 +738,8 @@ struct C2 : public App { v3f(1.0f, 0.0f, 0.0f) ); camera.asp = (float)bb.w / (float)bb.h; - camera.update(*this); + camera.update_orbit(*this); + camera.update(); scene.update(camera, dev); ctx.debug_push("scene"); ctx.debug_push("depth prepass"); @@ -888,19 +765,18 @@ struct C2 : public App { ctx.debug_pop(); if (mjp(mbtn_left)) { - std::tie(selected_model, selected_mesh) = - scene.pick(camera, w, h, mx, my); + auto [a, b] = scene.pick(camera, w, h, mx, my); + editor_on_select(a, b); } lr.colour(v3f(1.0f, 0.0f, 0.0f)); - if (selected_model) { - lr.add_box(selected_model->bounds[selected_mesh]); - } + editor_draw(lr); ctx.debug_push("debug"); pb.begin_rp(); pb.rp_target(dev->get_backbuffer(), Clear_Mode::restore); + pb.rp_depth_target(dev->get_depth_target(), Clear_Mode::restore); lr.flush(camera, dev, &frame_arena, pb.build_rp()); ctx.debug_pop(); @@ -916,6 +792,7 @@ struct C2 : public App { lr.destroy(dev); eprobe.destroy(dev); ui->destroy(); + deinit_editor(); assets.destroy(); dev->destroy_texture(default_texture); dev->destroy_sampler(clamped_linear); diff --git a/camera.cpp b/camera.cpp new file mode 100644 index 0000000..59a604e --- /dev/null +++ b/camera.cpp @@ -0,0 +1,25 @@ +#include "camera.hpp" + +void Camera::init(float vfov, const v3f& f, const v3f& p) { + fov = vfov; + forward = f; + position = p; + near = 0.1f; + far = 1000.0f; + asp = 1.0f; +} + +void Camera::update() { + v3f up(0.0f, 1.0f, 0.0f); + view = m4f::lookat(position, position + forward, up); + proj = m4f::pers(fov, asp, near, far); +} + +const m4f& Camera::get_view() const { + return view; +} + +const m4f& Camera::get_proj() const { + return proj; +} + diff --git a/camera.hpp b/camera.hpp new file mode 100644 index 0000000..f88b4fe --- /dev/null +++ b/camera.hpp @@ -0,0 +1,16 @@ +#ifndef camera_hpp +#define camera_hpp + +#include "maths.hpp" + +struct Camera { + float fov, near, far, asp; + v3f forward, position; + m4f view, proj; + void init(float vfov, const v3f& f, const v3f& p); + void update(); + const m4f& get_view() const; + const m4f& get_proj() const; +}; + +#endif diff --git a/configure.lua b/configure.lua index 2c5672b..c716c33 100644 --- a/configure.lua +++ b/configure.lua @@ -1,13 +1,16 @@ config = { c2 = { "app", + "asset", "c2", - "video", + "camera", + "debugdraw", + "editor", + "maths", + "model", "pipeline", - "asset", "ui", - "maths", - "model" + "video", }, qstd = { "memory", diff --git a/debugdraw.cpp b/debugdraw.cpp new file mode 100644 index 0000000..43527ab --- /dev/null +++ b/debugdraw.cpp @@ -0,0 +1,119 @@ +#include "asset.hpp" +#include "camera.hpp" +#include "debugdraw.hpp" +#include "video.hpp" +extern "C" { +#include "plat.h" +} + +void Line_Renderer::init(Device* dev, Asset_Arena* assets) { + vb.init( + dev, + "Line Renderer mesh", + max_lines * sizeof(Vertex) * 2, + Buffer_Flags::vertex_buffer + ); + cb.init( + dev, + "Line Renderer cbuffer", + sizeof(CBuffer), + Buffer_Flags::constant_buffer + ); + shader = (Shader*)assets->load("debug.csh"); + vert_binding = shader->binding_index("verts"); + cbuffer_binding = shader->descriptor_binding("cbuf"); + assert(vert_binding >= 0); + assert(cbuffer_binding >= 0); + verts = (Vertex*)vb.map(dev); + cur = 0; +} + +void Line_Renderer::destroy(Device* dev) { + vb.unmap(dev); + vb.destroy(dev); + cb.destroy(dev); +} + +void Line_Renderer::begin(int wi, int he) { + cur = 0; + w = wi; + h = he; + cur_col = v3f(1.0f, 1.0f, 1.0f); +} + +void Line_Renderer::colour(const v3f& c) { + cur_col = c; +} + +void Line_Renderer::add_line(const v3f& s, const v3f& e) { + if (cur >= max_lines) { + assert(0); + return; + } + Vertex& a = verts[cur * 2]; + Vertex& b = verts[cur * 2 + 1]; + a.x = s.x; + a.y = s.y; + a.z = s.z; + b.x = e.x; + b.y = e.y; + b.z = e.z; + a.r = cur_col.x; + a.g = cur_col.y; + a.b = cur_col.z; + b.r = cur_col.x; + b.g = cur_col.y; + b.b = cur_col.z; + cur++; +} + +void Line_Renderer::add_box(const AABB& b) { + add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.max.x, b.max.y, b.min.z)); + add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.max.x, b.min.y, b.max.z)); + add_line(v3f(b.max.x, b.max.y, b.max.z), v3f(b.min.x, b.max.y, b.max.z)); + add_line(v3f(b.max.x, b.min.y, b.min.z), v3f(b.max.x, b.max.y, b.min.z)); + add_line(v3f(b.max.x, b.min.y, b.min.z), v3f(b.max.x, b.min.y, b.max.z)); + add_line(v3f(b.min.x, b.max.y, b.max.z), v3f(b.min.x, b.min.y, b.max.z)); + add_line(v3f(b.min.x, b.max.y, b.min.z), v3f(b.max.x, b.max.y, b.min.z)); + add_line(v3f(b.min.x, b.max.y, b.min.z), v3f(b.min.x, b.max.y, b.max.z)); + add_line(v3f(b.min.x, b.min.y, b.max.z), v3f(b.max.x, b.min.y, b.max.z)); + add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.max.x, b.min.y, b.min.z)); + add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.min.x, b.max.y, b.min.z)); + add_line(v3f(b.min.x, b.min.y, b.min.z), v3f(b.min.x, b.min.y, b.max.z)); +} + +void Line_Renderer::flush( + const Camera& cam, + Device* dev, + Arena* a, + Render_Pass& rp +) { + if (!cur) return; + CBuffer* c = (CBuffer*)cb.map(dev); + c->vp = cam.get_proj() * cam.get_view(); + cb.unmap(dev); + Pipeline_Builder pb(a, dev); + Context& ctx = dev->get_ctx(); + cb.update(ctx); + vb.update(ctx); + pb.begin(); + pb.shader(shader->id); + pb.cbuffer(cbuffer_binding, cb.gpuonly); + pb.vertex_format(shader->vf); + pb.geo(Geo_Type::lines); + if (rp.depth.id) + pb.depth(true, false, Depth_Mode::less); + Pipeline& pip = pb.build(); + Vertex_Buffer_Binding binding[] = {{ + .id = vb.gpuonly, + .offset = 0, + .target = vert_binding + }, {}}; + Draw d{}; + d.verts = binding; + d.vertex_count = cur * 2; + d.instance_count = 1; + ctx.submit(d, pip, rp); + cur = 0; +} + diff --git a/debugdraw.hpp b/debugdraw.hpp new file mode 100644 index 0000000..e5142dc --- /dev/null +++ b/debugdraw.hpp @@ -0,0 +1,42 @@ +#ifndef debugdraw_hpp +#define debugdraw_hpp + +#include "maths.hpp" +#include "video.hpp" + +struct Camera; + +struct Line_Renderer { + static constexpr int max_lines = 1024; + Staged_Buffer vb, cb; + Shader* shader; + int vert_binding, cbuffer_binding; + int cur; + int w, h; + v3f cur_col; + + struct Vertex { + float x, y, z; + float r, g, b; + }* verts; + + struct CBuffer { + m4f vp; + }; + + void init(Device* dev, Asset_Arena* assets); + + void destroy(Device* dev); + void begin(int wi, int he); + void colour(const v3f& c); + void add_line(const v3f& s, const v3f& e); + void add_box(const AABB& b); + void flush( + const Camera& cam, + Device* dev, + Arena* a, + Render_Pass& rp + ); +}; + +#endif diff --git a/editor.cpp b/editor.cpp new file mode 100644 index 0000000..b4555f3 --- /dev/null +++ b/editor.cpp @@ -0,0 +1,61 @@ +#include "debugdraw.hpp" +#include "editor.hpp" +#include "model.hpp" +#include "ui.hpp" + +static struct { + UI* ui; + UI::Toolbar* toolbar; + UI::Button* mat_btn; + UI::Modal* mat_win; + Model_Instance* selected_inst; + int selected_mesh; +} editor; + +static int mat_win_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::destroy) + editor.mat_btn->enable(); + return 0; +} + +static int mat_btn_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::click) { + editor.mat_win = editor.ui->create_element<UI::Modal>( + editor.ui->root, + "Material Editor" + ); + editor.mat_win->handler = mat_win_handler; + editor.mat_btn->disable(); + } + return 0; +} + +void init_editor(UI* ui) { + editor.ui = ui; + editor.toolbar = ui->create_element<UI::Toolbar>(ui->root); + editor.mat_btn = ui->create_element<UI::Button>( + editor.toolbar, + "Edit Material" + ); + editor.mat_win = 0; + editor.mat_btn->handler = mat_btn_handler; +} + +void deinit_editor() { + +} + +void editor_on_select(Model_Instance* instance, int mesh) { + editor.selected_inst = instance; + editor.selected_mesh = mesh; +} + +void editor_draw(Line_Renderer& lr) { + if (editor.selected_inst) { + lr.add_box( + editor.selected_inst->bounds[editor.selected_mesh] + ); + } +} diff --git a/editor.hpp b/editor.hpp new file mode 100644 index 0000000..bb6a6a3 --- /dev/null +++ b/editor.hpp @@ -0,0 +1,13 @@ +#ifndef editor_hpp +#define editor_hpp + +struct UI; +struct Model_Instance; +struct Line_Renderer; + +void init_editor(UI* ui); +void deinit_editor(); +void editor_on_select(Model_Instance* instance, int mesh); +void editor_draw(Line_Renderer& lr); + +#endif @@ -178,9 +178,9 @@ m4f m4f::orth(float l, float r, float b, float t, float n, float f) { return res; } -m4f m4f::inverse() { +m4f m4f::inverse() const { const float* mm = (float*)m; - + m4f r; float t0 = mm[10] * mm[15]; float t1 = mm[14] * mm[11]; float t2 = mm[6] * mm[15]; @@ -205,17 +205,12 @@ m4f m4f::inverse() { float t21 = mm[8] * mm[1]; float t22 = mm[0] * mm[5]; float t23 = mm[4] * mm[1]; - - m4f r(1.0f); float* o = (float*)r.m; - o[0] = (t0 * mm[5] + t3 * mm[9] + t4 * mm[13]) - (t1 * mm[5] + t2 * mm[9] + t5 * mm[13]); o[1] = (t1 * mm[1] + t6 * mm[9] + t9 * mm[13]) - (t0 * mm[1] + t7 * mm[9] + t8 * mm[13]); o[2] = (t2 * mm[1] + t7 * mm[5] + t10 * mm[13]) - (t3 * mm[1] + t6 * mm[5] + t11 * mm[13]); o[3] = (t5 * mm[1] + t8 * mm[5] + t11 * mm[9]) - (t4 * mm[1] + t9 * mm[5] + t10 * mm[9]); - float d = 1.0f / (mm[0] * o[0] + mm[4] * o[1] + mm[8] * o[2] + mm[12] * o[3]); - o[0] = d * o[0]; o[1] = d * o[1]; o[2] = d * o[2]; @@ -232,11 +227,10 @@ m4f m4f::inverse() { o[13] = d * ((t20 * mm[14] + t12 * mm[2] + t19 * mm[10]) - (t18 * mm[10] + t21 * mm[14] + t13 * mm[2])); o[14] = d * ((t18 * mm[6] + t23 * mm[14] + t15 * mm[2]) - (t22 * mm[14] + t14 * mm[2] + t19 * mm[6])); o[15] = d * ((t22 * mm[10] + t16 * mm[2] + t21 * mm[6]) - (t20 * mm[6] + t23 * mm[10] + t17 * mm[2])); - return r; } -m4f m4f::transposed() { +m4f m4f::transposed() const { m4f r(1.0f); r.m[0][0] = m[0][0]; r.m[1][0] = m[0][1]; @@ -489,8 +489,8 @@ struct m4f { static v4f transform(m4f m, v4f v); static AABB transform(m4f m, AABB aabb); - m4f inverse(); - m4f transposed(); + m4f inverse() const; + m4f transposed() const; }; inline static v4f make_color(uint32_t rgb, uint8_t a) { @@ -1,3 +1,4 @@ +#include "camera.hpp" #include "maths.hpp" #include "model.hpp" @@ -257,24 +258,6 @@ void Material_Loader::unload(Asset* a) { (void)a; } -void Camera::init(float vfov, const v3f& f, const v3f& p) { - fov = vfov; - forward = f; - position = p; - near = 0.1f; - far = 1000.0f; - asp = 1.0f; -} - -m4f Camera::get_view() const { - v3f up(0.0f, 1.0f, 0.0f); - return m4f::lookat(position, position + forward, up); -} - -m4f Camera::get_proj() const { - return m4f::pers(fov, asp, near, far); -} - void Model_Instance::init(Device* dev, Heap* h, Model* model) { m = model; mvp = dev->create_buffer( @@ -7,6 +7,8 @@ #include <tuple> +struct Camera; + struct Material : public Asset { float metalness, roughness, ao; v3f albedo; @@ -82,14 +84,6 @@ struct Material_Loader : public Asset_Loader { void unload(Asset* a) override; }; -struct Camera { - float fov, near, far, asp; - v3f forward, position; - void init(float vfov, const v3f& f, const v3f& p); - m4f get_view() const; - m4f get_proj() const; -}; - struct Model_Instance { Buffer_Id mvp; Buffer_Id mat; |