summaryrefslogtreecommitdiff
path: root/src/new_render
diff options
context:
space:
mode:
authoromnisci3nce <omniscient.oce@gmail.com>2024-07-17 14:45:31 +1000
committeromnisci3nce <omniscient.oce@gmail.com>2024-07-17 14:45:31 +1000
commitf8641a5cc4c8baf1f0a7be3685afc219d90143d9 (patch)
tree6f6edf43f88b456933330ec83a203bf2f414bea4 /src/new_render
parentb9315f9cb625db09c3c41d8adf5230a67510bef7 (diff)
whole thing is compiling and running again
Diffstat (limited to 'src/new_render')
-rw-r--r--src/new_render/render.c30
-rw-r--r--src/new_render/render.h3
-rw-r--r--src/new_render/render_scene.h2
-rw-r--r--src/new_render/shadows.c5
-rw-r--r--src/new_render/shadows.h2
5 files changed, 31 insertions, 11 deletions
diff --git a/src/new_render/render.c b/src/new_render/render.c
index 21046ea..1fef610 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -35,7 +35,9 @@ struct Renderer {
ResourcePools* resource_pools;
};
-bool Renderer_Init(RendererConfig config, Renderer* ren) {
+Renderer* get_renderer() { return g_core.renderer; }
+
+bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window) {
INFO("Renderer init");
// init resource pools
@@ -66,6 +68,7 @@ bool Renderer_Init(RendererConfig config, Renderer* ren) {
return false;
}
ren->window = window;
+ *out_window = window;
glfwMakeContextCurrent(ren->window);
@@ -81,16 +84,17 @@ bool Renderer_Init(RendererConfig config, Renderer* ren) {
Camera default_cam =
Camera_Create(vec3(0.0, 2.0, 4.0), vec3_normalise(vec3(0.0, -2.0, -4.0)), VEC3_Y, 45.0);
SetCamera(default_cam);
- PointLight default_light = { /* TODO */ };
- SetPointLight(default_light);
+ DirectionalLight default_light = { /* TODO */ };
+ SetMainLight(default_light);
// create our renderpasses
- Shadow_Init(ren->shadows);
+ ren->shadows = malloc(sizeof(Shadow_Storage));
+ Shadow_Init(ren->shadows, u32x2(512, 512));
return true;
}
-void Renderer_Shutdown(Renderer* ren) {}
+void Renderer_Shutdown(Renderer* ren) { free(ren->shadows); }
size_t Renderer_GetMemReqs() { return sizeof(Renderer); }
void Render_FrameBegin(Renderer* ren) {
@@ -107,9 +111,11 @@ void Render_FrameEnd(Renderer* ren) {
}
GPU_CmdEncoder* enc = GPU_GetDefaultEncoder();
+
+ GPU_Backend_EndFrame();
}
void Render_RenderEntities(RenderEnt* entities, size_t entity_count) {
- Renderer* ren = Core_GetRenderer(&g_core);
+ Renderer* ren = get_renderer();
RenderScene scene = ren->scene;
// -- Shadows
@@ -144,3 +150,15 @@ Mesh Mesh_Create(Geometry* geometry, bool free_on_upload) {
}
return m;
}
+
+void Geometry_Destroy(Geometry* geometry) {
+ if (geometry->indices) {
+ u32_darray_free(geometry->indices);
+ }
+ if (geometry->vertices) {
+ Vertex_darray_free(geometry->vertices);
+ }
+}
+
+void SetCamera(Camera camera) { g_core.renderer->scene.camera = camera; }
+void SetMainLight(DirectionalLight light) { g_core.renderer->scene.sun = light; } \ No newline at end of file
diff --git a/src/new_render/render.h b/src/new_render/render.h
index 6e9f380..fa05fec 100644
--- a/src/new_render/render.h
+++ b/src/new_render/render.h
@@ -9,6 +9,7 @@
#include "render_types.h"
typedef struct Renderer Renderer;
+typedef struct GLFWwindow GLFWwindow;
typedef struct RendererConfig {
char window_name[256];
u32 scr_width, scr_height;
@@ -22,7 +23,7 @@ typedef struct RenderCtx {
// --- Lifecycle
-PUB bool Renderer_Init(RendererConfig config, Renderer* renderer);
+PUB bool Renderer_Init(RendererConfig config, Renderer* renderer, GLFWwindow** out_window);
PUB void Renderer_Shutdown(Renderer* renderer);
PUB size_t Renderer_GetMemReqs();
diff --git a/src/new_render/render_scene.h b/src/new_render/render_scene.h
index 791e862..1e4660a 100644
--- a/src/new_render/render_scene.h
+++ b/src/new_render/render_scene.h
@@ -17,4 +17,4 @@ typedef struct RenderScene {
// --- Public APIs
PUB void SetCamera(Camera camera);
-PUB void SetPointLight(PointLight light);
+PUB void SetMainLight(DirectionalLight light);
diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c
index df836b4..612fd34 100644
--- a/src/new_render/shadows.c
+++ b/src/new_render/shadows.c
@@ -1,6 +1,7 @@
-#include <string.h>
#include "shadows.h"
+#include <string.h>
#include "core.h"
+#include "file.h"
#include "log.h"
#include "maths.h"
#include "ral_common.h"
@@ -28,7 +29,7 @@ ShaderDataLayout ShadowUniforms_GetLayout(void* data) {
};
if (has_data) {
- b1.data.bytes.data = data;
+ b1.data.bytes.data = data;
}
return (ShaderDataLayout){ .binding_count = 1, .bindings = { b1 } };
diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h
index 81711de..4dc20e2 100644
--- a/src/new_render/shadows.h
+++ b/src/new_render/shadows.h
@@ -22,7 +22,7 @@ typedef struct Camera Camera;
typedef struct Mat4 Mat4;
// --- Public API
-PUB void Shadow_Init(Shadow_Storage* storage);
+PUB void Shadow_Init(Shadow_Storage* storage, u32x2 shadowmap_extents);
/** @brief Run shadow map generation for given entities, and store in a texture.
* @note Uses active directional light for now */