diff options
-rw-r--r-- | editor/Cargo.lock | 1098 | ||||
-rw-r--r-- | editor/Cargo.toml | 10 | ||||
-rw-r--r-- | editor/build.rs | 20 | ||||
-rw-r--r-- | editor/src/lib.rs | 2 | ||||
-rw-r--r-- | editor/src/main.rs | 89 | ||||
-rw-r--r-- | examples/game_demo/game_demo.c | 24 | ||||
-rw-r--r-- | scripts/apidocs/gen_apidocs.py | 10 | ||||
-rw-r--r-- | scripts/apidocs/index.html | 174 | ||||
-rw-r--r-- | src/core/camera.c | 9 | ||||
-rw-r--r-- | src/core/camera.h | 4 | ||||
-rw-r--r-- | src/core/core.c | 4 | ||||
-rw-r--r-- | src/maths/primitives.c | 10 | ||||
-rw-r--r-- | src/new_render/pbr.c | 2 | ||||
-rw-r--r-- | src/new_render/pbr.h | 9 | ||||
-rw-r--r-- | src/new_render/render.c | 8 | ||||
-rw-r--r-- | src/new_render/render.h | 5 | ||||
-rw-r--r-- | src/new_render/render_types.h | 7 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 3 | ||||
-rw-r--r-- | src/resources/gltf.c | 476 | ||||
-rw-r--r-- | src/systems/input.h | 14 | ||||
-rw-r--r-- | src/systems/terrain.h | 10 |
21 files changed, 438 insertions, 1550 deletions
diff --git a/editor/Cargo.lock b/editor/Cargo.lock deleted file mode 100644 index 66ea6d0..0000000 --- a/editor/Cargo.lock +++ /dev/null @@ -1,1098 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ab_glyph" -version = "0.2.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79faae4620f45232f599d9bc7b290f88247a0834162c4495ab2f02d60004adfb" -dependencies = [ - "ab_glyph_rasterizer", - "owned_ttf_parser", -] - -[[package]] -name = "ab_glyph_rasterizer" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" - -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "bindgen" -version = "0.69.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" -dependencies = [ - "bitflags 2.6.0", - "cexpr", - "clang-sys", - "itertools", - "lazy_static", - "lazycell", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.72", - "which", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" - -[[package]] -name = "cc" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" - -[[package]] -name = "celeritas" -version = "0.1.0" -dependencies = [ - "celeritas-sys", - "egui", - "egui_glfw", - "gl", - "serde", - "serde_json", -] - -[[package]] -name = "celeritas-sys" -version = "0.1.0" -dependencies = [ - "bindgen", - "serde", -] - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "cli-clipboard" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04087c1d4a2aa259784a563932aee09cbb0869d490775e051096174b070f3e3d" -dependencies = [ - "clipboard-win", - "objc", - "objc-foundation", - "objc_id", - "wl-clipboard-rs", - "x11-clipboard", -] - -[[package]] -name = "clipboard-win" -version = "4.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" -dependencies = [ - "error-code", - "str-buf", - "winapi", -] - -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - -[[package]] -name = "derive-new" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "downcast-rs" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" - -[[package]] -name = "ecolor" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20930a432bbd57a6d55e07976089708d4893f3d556cf42a0d79e9e321fa73b10" - -[[package]] -name = "editor" -version = "0.1.0" -dependencies = [ - "celeritas", - "egui", - "egui_glfw", - "gl", -] - -[[package]] -name = "egui" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584c5d1bf9a67b25778a3323af222dbe1a1feb532190e103901187f92c7fe29a" -dependencies = [ - "ahash", - "epaint", - "nohash-hasher", -] - -[[package]] -name = "egui_glfw" -version = "0.55.1" -source = "git+https://github.com/omnisci3nce/egui_glfw.git?rev=67b432695433feb59761f3ae984b966ca3da31db#67b432695433feb59761f3ae984b966ca3da31db" -dependencies = [ - "cli-clipboard", - "egui", - "gl", - "glfw", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "emath" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c3a552cfca14630702449d35f41c84a0d15963273771c6059175a803620f3f" - -[[package]] -name = "epaint" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b381f8b149657a4acf837095351839f32cd5c4aec1817fc4df84e18d76334176" -dependencies = [ - "ab_glyph", - "ahash", - "ecolor", - "emath", - "nohash-hasher", - "parking_lot", -] - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "gethostname" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "gl" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" -dependencies = [ - "gl_generator", -] - -[[package]] -name = "gl_generator" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" -dependencies = [ - "khronos_api", - "log", - "xml-rs", -] - -[[package]] -name = "glfw" -version = "0.55.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a310dfc7966e5340f5d0e314fa7eed8888f1cd3bfcaa433d35cbd32d430e50c" -dependencies = [ - "bitflags 1.3.2", - "glfw-sys", - "objc", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", - "winapi", -] - -[[package]] -name = "glfw-sys" -version = "5.0.0+3.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dfc32d45fb58ff38b112696907963a7d671e9cf742b16f882062169a053cf88" -dependencies = [ - "cmake", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "khronos_api" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nix" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nohash-hasher" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - -[[package]] -name = "objc_id" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -dependencies = [ - "objc", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "os_pipe" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d73ba8daf8fac13b0501d1abeddcfe21ba7401ada61a819144b6c2a4f32209" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "owned_ttf_parser" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490d3a563d3122bf7c911a59b0add9389e5ec0f5f0c3ac6b91ff235a0e6a7f90" -dependencies = [ - "ttf-parser", -] - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - -[[package]] -name = "petgraph" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - -[[package]] -name = "prettyplease" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" -dependencies = [ - "proc-macro2", - "syn 2.0.72", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "raw-window-handle" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" - -[[package]] -name = "raw-window-handle" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" - -[[package]] -name = "redox_syscall" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" -dependencies = [ - "bitflags 2.6.0", -] - -[[package]] -name = "regex" -version = "1.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.6.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - -[[package]] -name = "serde_json" -version = "1.0.120" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys", -] - -[[package]] -name = "thiserror" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - -[[package]] -name = "tree_magic_mini" -version = "3.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469a727cac55b41448315cc10427c069c618ac59bb6a4480283fcd811749bdc2" -dependencies = [ - "fnv", - "home", - "memchr", - "nom", - "once_cell", - "petgraph", -] - -[[package]] -name = "ttf-parser" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8686b91785aff82828ed725225925b33b4fde44c4bb15876e5f7c832724c420a" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wayland-client" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" -dependencies = [ - "bitflags 1.3.2", - "downcast-rs", - "libc", - "nix", - "wayland-commons", - "wayland-scanner", - "wayland-sys", -] - -[[package]] -name = "wayland-commons" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" -dependencies = [ - "nix", - "once_cell", - "smallvec", - "wayland-sys", -] - -[[package]] -name = "wayland-protocols" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" -dependencies = [ - "bitflags 1.3.2", - "wayland-client", - "wayland-commons", - "wayland-scanner", -] - -[[package]] -name = "wayland-scanner" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" -dependencies = [ - "proc-macro2", - "quote", - "xml-rs", -] - -[[package]] -name = "wayland-sys" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" -dependencies = [ - "pkg-config", -] - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-wsapoll" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1eafc5f679c576995526e81635d0cf9695841736712b4e892f87abbe6fed3f28" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "wl-clipboard-rs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "981a303dfbb75d659f6612d05a14b2e363c103d24f676a2d44a00d18507a1ad9" -dependencies = [ - "derive-new", - "libc", - "log", - "nix", - "os_pipe", - "tempfile", - "thiserror", - "tree_magic_mini", - "wayland-client", - "wayland-protocols", -] - -[[package]] -name = "x11-clipboard" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980b9aa9226c3b7de8e2adb11bf20124327c054e0e5812d2aac0b5b5a87e7464" -dependencies = [ - "x11rb", -] - -[[package]] -name = "x11rb" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" -dependencies = [ - "gethostname", - "nix", - "winapi", - "winapi-wsapoll", - "x11rb-protocol", -] - -[[package]] -name = "x11rb-protocol" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" -dependencies = [ - "nix", -] - -[[package]] -name = "xml-rs" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] diff --git a/editor/Cargo.toml b/editor/Cargo.toml deleted file mode 100644 index 580e726..0000000 --- a/editor/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "editor" -version = "0.1.0" -edition = "2021" - -[dependencies] -celeritas = { path = "../bindgen/rust"} -egui = "0.27.1" -egui_glfw = { git = "https://github.com/omnisci3nce/egui_glfw.git", rev = "67b432695433feb59761f3ae984b966ca3da31db" } -gl = "0.14.0"
\ No newline at end of file diff --git a/editor/build.rs b/editor/build.rs deleted file mode 100644 index c37df51..0000000 --- a/editor/build.rs +++ /dev/null @@ -1,20 +0,0 @@ -fn main() { - // Tell cargo to look for shared libraries in the specified directory - // TODO: we need to look based on OS - // println!("cargo:rustc-link-search=/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/debug"); - // // println!("cargo:rustc-link-search=../../build/windows/x64/debug"); - - // // Tell cargo to tell rustc to link the system bzip2 - // // shared library. - // println!("cargo:rustc-link-lib=framework=CoreFoundation"); - // println!("cargo:rustc-link-lib=framework=Cocoa"); - // println!("cargo:rustc-link-lib=framework=IOKit"); - // println!("cargo:rustc-link-lib=framework=OpenGL"); - - // println!("cargo:rustc-link-lib=core_static"); - // println!("cargo:rustc-link-lib=glfw3"); - // println!("cargo:rustc-link-lib=framework=Cocoa"); - // println!("cargo:rustc-link-lib=framework=Foundation"); - // println!("cargo:rustc-link-lib=framework=QuartzCore"); - -}
\ No newline at end of file diff --git a/editor/src/lib.rs b/editor/src/lib.rs deleted file mode 100644 index 495da30..0000000 --- a/editor/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ - -// Scene storage diff --git a/editor/src/main.rs b/editor/src/main.rs deleted file mode 100644 index 962a4cc..0000000 --- a/editor/src/main.rs +++ /dev/null @@ -1,89 +0,0 @@ -use std::{ - ffi::CString, - fs::{self, File}, - io::Write, - path::Path, - ptr::{self, addr_of_mut}, -}; - - -use egui_backend::egui::{vec2, Pos2, Rect}; -use egui_glfw as egui_backend; -use egui_glfw::glfw::{fail_on_errors, Context}; - -use egui_glfw::glfw; - -use celeritas::*; -use ffi::*; - -fn main() { - unsafe { - let p: *mut GLFWwindow = ptr::null_mut(); - Core_Bringup(p); - - // let core = get_global_core(); - - let camera_pos = Vec3 { - x: 18.9, - y: 10.6, - z: 11.6, - }; - let camera_front = Vec3 { - x: -0.6, - y: -0.2, - z: -0.7, - }; - let mut camera = Camera_Create( - camera_pos, - camera_front, - Vec3 { - x: 0.0, - y: 1.0, - z: 0.0, - }, - 45.0, - ); - SetCamera(camera); - - let mut cube_geo = Geo_CreateCuboid(f32x3 { - x: 2.0, - y: 2.0, - z: 2.0, - }); - - let scene = SerializableScene { - sun: DirectionalLight { - direction: Vec3 { - x: 0.0, - y: 1.0, - z: 0.0, - }, - ambient: Vec3 { - x: 1.0, - y: 1.0, - z: 1.0, - }, - diffuse: Vec3 { - x: 1.0, - y: 1.0, - z: 1.0, - }, - specular: Vec3 { - x: 0.0, - y: 0.0, - z: 0.0, - }, - }, - point_lights: [None, None, None, None], - camera_orientation: (camera_pos, camera_front), - models: vec![], - }; - - let scene_path = Path::new("default_scene.json"); - scene.store_to_file(scene_path); - - let rehydrated_scene = SerializableScene::load_from_file(scene_path); - dbg!(&rehydrated_scene); - - } -} diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c index 5b69251..43ad91f 100644 --- a/examples/game_demo/game_demo.c +++ b/examples/game_demo/game_demo.c @@ -34,7 +34,7 @@ int main() { // TODO: Move camera with model // --- Render Scene - Vec3 camera_pos = vec3(0.0, 5.0, 0.0); + Vec3 camera_pos = vec3(0.0, 1.0, 2.0); Camera cam = Camera_Create(camera_pos, VEC3_NEG_Z, VEC3_Y, 45.0); SetCamera(cam); // update the camera in RenderScene @@ -79,20 +79,24 @@ int main() { MaterialHandle crate_mat_handle = Material_pool_insert(Render_GetMaterialPool(), &crate_mat); // ModelHandle cube_handle = ModelLoad_gltf("assets/models/gltf/Cube/glTF/Cube.gltf", false); - // ModelHandle cube_handle = ModelLoad_gltf("../../assets/prototyper/prototyper_m.gltf", false); - // Model* Cube = MODEL_GET(cube_handle); - // RenderEnt cube_r = { .mesh = &Cube->meshes->data[0], - // .material = &Cube->materials->data[0], - // .affine = mat4_ident(), - // .casts_shadows = true }; + ModelHandle cube_handle = ModelLoad_gltf("../../assets/prototyper/prototyper_m.gltf", false); + Model* Cube = MODEL_GET(cube_handle); + RenderEnt proto_1 = { .mesh = Cube->meshes[0], + .material = Cube->materials[0], + .affine = mat4_ident(), + .flags = (REND_ENT_CASTS_SHADOWS | REND_ENT_VISIBLE) }; + RenderEnt proto_2 = { .mesh = Cube->meshes[1], + .material = Cube->materials[1], + .affine = mat4_ident(), + .flags = (REND_ENT_CASTS_SHADOWS | REND_ENT_VISIBLE) }; RenderEnt crate_renderable = { .mesh = crate_mesh_handle, .material = crate_mat_handle, .affine = mat4_scale(3.0), .flags = (REND_ENT_CASTS_SHADOWS | REND_ENT_VISIBLE) }; - RenderEnt entities[] = { crate_renderable }; - size_t entity_count = 1; + RenderEnt entities[] = { proto_1, proto_2, crate_renderable }; + size_t entity_count = 2; // --- Transforms // TransformHierarchy* scene_tree = TransformHierarchy_Create(); @@ -107,7 +111,7 @@ int main() { draw_debug = !draw_debug; } - Camera_Update(&cam); + FlyCamera_Update(&cam); SetCamera(cam); // BEGIN Draw calls diff --git a/scripts/apidocs/gen_apidocs.py b/scripts/apidocs/gen_apidocs.py index cfce6ec..d01e441 100644 --- a/scripts/apidocs/gen_apidocs.py +++ b/scripts/apidocs/gen_apidocs.py @@ -33,7 +33,7 @@ page_start = """ page_header = """ <header> - <h1>CELERITAS CORE DOCS</h1> + <h1>CELERITAS CORE API DOCS</h1> </header> """ @@ -56,9 +56,11 @@ def emit_function_sig(signature: str) -> str: """ categories = { - "RAL": "src/ral", + "Core": "src/core", "Render": "src/new_render", - "Maths": "src/maths" + "Maths": "src/maths", + "RAL": "src/ral", + "Systems": "src/systems", } def find_pub_functions_in_folder(folder_path): @@ -85,6 +87,8 @@ def find_pub_functions_in_file(file_path): signature = match.group(0) if signature.startswith("PUB "): signature = signature[4:] + if signature.startswith("c_static_inline "): + signature = signature[16:] print(signature) functions.append(signature) diff --git a/scripts/apidocs/index.html b/scripts/apidocs/index.html index 0c19c0c..a72dbf3 100644 --- a/scripts/apidocs/index.html +++ b/scripts/apidocs/index.html @@ -20,227 +20,283 @@ <main> <header> - <h1>CELERITAS CORE DOCS</h1> + <h1>CELERITAS CORE API DOCS</h1> </header> -<h3>RAL</h3><ul class="category-list"> +<h3>Core</h3><ul class="category-list"> <li class="signature"> - <pre><code class="language-c">void GPU_Renderpass_Destroy(GPU_Renderpass* pass)</code></pre> + <pre><code class="language-c">Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GraphicsPipeline_Destroy(GPU_Pipeline* pipeline)</code></pre> + <pre><code class="language-c">Mat4 Camera_View2D(Camera* c)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">GPU_CmdEncoder GPU_CmdEncoder_Create()</code></pre> + <pre><code class="language-c">void FlyCamera_Update(Camera* camera)</code></pre> + </li> + </ul><h3>Render</h3><ul class="category-list"> + <li class="signature"> + <pre><code class="language-c">Skybox Skybox_Create(const char** face_paths, int n)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_CmdEncoder_Destroy(GPU_CmdEncoder* encoder)</code></pre> + <pre><code class="language-c">void Skybox_Draw(Skybox* skybox, Camera camera)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_CmdEncoder_Begin(GPU_CmdEncoder* encoder)</code></pre> + <pre><code class="language-c">void SetCamera(Camera camera)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_CmdEncoder_Finish(GPU_CmdEncoder* encoder)</code></pre> + <pre><code class="language-c">void SetMainLight(DirectionalLight light)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_CmdEncoder_BeginRender(GPU_CmdEncoder* encoder, GPU_Renderpass* renderpass)</code></pre> + <pre><code class="language-c">void PBR_Init(PBR_Storage* storage)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_CmdEncoder_EndRender(GPU_CmdEncoder* encoder)</code></pre> + <pre><code class="language-c">Material PBRMaterialDefault()</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer)</code></pre> + <pre><code class="language-c">ShaderDataLayout PBRMaterial_GetLayout(void* data)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">BufferHandle GPU_BufferCreate(u64 size, GPU_BufferType buf_type, GPU_BufferFlags flags, const void* data)</code></pre> + <pre><code class="language-c">void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_height)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_BufferDestroy(BufferHandle handle)</code></pre> + <pre><code class="language-c">void Shadow_Run(RenderEnt* entities, size_t entity_count)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_BufferUpload(BufferHandle buffer, size_t n_bytes, const void* data)</code></pre> + <pre><code class="language-c">void Shadow_DrawDebugQuad()</code></pre> </li> <li class="signature"> - <pre><code class="language-c">TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void* data)</code></pre> + <pre><code class="language-c">TextureHandle Shadow_GetShadowMapTexture(Shadow_Storage* storage)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_TextureDestroy(TextureHandle handle)</code></pre> + <pre><code class="language-c">void Immdraw_Init(Immdraw_Storage* storage)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_TextureUpload(TextureHandle handle, size_t n_bytes, const void* data)</code></pre> + <pre><code class="language-c">void Immdraw_Shutdown(Immdraw_Storage* storage)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeBindPipeline(GPU_CmdEncoder* encoder, GPU_Pipeline* pipeline)</code></pre> + <pre><code class="language-c">void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData data)</code></pre> + <pre><code class="language-c">void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeSetVertexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf)</code></pre> + <pre><code class="language-c">void Immdraw_Sphere(Transform tf, f32 size, Vec4 colour, bool wireframe)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf)</code></pre> + <pre><code class="language-c">void Immdraw_TransformGizmo(Transform tf, f32 size)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count)</code></pre> + <pre><code class="language-c">void EncodeDrawModel(Handle model, Mat4 transform)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count)</code></pre> + <pre><code class="language-c">void EncodeDrawMesh(Mesh* mesh, Material* material, Mat4 affine)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">bool GPU_Backend_BeginFrame()</code></pre> + <pre><code class="language-c">void Renderer_Shutdown(Renderer* renderer)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void GPU_Backend_EndFrame()</code></pre> + <pre><code class="language-c">size_t Renderer_GetMemReqs()</code></pre> </li> - </ul><h3>Render</h3><ul class="category-list"> + <li class="signature"> - <pre><code class="language-c">void EncodeDrawModel(Handle model, Mat4 transform)</code></pre> + <pre><code class="language-c">void Render_FrameBegin(Renderer* renderer)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void EncodeDrawMesh(Mesh* mesh, Material* material, Mat4 affine)</code></pre> + <pre><code class="language-c">void Render_FrameEnd(Renderer* renderer)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_Init(Immdraw_Storage* storage)</code></pre> + <pre><code class="language-c">void Render_RenderEntities(RenderEnt* entities, size_t entity_count)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_Shutdown(Immdraw_Storage* storage)</code></pre> + <pre><code class="language-c">TextureData TextureDataLoad(const char* path, bool invert_y)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_Plane(Transform tf, Vec4 colour, bool wireframe)</code></pre> + <pre><code class="language-c">void TextureUpload(TextureHandle handle, size_t n_bytes, const void* data)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_Cuboid(Transform tf, Vec4 colour, bool wireframe)</code></pre> + <pre><code class="language-c">TextureHandle TextureLoadFromFile(const char* path)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_Sphere(Transform tf, f32 size, Vec4 colour, bool wireframe)</code></pre> + <pre><code class="language-c">ModelHandle ModelLoad(const char* debug_name, const char* filepath)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Immdraw_TransformGizmo(Transform tf, f32 size)</code></pre> + <pre><code class="language-c">Mesh Mesh_Create(Geometry* geometry, bool free_on_upload)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void PBR_Init(PBR_Storage* storage)</code></pre> + <pre><code class="language-c">void Mesh_Delete(Mesh* mesh)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">bool Renderer_Init(RendererConfig config, Renderer* renderer)</code></pre> + <pre><code class="language-c">void DrawMesh(Mesh* mesh, Material* material, Mat4 model)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Renderer_Shutdown(Renderer* renderer)</code></pre> + <pre><code class="language-c">void Render_DrawTerrain()</code></pre> + </li> + </ul><h3>Maths</h3><ul class="category-list"> + <li class="signature"> + <pre><code class="language-c">Vec3 vec3_normalise(Vec3 a)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">size_t Renderer_GetMemReqs()</code></pre> + <pre><code class="language-c">Vec3 vec3_create(f32 x, f32 y, f32 z)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Render_FrameBegin(Renderer* renderer)</code></pre> + <pre><code class="language-c">Vec3 vec3_add(Vec3 a, Vec3 b)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Render_FrameEnd(Renderer* renderer)</code></pre> + <pre><code class="language-c">Vec3 vec3_sub(Vec3 a, Vec3 b)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Render_RenderEntities(RenderEnt* entities, size_t entity_count)</code></pre> + <pre><code class="language-c">Vec3 vec3_mult(Vec3 a, f32 s)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">TextureHandle TextureUpload()</code></pre> + <pre><code class="language-c">Vec3 vec3_div(Vec3 a, f32 s)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">ModelHandle ModelLoad(const char* debug_name, const char* filepath)</code></pre> + <pre><code class="language-c">f32 vec3_len_squared(Vec3 a)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">Mesh Mesh_Create(Geometry* geometry, bool free_on_upload)</code></pre> + <pre><code class="language-c">f32 vec3_len(Vec3 a)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Mesh_Delete(Mesh* mesh)</code></pre> + <pre><code class="language-c">Vec3 vec3_negate(Vec3 a)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void DrawMesh(Mesh* mesh, Material* material, Mat4 model)</code></pre> + <pre><code class="language-c">Vec3 vec3_normalise(Vec3 a)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Render_DrawTerrain()</code></pre> + <pre><code class="language-c">f32 vec3_dot(Vec3 a, Vec3 b)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void SetCamera(Camera camera)</code></pre> + <pre><code class="language-c">Vec3 vec3_cross(Vec3 a, Vec3 b)</code></pre> + </li> + </ul><h3>RAL</h3><ul class="category-list"> + <li class="signature"> + <pre><code class="language-c">void GPU_Renderpass_Destroy(GPU_Renderpass* pass)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void SetPointLight(PointLight light)</code></pre> + <pre><code class="language-c">void GraphicsPipeline_Destroy(GPU_Pipeline* pipeline)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Shadow_Init(Shadow_Storage* storage, u32x2 shadowmap_extents)</code></pre> + <pre><code class="language-c">GPU_CmdEncoder GPU_CmdEncoder_Create()</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Shadow_Run(Shadow_Storage* storage, RenderEnt* entities, size_t entity_count)</code></pre> + <pre><code class="language-c">void GPU_CmdEncoder_Destroy(GPU_CmdEncoder* encoder)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage)</code></pre> + <pre><code class="language-c">void GPU_CmdEncoder_Begin(GPU_CmdEncoder* encoder)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void CubeMapData_Load(const char** face_paths, int n)</code></pre> + <pre><code class="language-c">void GPU_CmdEncoder_Finish(GPU_CmdEncoder* encoder)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void CubeMapData_Free(CubeMapData* cubemap)</code></pre> + <pre><code class="language-c">void GPU_CmdEncoder_BeginRender(GPU_CmdEncoder* encoder, GPU_Renderpass* renderpass)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">TextureHandle CubeMapData_Upload(CubeMapData* cubemap)</code></pre> + <pre><code class="language-c">void GPU_CmdEncoder_EndRender(GPU_CmdEncoder* encoder)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">Skybox Skybox_Create(const char** face_paths, int n)</code></pre> + <pre><code class="language-c">void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer)</code></pre> </li> <li class="signature"> - <pre><code class="language-c">void Skybox_Draw(Skybox* skybox)</code></pre> + <pre><code class="language-c">void GPU_BufferDestroy(BufferHandle handle)</code></pre> </li> - </ul><h3>Maths</h3><ul class="category-list"> + + <li class="signature"> + <pre><code class="language-c">void GPU_BufferUpload(BufferHandle buffer, size_t n_bytes, const void* data)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void* data)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_TextureDestroy(TextureHandle handle)</code></pre> + </li> + <li class="signature"> - <pre><code class="language-c">static inline Vec3 vec3_create(f32 x, f32 y, f32 z)</code></pre> + <pre><code class="language-c">void GPU_TextureUpload(TextureHandle handle, size_t n_bytes, const void* data)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeBindPipeline(GPU_CmdEncoder* encoder, GPU_Pipeline* pipeline)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData data)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeSetVertexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count)</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">bool GPU_Backend_BeginFrame()</code></pre> + </li> + + <li class="signature"> + <pre><code class="language-c">void GPU_Backend_EndFrame()</code></pre> </li> </ul> </main> diff --git a/src/core/camera.c b/src/core/camera.c index cde457b..7bddb7e 100644 --- a/src/core/camera.c +++ b/src/core/camera.c @@ -4,6 +4,9 @@ #include "keys.h" #include "maths.h" +#define CAMERA_SPEED 0.2 +#define CAMERA_SENSITIVITY 0.5 + Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov) { Camera c = { .position = pos, .front = front, .up = up, .fov = fov }; return c; @@ -22,12 +25,12 @@ Mat4 Camera_ViewProj(Camera *c, f32 lens_height, f32 lens_width, Mat4 *out_view, return mat4_mult(view, proj); } -void Camera_Update(Camera *camera) { +void FlyCamera_Update(Camera *camera) { static f32 yaw = 0.0; static f32 pitch = 0.0; // Keyboard - f32 speed = 0.25; + f32 speed = CAMERA_SPEED; Vec3 horizontal = vec3_cross(camera->front, camera->up); if (key_is_pressed(KEYCODE_A) || key_is_pressed(KEYCODE_KEY_LEFT)) { Vec3 displacement = vec3_mult(horizontal, -speed); @@ -62,7 +65,7 @@ void Camera_Update(Camera *camera) { f32 x_offset = mouse.x_delta; f32 y_offset = -mouse.y_delta; - f32 sensitivity = 0.7f; // change this value to your liking + f32 sensitivity = CAMERA_SENSITIVITY; // change this value to your liking x_offset *= sensitivity; y_offset *= sensitivity; diff --git a/src/core/camera.h b/src/core/camera.h index 450f81e..536feca 100644 --- a/src/core/camera.h +++ b/src/core/camera.h @@ -15,7 +15,7 @@ typedef struct Camera { } Camera; /** @brief create a camera */ -Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov); +PUB Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov); /** * @brief Get 3D camera transform matrix @@ -31,7 +31,7 @@ PUB Mat4 Camera_View2D(Camera* c); // TODO: 2D cameras struct Input_State; -void Camera_Update(Camera* camera); +PUB void FlyCamera_Update(Camera* camera); // TODO: (HIGH) Basic reusable camera controls /* diff --git a/src/core/core.c b/src/core/core.c index 20bc813..fffb43d 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -78,6 +78,4 @@ Core* get_global_core() { return &g_core; } GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { return g_core.window; } -struct Renderer* Core_GetRenderer(Core* core) { - return core->renderer; -}
\ No newline at end of file +struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; }
\ No newline at end of file diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 32e7919..ceae260 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -45,9 +45,11 @@ Geometry Geo_CreatePlane(f32x2 extents) { push_triangle(indices, 2, 1, 0); push_triangle(indices, 3, 1, 2); - Geometry geo = { - .format = VERTEX_STATIC_3D, .vertices = vertices, .has_indices = true, .indices = indices - }; + Geometry geo = { .format = VERTEX_STATIC_3D, + .vertices = vertices, + .has_indices = true, + .index_count = indices->len, + .indices = indices }; // .colour = (rgba){ 0, 0, 0, 1 } }; return geo; @@ -126,6 +128,7 @@ Geometry Geo_CreateCuboid(f32x3 extents) { .format = VERTEX_STATIC_3D, .vertices = vertices, .has_indices = true, + .index_count = indices->len, .indices = indices, // FIXME: make darray methods that return stack allocated struct }; @@ -233,6 +236,7 @@ Geometry geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_west_li .format = VERTEX_STATIC_3D, .vertices = vertices, .has_indices = true, + .index_count = indices->len, .indices = indices, }; return geo; diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c index 09da50e..4a91080 100644 --- a/src/new_render/pbr.c +++ b/src/new_render/pbr.c @@ -94,7 +94,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te lights_data = { .pointLights = { // FIXME: add lights to our RenderScene structure. for now these are // hardcoded - (pbr_point_light){ .pos = vec3(10, 10, 10), .color = light_color }, + (pbr_point_light){ .pos = vec3(0.0, 2.0, 2.0), .color = light_color }, (pbr_point_light){ .pos = vec3(-10, 10, 10), .color = light_color }, (pbr_point_light){ .pos = vec3(10, -10, 10), .color = light_color }, (pbr_point_light){ .pos = vec3(-10, -10, 10), .color = light_color }, diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index d8c9405..cbdc577 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -48,11 +48,10 @@ typedef struct PBR_Textures { TextureHandle ao_map; } PBR_Textures; -// --- Internal - -typedef struct MaterialMap MaterialMap; +PUB Material PBRMaterialDefault(); +PUB ShaderDataLayout PBRMaterial_GetLayout(void* data); -Material PBRMaterialDefault(); +// --- Internal GPU_Renderpass* PBR_RPassCreate(); @@ -60,5 +59,3 @@ GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_tex, RenderEnt* entities, size_t entity_count); - -ShaderDataLayout PBRMaterial_GetLayout(void* data);
\ No newline at end of file diff --git a/src/new_render/render.c b/src/new_render/render.c index 235f1cb..77a3269 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -37,6 +37,7 @@ struct Renderer { GPU_Swapchain swapchain; GPU_Renderpass* default_renderpass; bool frame_aborted; + RenderMode render_mode; RenderScene scene; PBR_Storage* pbr; Shadow_Storage* shadows; @@ -54,6 +55,7 @@ Renderer* get_renderer() { return g_core.renderer; } bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window, GLFWwindow* optional_window) { INFO("Renderer init"); + ren->render_mode = RENDER_MODE_DEFAULT; ren->frame_arena = arena_create(malloc(FRAME_ARENA_SIZE), FRAME_ARENA_SIZE); @@ -293,6 +295,7 @@ TextureHandle Render_GetWhiteTexture() { return ren->white_1x1; } +/** @return an arena allocator that gets cleared at the beginning of every render frame */ arena* Render_GetFrameArena() { Renderer* ren = Core_GetRenderer(&g_core); return &ren->frame_arena; @@ -305,4 +308,9 @@ Mesh_pool* Render_GetMeshPool() { Material_pool* Render_GetMaterialPool() { Renderer* ren = Core_GetRenderer(&g_core); return &ren->material_pool; +} + +void Render_SetRenderMode(RenderMode mode) { + Renderer* ren = Core_GetRenderer(&g_core); + ren->render_mode = mode; }
\ No newline at end of file diff --git a/src/new_render/render.h b/src/new_render/render.h index ef11b5f..b7af7cb 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -84,4 +84,7 @@ Terrain_Storage* Render_GetTerrainStorage(); TextureHandle Render_GetWhiteTexture(); arena* Render_GetFrameArena(); Mesh_pool* Render_GetMeshPool(); -Material_pool* Render_GetMaterialPool();
\ No newline at end of file +Material_pool* Render_GetMaterialPool(); + +// --- Setters +void Render_SetRenderMode(RenderMode mode);
\ No newline at end of file diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index 2b7a77a..5fdca8a 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -17,6 +17,13 @@ CORE_DEFINE_HANDLE(MeshHandle); #define INVALID_MATERIAL_HANDLE ((MaterialHandle){ .raw = 9999992 }) #define INVALID_MESH_HANDLE ((MeshHandle){ .raw = 9999993 }) +typedef enum RenderMode { + RENDER_MODE_DEFAULT, + RENDER_MODE_WIREFRAME, + RENDER_MODE_WIREFRAME_ON_LIT, + RENDER_MODE_COUNT +} RenderMode; + typedef struct Geometry { VertexFormat format; Vertex_darray* vertices; diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 305ab36..7929a16 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -57,8 +57,7 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, } // All of these are no-ops in OpenGL -void GPU_Backend_Shutdown() { /* TODO */ -} +void GPU_Backend_Shutdown() { /* TODO */ } bool GPU_Device_Create(GPU_Device* out_device) { return true; } void GPU_Device_Destroy(GPU_Device* device) {} bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain) { return true; } diff --git a/src/resources/gltf.c b/src/resources/gltf.c index ef7569f..8b949ce 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -41,6 +41,8 @@ KITC_DECL_TYPED_ARRAY(face) bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 relative_path, Model *out_model, bool invert_textures_y); +size_t GLTF_LoadMaterials(cgltf_data *data, Str8 relative_path, Material_darray *out_materials); + ModelHandle ModelLoad_gltf(const char *path, bool invert_texture_y) { size_t arena_size = MB(1); arena scratch = arena_create(malloc(arena_size), arena_size); @@ -55,8 +57,6 @@ ModelHandle ModelLoad_gltf(const char *path, bool invert_texture_y) { ModelHandle handle; Model *model = Model_pool_alloc(&g_core.models, &handle); model->name = Str8_cstr_view(path); - model->meshes = Mesh_darray_new(1); - model->materials = Material_darray_new(1); bool success = model_load_gltf_str(file_string, path, relative_path.path, model, invert_texture_y); @@ -132,6 +132,10 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 rel Vec2_darray *tmp_uvs = Vec2_darray_new(1000); Vec4u_darray *tmp_joint_indices = Vec4u_darray_new(1000); Vec4_darray *tmp_weights = Vec4_darray_new(1000); + Material_darray *tmp_materials = Material_darray_new(1); + Mesh_darray *tmp_meshes = Mesh_darray_new(1); + u32_darray *tmp_material_indexes = u32_darray_new(1); + // FIXME // joint_darray *tmp_joints = joint_darray_new(256); // vertex_bone_data_darray *tmp_vertex_bone_data = vertex_bone_data_darray_new(1000); @@ -197,246 +201,182 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 rel // } // --- Materials - size_t num_materials = data->materials_count; - TRACE("Num materials %d", num_materials); - for (size_t m = 0; m < num_materials; m++) { - cgltf_material gltf_material = data->materials[m]; - cgltf_pbr_metallic_roughness pbr = gltf_material.pbr_metallic_roughness; - - Material our_material = PBRMaterialDefault(); - - TRACE("Has PBR metallic roughness "); - // we will use base color texture like blinn phong - cgltf_texture_view albedo_tex_view = pbr.base_color_texture; // albedo - if (albedo_tex_view.texture != NULL) { - char albedo_map_path[1024]; - snprintf(albedo_map_path, sizeof(albedo_map_path), "%s/%s", relative_path.buf, - albedo_tex_view.texture->image->uri); - our_material.albedo_map = TextureLoadFromFile(albedo_map_path); - } else { - WARN("GLTF model has no albedo map"); - } - - cgltf_texture_view metal_rough_tex_view = pbr.metallic_roughness_texture; - if (metal_rough_tex_view.texture != NULL) { - char metal_rough_map_path[1024]; - snprintf(metal_rough_map_path, sizeof(metal_rough_map_path), "%s/%s", relative_path.buf, - metal_rough_tex_view.texture->image->uri); - our_material.metallic_roughness_map = TextureLoadFromFile(metal_rough_map_path); - } else { - WARN("GLTF model has no metal/roughness map"); - } + size_t num_materials = GLTF_LoadMaterials(data, relative_path, tmp_materials); - cgltf_texture_view normal_tex_view = gltf_material.normal_texture; - if (normal_tex_view.texture != NULL) { - char normal_map_path[1024]; - snprintf(normal_map_path, sizeof(normal_map_path), "%s/%s", relative_path.buf, - normal_tex_view.texture->image->uri); - our_material.normal_map = TextureLoadFromFile(normal_map_path); - } else { - WARN("GLTF model has no normal map"); - } + // --- Meshes + size_t num_meshes = data->meshes_count; + TRACE("Num meshes %d", num_meshes); + for (size_t m = 0; m < num_meshes; m++) { + printf("Primitive count %d\n", data->meshes[m].primitives_count); + for (size_t prim_i = 0; prim_i < data->meshes[m].primitives_count; prim_i++) { + DEBUG("Primitive %d\n", prim_i); - // TextureHandle albedo_map = TextureLoadFromFile(albedo_map_path); - // TextureHandle metal_roughness_map = TextureLoadFromFile(metal_rough_map_path); - // TextureHandle normal_map = TextureLoadFromFile(normal_map_path); + cgltf_primitive primitive = data->meshes[m].primitives[prim_i]; + DEBUG("Found %d attributes", primitive.attributes_count); - // Material our_material = { - // .kind = MAT_PBR, - // // .metal_roughness_combined = true, - // .albedo_map = albedo_map, - // .metallic_roughness_map = metal_roughness_map, - // .normal_map= normal_map, - // .ambient_occlusion_map = INVALID_TEX_HANDLE, + for (cgltf_size a = 0; a < primitive.attributes_count; a++) { + cgltf_attribute attribute = primitive.attributes[a]; + if (attribute.type == cgltf_attribute_type_position) { + cgltf_accessor *accessor = attribute.data; + load_position_components(tmp_positions, accessor); + } else if (attribute.type == cgltf_attribute_type_normal) { + cgltf_accessor *accessor = attribute.data; + load_normal_components(tmp_normals, accessor); + } else if (attribute.type == cgltf_attribute_type_texcoord) { + cgltf_accessor *accessor = attribute.data; + load_texcoord_components(tmp_uvs, accessor); + } else if (attribute.type == cgltf_attribute_type_joints) { + // FIXME: joints + // TRACE("Load joint indices from accessor"); + // cgltf_accessor *accessor = attribute.data; + // assert(accessor->component_type == cgltf_component_type_r_16u); + // assert(accessor->type == cgltf_type_vec4); + // vec4u joint_indices; + // vec4 joints_as_floats; + // for (cgltf_size v = 0; v < accessor->count; ++v) { + // cgltf_accessor_read_float(accessor, v, &joints_as_floats.x, 4); + // joint_indices.x = (u32)joints_as_floats.x; + // joint_indices.y = (u32)joints_as_floats.y; + // joint_indices.z = (u32)joints_as_floats.z; + // joint_indices.w = (u32)joints_as_floats.w; + // printf("Joints affecting vertex %d : %d %d %d %d\n", v, joint_indices.x, + // joint_indices.y, + // joint_indices.z, joint_indices.w); + // vec4u_darray_push(tmp_joint_indices, joint_indices); + // } + + } else if (attribute.type == cgltf_attribute_type_weights) { + // FIXME: weights + // TRACE("Load joint weights from accessor"); + // cgltf_accessor *accessor = attribute.data; + // assert(accessor->component_type == cgltf_component_type_r_32f); + // assert(accessor->type == cgltf_type_vec4); + + // for (cgltf_size v = 0; v < accessor->count; ++v) { + // vec4 weights; + // cgltf_accessor_read_float(accessor, v, &weights.x, 4); + // printf("Weights affecting vertex %d : %f %f %f %f\n", v, weights.x, weights.y, + // weights.z, + // weights.w); + // vec4_darray_push(tmp_weights, weights); + // } + } else { + WARN("Unhandled cgltf_attribute_type: %s. skipping..", attribute.name); + } + } + // mesh.vertex_bone_data = vertex_bone_data_darray_new(1); + i32 mat_idx = -1; + if (primitive.material != NULL) { + DEBUG("Primitive Material %s", primitive.material->name); + // FIXME! + for (u32 i = 0; i < Material_darray_len(tmp_materials); i++) { + printf("%s vs %s \n", primitive.material->name, tmp_materials->data[i].name); + if (strcmp(primitive.material->name, tmp_materials->data[i].name) == 0) { + INFO("Found material"); + mat_idx = i; + u32_darray_push(tmp_material_indexes, mat_idx); + break; + } + } + } - // }; + TRACE("Vertex data has been loaded"); + + // // FIXME + // // if (is_skinned) { + // // mesh.is_skinned = true; + // // // mesh.vertex_bone_data = vertex_bone_data_darray_new(tmp_joint_indices->len); + // // mesh.bones = joint_darray_new(tmp_joints->len); + // // for (int i = 0; i < tmp_joint_indices->len; i++) { + // // vertex_bone_data data; + // // data.joints = tmp_joint_indices->data[i]; + // // data.weights = tmp_weights->data[i]; + // // vertex_bone_data_darray_push(tmp_vertex_bone_data, + // // data); // Push the temp data that aligns with raw + // vertices + // // } + // // for (int i = 0; i < tmp_joints->len; i++) { + // // joint data = tmp_joints->data[i]; + // // joint_darray_push(mesh.bones, data); + // // } + // // } + + bool has_indices = false; + Vertex_darray *geo_vertices = Vertex_darray_new(3); + u32_darray *geo_indices = u32_darray_new(0); + + // Store vertices + printf("Positions %d Normals %d UVs %d\n", tmp_positions->len, tmp_normals->len, + tmp_uvs->len); + assert(tmp_positions->len == tmp_normals->len); + assert(tmp_normals->len == tmp_uvs->len); + for (u32 v_i = 0; v_i < tmp_positions->len; v_i++) { + Vertex v = { .static_3d = { + .position = tmp_positions->data[v_i], + .normal = tmp_normals->data[v_i], + .tex_coords = tmp_uvs->data[v_i], + } }; + Vertex_darray_push(geo_vertices, v); + } - // our_material.name = malloc(strlen(gltf_material.name) + 1); - u32 string_length = strlen(gltf_material.name) + 1; - assert(string_length < 64); - strcpy(our_material.name, gltf_material.name); + // Store indices + cgltf_accessor *indices = primitive.indices; + if (primitive.indices > 0) { + WARN("indices! %d", indices->count); + has_indices = true; - Material_darray_push(out_model->materials, our_material); - } + // store indices + for (cgltf_size i = 0; i < indices->count; ++i) { + cgltf_uint ei; + cgltf_accessor_read_uint(indices, i, &ei, 1); + u32_darray_push(geo_indices, ei); + } - // --- Meshes - size_t num_meshes = data->meshes_count; - TRACE("Num meshes %d", num_meshes); - for (size_t m = 0; m < num_meshes; m++) { - cgltf_primitive primitive = data->meshes[m].primitives[0]; - DEBUG("Found %d attributes", primitive.attributes_count); - - for (cgltf_size a = 0; a < data->meshes[m].primitives[0].attributes_count; a++) { - cgltf_attribute attribute = data->meshes[m].primitives[0].attributes[a]; - if (attribute.type == cgltf_attribute_type_position) { - cgltf_accessor *accessor = attribute.data; - load_position_components(tmp_positions, accessor); - } else if (attribute.type == cgltf_attribute_type_normal) { - cgltf_accessor *accessor = attribute.data; - load_normal_components(tmp_normals, accessor); - } else if (attribute.type == cgltf_attribute_type_texcoord) { - cgltf_accessor *accessor = attribute.data; - load_texcoord_components(tmp_uvs, accessor); - } else if (attribute.type == cgltf_attribute_type_joints) { - // FIXME: joints - // TRACE("Load joint indices from accessor"); - // cgltf_accessor *accessor = attribute.data; - // assert(accessor->component_type == cgltf_component_type_r_16u); - // assert(accessor->type == cgltf_type_vec4); - // vec4u joint_indices; - // vec4 joints_as_floats; - // for (cgltf_size v = 0; v < accessor->count; ++v) { - // cgltf_accessor_read_float(accessor, v, &joints_as_floats.x, 4); - // joint_indices.x = (u32)joints_as_floats.x; - // joint_indices.y = (u32)joints_as_floats.y; - // joint_indices.z = (u32)joints_as_floats.z; - // joint_indices.w = (u32)joints_as_floats.w; - // printf("Joints affecting vertex %d : %d %d %d %d\n", v, joint_indices.x, - // joint_indices.y, - // joint_indices.z, joint_indices.w); - // vec4u_darray_push(tmp_joint_indices, joint_indices); + // fetch and store vertices for each index + // for (cgltf_size i = 0; i < indices->count; ++i) { + // Vertex vert; + // cgltf_uint index = mesh.indices[i]; + // vert.position = tmp_positions->data[index]; + // vert.normal = tmp_normals->data[index]; + // vert.uv = tmp_uvs->data[index]; + // vertex_darray_push(mesh.vertices, vert); + + // if (is_skinned) { + // vertex_bone_data vbd = tmp_vertex_bone_data->data[index]; // create a copy + // vertex_bone_data_darray_push(mesh.vertex_bone_data, vbd); // } - - } else if (attribute.type == cgltf_attribute_type_weights) { - // FIXME: weights - // TRACE("Load joint weights from accessor"); - // cgltf_accessor *accessor = attribute.data; - // assert(accessor->component_type == cgltf_component_type_r_32f); - // assert(accessor->type == cgltf_type_vec4); - - // for (cgltf_size v = 0; v < accessor->count; ++v) { - // vec4 weights; - // cgltf_accessor_read_float(accessor, v, &weights.x, 4); - // printf("Weights affecting vertex %d : %f %f %f %f\n", v, weights.x, weights.y, - // weights.z, - // weights.w); - // vec4_darray_push(tmp_weights, weights); + // for each vertex do the bone data + // } + // } else { + // has_indices = false; + // return false; // TODO: handle this // } - } else { - WARN("Unhandled cgltf_attribute_type: %s. skipping..", attribute.name); - } - } - // mesh.vertex_bone_data = vertex_bone_data_darray_new(1); - i32 mat_idx = -1; - if (primitive.material != NULL) { - DEBUG("Primitive Material %s", primitive.material->name); - // FIXME! - // for (u32 i = 0; i < Material_darray_len(out_model->materials); i++) { - // printf("%s vs %s \n", primitive.material->name, out_model->materials->data[i].name); - // if (strcmp(primitive.material->name, out_model->materials->data[i].name) == 0) { - // INFO("Found material"); - // mat_idx = i; - // // mesh.material_index = i; - // break; - // } - // } - } - - TRACE("Vertex data has been loaded"); - - // // FIXME - // // if (is_skinned) { - // // mesh.is_skinned = true; - // // // mesh.vertex_bone_data = vertex_bone_data_darray_new(tmp_joint_indices->len); - // // mesh.bones = joint_darray_new(tmp_joints->len); - // // for (int i = 0; i < tmp_joint_indices->len; i++) { - // // vertex_bone_data data; - // // data.joints = tmp_joint_indices->data[i]; - // // data.weights = tmp_weights->data[i]; - // // vertex_bone_data_darray_push(tmp_vertex_bone_data, - // // data); // Push the temp data that aligns with raw - // vertices - // // } - // // for (int i = 0; i < tmp_joints->len; i++) { - // // joint data = tmp_joints->data[i]; - // // joint_darray_push(mesh.bones, data); - // // } - // // } - - bool has_indices = false; - Vertex_darray *geo_vertices = Vertex_darray_new(3); - u32_darray *geo_indices = u32_darray_new(0); - - // Store vertices - printf("Positions %d Normals %d UVs %d\n", tmp_positions->len, tmp_normals->len, tmp_uvs->len); - assert(tmp_positions->len == tmp_normals->len); - assert(tmp_normals->len == tmp_uvs->len); - for (u32 v_i = 0; v_i < tmp_positions->len; v_i++) { - Vertex v = { .static_3d = { - .position = tmp_positions->data[v_i], - .normal = tmp_normals->data[v_i], - .tex_coords = tmp_uvs->data[v_i], - } }; - Vertex_darray_push(geo_vertices, v); - } - // Store indices - cgltf_accessor *indices = primitive.indices; - if (primitive.indices > 0) { - WARN("indices! %d", indices->count); - has_indices = true; - - // store indices - for (cgltf_size i = 0; i < indices->count; ++i) { - cgltf_uint ei; - cgltf_accessor_read_uint(indices, i, &ei, 1); - u32_darray_push(geo_indices, ei); + Geometry *geometry = malloc(sizeof(Geometry)); + geometry->format = VERTEX_STATIC_3D; + geometry->has_indices = true; + geometry->vertices = geo_vertices; + geometry->indices = geo_indices; + geometry->index_count = geo_indices->len; + + Mesh m = Mesh_Create(geometry, false); + Mesh_darray_push(tmp_meshes, m); + + Vec3_darray_clear(tmp_positions); + Vec3_darray_clear(tmp_normals); + Vec2_darray_clear(tmp_uvs); + Vec4u_darray_clear(tmp_joint_indices); + Vec4_darray_clear(tmp_weights); } - - // fetch and store vertices for each index - // for (cgltf_size i = 0; i < indices->count; ++i) { - // Vertex vert; - // cgltf_uint index = mesh.indices[i]; - // vert.position = tmp_positions->data[index]; - // vert.normal = tmp_normals->data[index]; - // vert.uv = tmp_uvs->data[index]; - // vertex_darray_push(mesh.vertices, vert); - - // if (is_skinned) { - // vertex_bone_data vbd = tmp_vertex_bone_data->data[index]; // create a copy - // vertex_bone_data_darray_push(mesh.vertex_bone_data, vbd); - // } - // for each vertex do the bone data - // } - // } else { - // has_indices = false; - // return false; // TODO: handle this - // } - - Geometry *geometry = malloc(sizeof(Geometry)); - geometry->format = VERTEX_STATIC_3D; - geometry->has_indices = true; - geometry->vertices = geo_vertices; - geometry->indices = geo_indices; - // geometry->format = VERTEX_STATIC_3D; - // geometry->colour = (rgba){ 1, 1, 1, 1 }; - // geometry->vertices = geo_vertices; - // geometry->indices = geo_indices; - // geometry->has_indices = has_indices; - - // mesh m = mesh_create(geometry, true); - // m.material_index = (u32_opt){ .has_value = mat_idx == 9999, .value = mat_idx }; - - Mesh m = Mesh_Create(geometry, false); - // m.material_index = mat_idx; FIXME - Mesh_darray_push(out_model->meshes, m); } - // // clear data for each mesh - // vec3_darray_clear(tmp_positions); - // vec3_darray_clear(tmp_normals); - // vec2_darray_free(tmp_uvs); - // vec4u_darray_clear(tmp_joint_indices); - // vec4_darray_clear(tmp_weights); - // joint_darray_clear(tmp_joints); - // } - // for (int i = 0; i < out_model->meshes->len; i++) { // u32 mat_idx = out_model->meshes->data[i].material_index; // printf("Mesh %d Mat index %d Mat name %s\n", i, mat_idx, // out_model->materials->data[mat_idx].name); // } + // TODO: GLTF_LoadAnimations() // // Animations // TRACE("Num animations %d", data->animations_count); // size_t num_animations = data->animations_count; @@ -557,9 +497,99 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 rel // } } + num_meshes = tmp_meshes->len; + + // we now have an array of meshes, materials, and the material which each mesh should get + out_model->meshes = malloc(num_meshes * sizeof(MeshHandle)); + out_model->mesh_count = num_meshes; + out_model->materials = malloc(num_materials * sizeof(MaterialHandle)); + out_model->material_count = num_materials; + + MaterialHandle *mat_handles = calloc(num_materials, sizeof(MaterialHandle)); + for (u32 mat_i = 0; mat_i < num_materials; mat_i++) { + mat_handles[mat_i] = + Material_pool_insert(Render_GetMaterialPool(), &tmp_materials->data[mat_i]); + } + memcpy(out_model->materials, mat_handles, num_materials * sizeof(MaterialHandle)); + + for (u32 mesh_i = 0; mesh_i < num_meshes; mesh_i++) { + u32 mat_idx = tmp_material_indexes->data[mesh_i]; + tmp_meshes->data[mesh_i].material = mat_handles[mat_idx]; + MeshHandle mesh = Mesh_pool_insert(Render_GetMeshPool(), &tmp_meshes->data[mesh_i]); + out_model->meshes[mesh_i] = mesh; + } + + free(mat_handles); + return true; } +const char *bool_yes_no(bool pred) { return pred ? "Yes" : "No"; } + +// Loads all materials +size_t GLTF_LoadMaterials(cgltf_data *data, Str8 relative_path, Material_darray *out_materials) { + size_t num_materials = data->materials_count; + TRACE("Num materials %d", num_materials); + for (size_t m = 0; m < num_materials; m++) { + cgltf_material gltf_material = data->materials[m]; + TRACE("Loading material '%s'", gltf_material.name); + cgltf_pbr_metallic_roughness pbr = gltf_material.pbr_metallic_roughness; + + Material our_material = PBRMaterialDefault(); // focusing on PBR materials for now + + our_material.base_colour = + vec3(pbr.base_color_factor[0], pbr.base_color_factor[1], pbr.base_color_factor[2]); + our_material.metallic = pbr.metallic_factor; + our_material.roughness = pbr.roughness_factor; + + // -- albedo / base colour + cgltf_texture_view albedo_tex_view = pbr.base_color_texture; + bool has_albedo_texture = albedo_tex_view.texture != NULL; + TRACE("Has PBR base colour texture? %s", bool_yes_no(has_albedo_texture)); + printf("Base colour factor: %f %f %f\n", pbr.base_color_factor[0], pbr.base_color_factor[1], + pbr.base_color_factor[2]); + if (has_albedo_texture) { + char albedo_map_path[1024]; + snprintf(albedo_map_path, sizeof(albedo_map_path), "%s/%s", relative_path.buf, + albedo_tex_view.texture->image->uri); + our_material.albedo_map = TextureLoadFromFile(albedo_map_path); + } else { + our_material.albedo_map = Render_GetWhiteTexture(); + WARN("GLTF model has no albedo map"); + } + + // -- metallic + cgltf_texture_view metal_rough_tex_view = pbr.metallic_roughness_texture; + // bool has_metal_ + if (metal_rough_tex_view.texture != NULL) { + char metal_rough_map_path[1024]; + snprintf(metal_rough_map_path, sizeof(metal_rough_map_path), "%s/%s", relative_path.buf, + metal_rough_tex_view.texture->image->uri); + our_material.metallic_roughness_map = TextureLoadFromFile(metal_rough_map_path); + } else { + WARN("GLTF model has no metal/roughness map"); + } + + cgltf_texture_view normal_tex_view = gltf_material.normal_texture; + if (normal_tex_view.texture != NULL) { + char normal_map_path[1024]; + snprintf(normal_map_path, sizeof(normal_map_path), "%s/%s", relative_path.buf, + normal_tex_view.texture->image->uri); + our_material.normal_map = TextureLoadFromFile(normal_map_path); + } else { + WARN("GLTF model has no normal map"); + } + + u32 string_length = strlen(gltf_material.name) + 1; + assert(string_length < 64); + strcpy(our_material.name, gltf_material.name); + + Material_darray_push(out_materials, our_material); + } + + return out_materials->len; +} + /* bool model_load_gltf(const char *path, model *out_model) { TRACE("Load GLTF %s", path); diff --git a/src/systems/input.h b/src/systems/input.h index bf80a84..2665a11 100644 --- a/src/systems/input.h +++ b/src/systems/input.h @@ -32,22 +32,22 @@ typedef struct Input_State { } Input_State; /** @brief `key` is currently being held down */ -bool key_is_pressed(keycode key); +PUB bool key_is_pressed(keycode key); /** @brief `key` was just pressed */ -bool key_just_pressed(keycode key); +PUB bool key_just_pressed(keycode key); /** @brief `key` was just released */ -bool key_just_released(keycode key); +PUB bool key_just_released(keycode key); // TODO: right btn as well -bool MouseBtn_Held(MouseBtn btn); +PUB bool MouseBtn_Held(MouseBtn btn); // --- Lifecycle -bool Input_Init(Input_State *input, struct GLFWwindow *window); -void Input_Shutdown(Input_State *input); +PUB bool Input_Init(Input_State *input, struct GLFWwindow *window); +PUB void Input_Shutdown(Input_State *input); -void Input_Update(Input_State *state); // must be run once per main loop +PUB void Input_Update(Input_State *state); // must be run once per main loop PUB mouse_state Input_GetMouseState();
\ No newline at end of file diff --git a/src/systems/terrain.h b/src/systems/terrain.h index 4399e6b..5a96132 100644 --- a/src/systems/terrain.h +++ b/src/systems/terrain.h @@ -13,8 +13,6 @@ Future: #include "defines.h" #include "maths_types.h" -#include "mem.h" -#include "ral.h" #include "ral_types.h" #include "render.h" #include "str.h" @@ -57,16 +55,12 @@ PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters * PUB bool Terrain_IsActive(); // checks whether we have a loaded heightmap and it's being rendered -// --- Internal - -// TODO: void terrain_system_render_hmap(renderer* rend, terrain_state* state); - /** @brief Get the height (the Y component) for a vertex at a particular coordinate in the heightmap */ -f32 Heightmap_HeightXZ(const Heightmap* hmap, u32 x, u32 z); +PUB f32 Heightmap_HeightXZ(const Heightmap* hmap, u32 x, u32 z); /** @brief Calculate the normal vector of a vertex at a particular coordinate in the heightmap */ -Vec3 Heightmap_NormalXZ(const Heightmap* hmap, f32 x, f32 z); +PUB Vec3 Heightmap_NormalXZ(const Heightmap* hmap, f32 x, f32 z); // /** @brief Generate the `geometry_data` for a heightmap ready to be uploaded to the GPU */ // Geometry geo_heightmap(arena* a, Heightmap heightmap); |