summaryrefslogtreecommitdiff
path: root/src/renderer/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/render.c')
-rw-r--r--src/renderer/render.c76
1 files changed, 64 insertions, 12 deletions
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) {}