@@ -4,45 +4,10 @@ import std;
44#include < bgfx/bgfx.h>
55#include < bx/math.h>
66
7- import rendering.rhi;
8-
9- // Vertex struct
10- // Will later be moved to a seperate file & rewritten
11- struct Vertex
12- {
13- float x, y, z; // Position
14- uint32_t agbr; // Color, stored as AGBR
15- };
16-
17- // Shader binary loadin' logic
18- // Will later be moved to a seperate file & rewritten
19- std::vector<uint8_t > loadShaderBinary (const std::string& path);
20-
21- std::vector<uint8_t > loadShaderBinary (const std::string& path) {
22- // Open at the end (ate) to get size and in binary mode
23- std::ifstream file (path, std::ios::binary | std::ios::ate);
24-
25- if (!file.is_open ()) {
26- std::println (" Error: Could not find shader file at: {}" , path);
27- // Return an empty vector
28- return {};
29- }
7+ import core.filesystem;
308
31- std::streamsize size = file.tellg ();
32- if (size <= 0 ) {
33- std::println (" Error: Shader file is empty: {}" , path);
34- return {};
35- }
36-
37- file.seekg (0 , std::ios::beg);
38-
39- std::vector<uint8_t > buffer (static_cast <size_t >(size));
40- if (file.read (reinterpret_cast <char *>(buffer.data ()), size)) {
41- return buffer;
42- }
43-
44- return {};
45- }
9+ import rendering.rhi;
10+ import rendering.rhi.vertex;
4611
4712int main (int argc, char * argv[])
4813{
@@ -95,7 +60,7 @@ int main(int argc, char* argv[])
9560
9661 // Geometry data for a triangle to test rendering
9762 // It includes both positions & colors
98- Vertex triangle[] = {
63+ draco::rhi::PosColorVertex triangle[] = {
9964 { 0 .0f , 0 .5f , 0 .0f , 0xff0000ff },
10065 { 0 .5f , -0 .5f , 0 .0f , 0xff00ff00 },
10166 { -0 .5f , -0 .5f , 0 .0f , 0xffff0000 }
@@ -104,8 +69,8 @@ int main(int argc, char* argv[])
10469 auto vbh = draco::rhi::create_vertex_buffer (triangle, sizeof (triangle));
10570
10671 // Load the vertex & fragment shaders
107- auto vs_data = loadShaderBinary (" vs_triangle.bin" );
108- auto fs_data = loadShaderBinary (" fs_triangle.bin" );
72+ auto vs_data = draco::filesystem::load_binary (" vs_triangle.bin" );
73+ auto fs_data = draco::filesystem::load_binary (" fs_triangle.bin" );
10974
11075 // If the path is empty, return an error
11176 if (vs_data.empty () || fs_data.empty ()) {
0 commit comments