summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-31 10:19:38 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-31 10:19:38 +1000
commit0a60692230841cbcbbf67acba55d2dbb4730b6cb (patch)
tree1f53fb5144310e6972aa3448c3b68c57e922cb70
parent547268b5a9cacc514445a59cc482897fd2f201ee (diff)
add empty grid system
-rw-r--r--assets/shaders/grid.frag7
-rw-r--r--assets/shaders/grid.vert11
-rw-r--r--bindgen/rust/src/ral.rs50
-rw-r--r--examples/game_demo/game_demo.c12
-rw-r--r--src/core/core.c4
-rw-r--r--src/new_render/render.c6
-rw-r--r--src/systems/grid.c59
-rw-r--r--src/systems/grid.h20
8 files changed, 158 insertions, 11 deletions
diff --git a/assets/shaders/grid.frag b/assets/shaders/grid.frag
new file mode 100644
index 0000000..5bce13b
--- /dev/null
+++ b/assets/shaders/grid.frag
@@ -0,0 +1,7 @@
+#version 410 core
+
+out vec4 FragColor;
+
+void main() {
+ FragColor = vec4(1.0);
+} \ No newline at end of file
diff --git a/assets/shaders/grid.vert b/assets/shaders/grid.vert
new file mode 100644
index 0000000..a98eabe
--- /dev/null
+++ b/assets/shaders/grid.vert
@@ -0,0 +1,11 @@
+#version 410 core
+
+uniform Camera {
+ mat4 view;
+ mat4 proj;
+ vec4 viewPos;
+} cam;
+
+void main() {
+ gl_Position = vec4(1.0);
+} \ No newline at end of file
diff --git a/bindgen/rust/src/ral.rs b/bindgen/rust/src/ral.rs
index 775335a..2941275 100644
--- a/bindgen/rust/src/ral.rs
+++ b/bindgen/rust/src/ral.rs
@@ -1,15 +1,20 @@
//! Wrapper around the RAL code in celeritas-core
+use std::{os::raw::c_void, ptr};
+
use celeritas_sys::{
- BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender,
- GPU_GetDefaultEncoder,
+ BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender, GPU_GetDefaultEncoder, GPU_GetDefaultRenderpass, GPU_GraphicsPipeline_Create, GraphicsPipelineDesc, ShaderData
};
+/// Holds a pointer to the raw `GPU_CmdEncoder`
pub struct FrameRenderEncoder(*mut GPU_CmdEncoder);
-/// Holds a pointer into the raw `GPU_Renderpass`
+/// Holds a pointer to the raw `GPU_Renderpass`
pub struct RenderPass(*mut celeritas_sys::GPU_Renderpass);
+/// Holds a pointer to the raw `GPU_Pipeline`
+pub struct Pipeline(*mut celeritas_sys::GPU_Pipeline);
+
impl FrameRenderEncoder {
pub fn new(renderpass: &RenderPass) -> Self {
let enc = unsafe {
@@ -42,6 +47,45 @@ impl FrameRenderEncoder {
}
}
+pub struct PipelineBuilder {
+ renderpass: Option<RenderPass>,
+ data_layouts: Vec<()>,
+
+}
+impl PipelineBuilder {
+ // pub fn add_
+
+ pub fn build(self) -> Pipeline {
+ let shad = ShaderData {
+ get_layout: todo!(),
+ data: ptr::null_mut()
+ };
+ let desc = GraphicsPipelineDesc {
+ debug_name: todo!(),
+ vertex_desc: todo!(),
+ vs: todo!(),
+ fs: todo!(),
+ data_layouts: todo!(),
+ data_layouts_count: todo!(),
+ wireframe: todo!(),
+ depth_test: todo!(),
+ };
+ let p = unsafe { GPU_GraphicsPipeline_Create(
+ todo!(),
+ self.renderpass.map(|r| r.0).unwrap_or(GPU_GetDefaultRenderpass())
+ ) };
+ Pipeline(p)
+ }
+}
+// impl Default for PipelineBuilder {
+// fn default() -> Self {
+// Self {
+// renderpass: Default::default(),
+
+// }
+// }
+// }
+
// --- types
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index c510ee0..2362a2e 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -74,10 +74,11 @@ int main() {
crate_mat.metallic = 0.0;
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/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf", false);
-
+ ModelHandle cube_handle =
+ ModelLoad_gltf("assets/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf", false);
+
RenderEnt_darray* render_entities = RenderEnt_darray_new(1);
-
+
// --- Transforms
// TransformHierarchy* scene_tree = TransformHierarchy_Create();
// TODO: parent camera to model - to start with I can just manually update it every frame
@@ -95,9 +96,10 @@ int main() {
SetCamera(cam);
// BEGIN Draw calls
- RenderEnt_darray_clear(render_entities); // we re-extract every frame
+ RenderEnt_darray_clear(render_entities); // we re-extract every frame
Quat rot = quat_from_axis_angle(VEC3_X, -HALF_PI, true);
- ModelExtractRenderEnts(render_entities, cube_handle, mat4_rotation(rot), REND_ENT_CASTS_SHADOWS);
+ ModelExtractRenderEnts(render_entities, cube_handle, mat4_rotation(rot),
+ REND_ENT_CASTS_SHADOWS);
// Shadow_Run(entities, entity_count);
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