diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core.c | 4 | ||||
-rw-r--r-- | src/new_render/render.c | 6 | ||||
-rw-r--r-- | src/systems/grid.c | 59 | ||||
-rw-r--r-- | src/systems/grid.h | 20 |
4 files changed, 86 insertions, 3 deletions
diff --git a/src/core/core.c b/src/core/core.c index b18b807..bb30ced 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -80,6 +80,4 @@ GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { return g_core.window; } struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; } -Model* Model_Get(ModelHandle h) { - return Model_pool_get(&g_core.models, h); -}
\ No newline at end of file +Model* Model_Get(ModelHandle h) { return Model_pool_get(&g_core.models, h); }
\ No newline at end of file diff --git a/src/new_render/render.c b/src/new_render/render.c index 9314871..54ea32a 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -7,6 +7,7 @@ #include <glfw3.h> #include "camera.h" #include "core.h" +#include "grid.h" #include "log.h" #include "maths.h" #include "maths_types.h" @@ -43,6 +44,7 @@ struct Renderer { PBR_Storage* pbr; Shadow_Storage* shadows; Terrain_Storage* terrain; + Grid_Storage* grid; // Text_Storage* text; ResourcePools* resource_pools; Mesh_pool mesh_pool; @@ -139,8 +141,12 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window ren->terrain = malloc(sizeof(Terrain_Storage)); Terrain_Init(ren->terrain); + ren->grid = calloc(1, sizeof(Grid_Storage)); + Grid_Init(ren->grid); + // load default textures ren->white_1x1 = TextureLoadFromFile("assets/textures/white1x1.png"); + // TODO: black_1x1 return true; } diff --git a/src/systems/grid.c b/src/systems/grid.c new file mode 100644 index 0000000..20e3657 --- /dev/null +++ b/src/systems/grid.c @@ -0,0 +1,59 @@ +#include "grid.h" +#include "file.h" +#include "log.h" +#include "maths_types.h" +#include "primitives.h" +#include "ral_common.h" +#include "ral_impl.h" +#include "ral_types.h" +#include "render.h" +#include "render_types.h" +#include "shader_layouts.h" + +void Grid_Init(Grid_Storage* storage) { + INFO("Infinite Grid initialisation"); + Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0)); + Mesh plane_mesh = Mesh_Create(&plane_geo, true); + storage->plane_vertices = plane_mesh.vertex_buffer; + storage->plane_indices = plane_mesh.index_buffer; + + GPU_RenderpassDesc rpass_desc = { + .default_framebuffer = true, + }; + storage->renderpass = GPU_Renderpass_Create(rpass_desc); + + arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); + + Str8 vert_path = str8("assets/shaders/grid.vert"); + Str8 frag_path = str8("assets/shaders/grid.frag"); + str8_opt vertex_shader = str8_from_file(&scratch, vert_path); + str8_opt fragment_shader = str8_from_file(&scratch, frag_path); + if (!vertex_shader.has_value || !fragment_shader.has_value) { + ERROR_EXIT("Failed to load shaders from disk") + } + + ShaderData camera_data = { .get_layout = &Binding_Camera_GetLayout }; + + GraphicsPipelineDesc pipeline_desc = { + .debug_name = "Infinite grid pipeline", + .vertex_desc = static_3d_vertex_description(), + .data_layouts = { camera_data }, + .data_layouts_count = 1, + .vs = { + .debug_name = "Grid vertex shader", + .filepath = vert_path, + .code = vertex_shader.contents, + }, + .fs = { + .debug_name = "Grid fragment shader", + .filepath = frag_path, + .code = fragment_shader.contents, + }, + .wireframe = false, + }; + storage->pipeline = GPU_GraphicsPipeline_Create(pipeline_desc, storage->renderpass); +} + +void Grid_Draw(Grid_Storage* storage) { + +}
\ No newline at end of file diff --git a/src/systems/grid.h b/src/systems/grid.h new file mode 100644 index 0000000..7d983dc --- /dev/null +++ b/src/systems/grid.h @@ -0,0 +1,20 @@ +#pragma once + +#include "ral_impl.h" +#include "ral_types.h" + +typedef struct Grid_Storage { + GPU_Renderpass* renderpass; + GPU_Pipeline* pipeline; + BufferHandle plane_vertices; + BufferHandle plane_indices; +} Grid_Storage; + +// --- Public API +void Grid_Init(Grid_Storage* storage); +// void Grid_Shutdown(Grid_Storage* storage); +void Grid_Draw(Grid_Storage* storage); + +// --- Internal +// typedef struct GridUniforms {} GridUniforms; +// ShaderDataLayout GridUniforms_GetLayout(void* data);
\ No newline at end of file |