summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-22 15:12:44 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-22 15:12:44 +1000
commit51d0535a8d49b72ab1e47acf30f654403a94c423 (patch)
treec8e8124c7a35c2fcfa7afa857b50ce0cdb15ba7c /src
parent6fccac3372170153b59e829d11c6c0b0a5c2bc77 (diff)
wip: porting shadowmaps to RAL
Diffstat (limited to 'src')
-rw-r--r--src/maths/maths_types.h2
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c40
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h4
-rw-r--r--src/renderer/ral.h5
-rw-r--r--src/renderer/renderpasses.c49
-rw-r--r--src/renderer/renderpasses.h17
6 files changed, 105 insertions, 12 deletions
diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h
index 5ef09db..609672c 100644
--- a/src/maths/maths_types.h
+++ b/src/maths/maths_types.h
@@ -92,7 +92,7 @@ typedef struct u32x2 {
u32 x;
u32 y;
} u32x2;
-#define u32x2(x, y) ((u32x3){ x, y })
+#define u32x2(x, y) ((u32x2){ x, y })
// Type aliass
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index 18d1617..0d69296 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -1,5 +1,6 @@
#include <stddef.h>
#include <stdio.h>
+#include <string.h>
#include "builtin_materials.h"
#include "colours.h"
#include "maths.h"
@@ -109,15 +110,12 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
&blocksize);
printf("\t with size %d bytes\n", blocksize);
- glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, s_binding_point, ubo_buf->id.ubo);
if (blockIndex != GL_INVALID_INDEX) {
glUniformBlockBinding(pipeline->shader_id, blockIndex, s_binding_point);
}
ubo_buf->ubo_binding_point = s_binding_point;
s_binding_point++;
-
- // Now we want to store a handle associated with the shader for this
}
}
}
@@ -129,8 +127,38 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
void gpu_pipeline_destroy(gpu_pipeline* pipeline) {}
// --- Renderpass
-gpu_renderpass* gpu_renderpass_create(const gpu_renderpass_desc* description) {}
-void gpu_renderpass_destroy(gpu_renderpass* pass) {}
+gpu_renderpass* gpu_renderpass_create(const gpu_renderpass_desc* description) {
+ gpu_renderpass* renderpass = renderpass_pool_alloc(&context.gpu_pools.renderpasses, NULL);
+
+ memcpy(&renderpass->description, description, sizeof(gpu_renderpass_desc));
+
+ if (!description->default_framebuffer) {
+ GLuint gl_fbo_id;
+ glGenFramebuffers(1, &gl_fbo_id);
+ renderpass->fbo = gl_fbo_id;
+ } else {
+ renderpass->fbo = OPENGL_DEFAULT_FRAMEBUFFER;
+ assert(!description->has_color_target);
+ assert(!description->has_depth_stencil);
+ }
+ glBindFramebuffer(GL_FRAMEBUFFER, renderpass->fbo);
+
+ if (description->has_color_target) {
+ gpu_texture* colour_attachment = TEXTURE_GET(description->color_target);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colour_attachment->id, 0);
+ }
+ if (description->has_depth_stencil) {
+ gpu_texture* depth_attachment = TEXTURE_GET(description->depth_stencil);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depth_attachment->id, 0);
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0); // reset to default framebuffer
+
+ return renderpass;
+}
+void gpu_renderpass_destroy(gpu_renderpass* pass) {
+ glDeleteFramebuffers(1, &pass->fbo);
+}
// --- Swapchain
bool gpu_swapchain_create(gpu_swapchain* out_swapchain) {}
@@ -144,6 +172,7 @@ gpu_cmd_encoder gpu_cmd_encoder_create() {
void gpu_cmd_encoder_destroy(gpu_cmd_encoder* encoder) {}
void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder) {}
void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) {
+ glBindFramebuffer(GL_FRAMEBUFFER, renderpass->fbo);
rgba clear_colour = STONE_800;
glClearColor(clear_colour.r, clear_colour.g, clear_colour.b, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -206,7 +235,6 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d
}
glBindBuffer(GL_UNIFORM_BUFFER, ubo_buf->id.ubo);
- glBindBufferBase(GL_UNIFORM_BUFFER, ubo_buf->ubo_binding_point, ubo_buf->id.ubo);
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo_buf->size, binding.data.bytes.data);
} else if (binding.type == SHADER_BINDING_TEXTURE) {
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index f52bd79..f588643 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -8,6 +8,8 @@
#define MAX_PIPELINE_UNIFORM_BUFFERS 32
+#define OPENGL_DEFAULT_FRAMEBUFFER 0
+
typedef struct gpu_swapchain {
u32x2 dimensions;
} gpu_swapchain;
@@ -23,6 +25,8 @@ typedef struct gpu_pipeline {
bool wireframe;
} gpu_pipeline;
typedef struct gpu_renderpass {
+ u32 fbo;
+ gpu_renderpass_desc description;
void *pad
} gpu_renderpass;
typedef struct gpu_cmd_encoder {
diff --git a/src/renderer/ral.h b/src/renderer/ral.h
index cd3f19f..ab62679 100644
--- a/src/renderer/ral.h
+++ b/src/renderer/ral.h
@@ -97,7 +97,10 @@ struct graphics_pipeline_desc {
};
typedef struct gpu_renderpass_desc {
- texture_handle color_target; // for now only support one
+ bool default_framebuffer;
+ bool has_color_target;
+ texture_handle color_target; // for now only support one
+ bool has_depth_stencil;
texture_handle depth_stencil;
} gpu_renderpass_desc;
diff --git a/src/renderer/renderpasses.c b/src/renderer/renderpasses.c
new file mode 100644
index 0000000..85b86ed
--- /dev/null
+++ b/src/renderer/renderpasses.c
@@ -0,0 +1,49 @@
+/**
+ * @file renderpasses.c
+ * @author your name (you@domain.com)
+ * @brief
+ * @version 0.1
+ * @date 2024-06-22
+ *
+ * @copyright Copyright (c) 2024
+ *
+ */
+
+#include "renderpasses.h"
+#include "maths_types.h"
+#include "ral.h"
+#include "ral_types.h"
+
+#define SHADOW_WIDTH 1000
+#define SHADOW_HEIGHT 1000
+
+
+gpu_renderpass* shadowmaps_renderpass_create() {
+ // Create depthmap texture
+ u32x2 extents = u32x2(SHADOW_WIDTH, SHADOW_HEIGHT);
+ texture_desc depthmap_desc = {
+ .extents = extents,
+ .format = CEL_TEXTURE_FORMAT_DEPTH_DEFAULT,
+ .tex_type = CEL_TEXTURE_TYPE_2D
+ };
+ texture_handle depthmap = gpu_texture_create(depthmap_desc, false, NULL);
+
+ gpu_renderpass_desc shadows_desc = {
+ .default_framebuffer = false,
+ .has_color_target = false,
+ .has_depth_stencil = true,
+ .depth_stencil = depthmap
+ };
+ return gpu_renderpass_create(&shadows_desc);
+}
+
+gpu_pipeline* shadowmaps_pipeline_create() {
+ struct graphics_pipeline_desc desc = {
+ .
+ };
+ gpu_graphics_pipeline_create(struct graphics_pipeline_desc description)
+}
+
+void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count) {
+
+} \ No newline at end of file
diff --git a/src/renderer/renderpasses.h b/src/renderer/renderpasses.h
index 951ff6e..4a689e6 100644
--- a/src/renderer/renderpasses.h
+++ b/src/renderer/renderpasses.h
@@ -9,9 +9,7 @@
*
*/
#pragma once
-#include "maths_types.h"
#include "ral.h"
-#include "render.h"
#include "render_types.h"
// Shadowmap pass
@@ -24,5 +22,16 @@ gpu_renderpass* renderpass_blinn_phong_create();
void renderpass_blinn_phong_execute(gpu_renderpass* pass, render_entity* entities,
size_t entity_count);
-gpu_renderpass* renderpass_shadows_create();
-void renderpass_shadows_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count); \ No newline at end of file
+typedef struct ren_shadowmaps {
+ u32 width;
+ u32 height;
+ gpu_renderpass* rpass;
+ gpu_pipeline* static_pipeline;
+} ren_shadowmaps;
+
+void ren_shadowmaps_init(ren_shadowmaps* storage);
+
+gpu_renderpass* shadowmaps_renderpass_create();
+gpu_pipeline* shadowmaps_pipeline_create();
+
+void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count);