summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/celeritas.h8
-rw-r--r--src/core.c6
-rw-r--r--src/core.h4
-rw-r--r--src/renderer/render.c76
-rw-r--r--src/renderer/render_types.h2
-rw-r--r--src/systems/input.c1
6 files changed, 81 insertions, 16 deletions
diff --git a/include/celeritas.h b/include/celeritas.h
index 425436c..9ba741b 100644
--- a/include/celeritas.h
+++ b/include/celeritas.h
@@ -33,9 +33,9 @@ void core_bringup();
void core_shutdown();
bool should_window_close();
-void render_frame_begin();
-void render_frame_draw();
-void render_frame_end();
+void frame_begin();
+void frame_draw();
+void frame_end();
// Assets
model_handle model_load(const char* filepath);
@@ -47,6 +47,8 @@ typedef struct render_entity {
transform3d transform;
} render_entity;
+void render_frame_begin();
+
// Scene
typedef struct directional_light {} directional_light;
typedef struct point_light {} point_light;
diff --git a/src/core.c b/src/core.c
index 17424b3..ffd72a5 100644
--- a/src/core.c
+++ b/src/core.c
@@ -58,7 +58,7 @@ void core_bringup() {
#include <glfw3.h>
-bool should_window_close(core* core) { glfwWindowShouldClose(core->renderer.window); }
+/* bool should_window_close(core* core) { glfwWindowShouldClose(core->renderer.window); } */
void core_input_update() { input_update(&g_core.input); }
void core_frame_begin(core* core) { render_frame_begin(&core->renderer); }
void core_frame_end(core* core) { render_frame_end(&core->renderer); }
@@ -72,3 +72,7 @@ void core_shutdown() {
bool should_exit() {
return key_just_released(KEYCODE_ESCAPE) || glfwWindowShouldClose(g_core.renderer.window);
}
+
+void frame_begin() { render_frame_begin(&g_core.renderer); }
+void frame_draw() {}
+void frame_end() { render_frame_end(&g_core.renderer); }
diff --git a/src/core.h b/src/core.h
index ec8cde9..db711d0 100644
--- a/src/core.h
+++ b/src/core.h
@@ -31,4 +31,8 @@ void core_bringup();
void core_shutdown();
bool should_exit();
+void frame_begin();
+void frame_draw();
+void frame_end();
+
void core_input_update();
diff --git a/src/renderer/render.c b/src/renderer/render.c
index f73578e..10589e5 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -1,6 +1,7 @@
#include "render.h"
#include <glfw3.h>
#include "camera.h"
+#include "file.h"
#include "log.h"
#include "ral.h"
@@ -35,20 +36,15 @@ bool renderer_init(renderer* ren) {
glfwMakeContextCurrent(ren->window);
- DEBUG("Start backend init");
+ DEBUG("Start gpu backend init");
- gpu_backend_init("Celeritas Engine - Vulkan", window);
+ if (!gpu_backend_init("Celeritas Engine - Vulkan", window)) {
+ FATAL("Couldnt load graphics api backend");
+ return false;
+ }
gpu_device_create(&ren->device); // TODO: handle errors
gpu_swapchain_create(&ren->swapchain);
- // DEBUG("init graphics api backend");
- // if (!gfx_backend_init(ren)) {
- // FATAL("Couldnt load graphics api backend");
- // return false;
- // }
-
- default_pipelines_init(ren);
-
// ren->blinn_phong =
// shader_create_separate("assets/shaders/blinn_phong.vert",
// "assets/shaders/blinn_phong.frag");
@@ -58,6 +54,9 @@ bool renderer_init(renderer* ren) {
// default_material_init();
+ // Create default rendering pipeline
+ default_pipelines_init(ren);
+
return true;
}
void renderer_shutdown(renderer* ren) {
@@ -71,10 +70,63 @@ void default_pipelines_init(renderer* ren) {
// graphics_pipeline_desc gfx = {
// };
// ren->static_opaque_pipeline = gpu_graphics_pipeline_create();
+ arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024);
+
+ gpu_renderpass_desc pass_description = {};
+ gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description);
+
+ ren->default_renderpass = *renderpass;
+
+ str8 vert_path = str8lit("celeritas-core/build/linux/x86_64/debug/triangle.vert.spv");
+ str8 frag_path = str8lit("celeritas-core/build/linux/x86_64/debug/triangle.frag.spv");
+ 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")
+ }
+
+ struct graphics_pipeline_desc pipeline_description = {
+ .debug_name = "Basic Pipeline",
+ .vs = { .debug_name = "Triangle Vertex Shader",
+ .filepath = vert_path,
+ .code = vertex_shader.contents,
+ .is_spirv = true },
+ .fs = { .debug_name = "Triangle Fragment Shader",
+ .filepath = frag_path,
+ .code = fragment_shader.contents,
+ .is_spirv = true },
+ .renderpass = renderpass,
+ .wireframe = false,
+ .depth_test = false
+ };
+ gpu_pipeline* gfx_pipeline = gpu_graphics_pipeline_create(pipeline_description);
+ ren->static_opaque_pipeline = *gfx_pipeline;
}
-void render_frame_begin(renderer* ren) {}
-void render_frame_end(renderer* ren) {}
+void render_frame_begin(renderer* ren) {
+ ren->frame_aborted = false;
+ if (!gpu_backend_begin_frame()) {
+ ren->frame_aborted = true;
+ return;
+ }
+ gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
+ // begin recording
+ gpu_cmd_encoder_begin(*enc);
+ gpu_cmd_encoder_begin_render(enc, &ren->default_renderpass);
+ encode_bind_pipeline(enc, PIPELINE_GRAPHICS, &ren->static_opaque_pipeline);
+ encode_set_default_settings(enc);
+}
+void render_frame_end(renderer* ren) {
+ if (ren->frame_aborted) {
+ return;
+ }
+ gpu_temp_draw();
+ gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder();
+ gpu_cmd_encoder_end_render(enc);
+ gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc);
+ gpu_queue_submit(&buf);
+ gpu_backend_end_frame();
+}
void render_frame_draw(renderer* ren) {}
void gfx_backend_draw_frame(renderer* ren, camera* camera, mat4 model, texture* tex) {}
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 3763967..06a8415 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -32,7 +32,9 @@ typedef struct renderer {
renderer_config config;
gpu_device device;
gpu_swapchain swapchain;
+ gpu_renderpass default_renderpass;
gpu_pipeline static_opaque_pipeline;
+ bool frame_aborted;
} renderer;
typedef struct geometry_data {
diff --git a/src/systems/input.c b/src/systems/input.c
index fc62db8..5df1159 100644
--- a/src/systems/input.c
+++ b/src/systems/input.c
@@ -25,6 +25,7 @@ bool input_system_init(input_state *input, GLFWwindow *window) {
assert(input->mouse.x_delta == 0);
assert(input->mouse.y_delta == 0);
+ INFO("Finish input init");
return true;
}