summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/new_render/pbr.c3
-rw-r--r--src/new_render/render.c10
-rw-r--r--src/new_render/render.h1
-rw-r--r--src/new_render/skybox.c3
-rw-r--r--src/ral/backends/opengl/backend_opengl.c14
-rw-r--r--src/ral/ral_common.h4
-rw-r--r--src/ral/ral_impl.h2
-rw-r--r--src/render/render.c3
8 files changed, 36 insertions, 4 deletions
diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c
index 46c621f..0a19ee1 100644
--- a/src/new_render/pbr.c
+++ b/src/new_render/pbr.c
@@ -71,7 +71,8 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
// Feed shader data
Mat4 view, proj;
- Camera_ViewProj(&camera, 1000, 1000, &view, &proj);
+ u32x2 dimensions = GPU_Swapchain_GetDimensions();
+ Camera_ViewProj(&camera, (f32)dimensions.x, (f32)dimensions.y, &view, &proj);
Binding_Camera camera_data = { .view = view,
.projection = proj,
.viewPos = vec4(camera.position.x, camera.position.y,
diff --git a/src/new_render/render.c b/src/new_render/render.c
index 07913f8..11f7e0a 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -81,6 +81,9 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window
glfwMakeContextCurrent(ren->window);
+ DEBUG("Set up GLFW window callbacks");
+ glfwSetWindowSizeCallback(window, Render_WindowSizeChanged);
+
// set the RAL backend up
if (!GPU_Backend_Init(config.window_name, window, ren->resource_pools)) {
return false;
@@ -116,6 +119,13 @@ void Renderer_Shutdown(Renderer* ren) {
}
size_t Renderer_GetMemReqs() { return sizeof(Renderer); }
+void Render_WindowSizeChanged(GLFWwindow* window, i32 new_width, i32 new_height) {
+ (void)window;
+ INFO("Window size changed callback");
+ // Renderer* ren = Core_GetRenderer(&g_core);
+ GPU_Swapchain_Resize(new_width, new_height);
+}
+
void Render_FrameBegin(Renderer* ren) {
arena_free_all(&ren->frame_arena);
ren->frame_aborted = false;
diff --git a/src/new_render/render.h b/src/new_render/render.h
index 13c626d..52aecfc 100644
--- a/src/new_render/render.h
+++ b/src/new_render/render.h
@@ -30,6 +30,7 @@ typedef struct RenderCtx {
PUB bool Renderer_Init(RendererConfig config, Renderer* renderer, GLFWwindow** out_window);
PUB void Renderer_Shutdown(Renderer* renderer);
PUB size_t Renderer_GetMemReqs();
+void Render_WindowSizeChanged(GLFWwindow* window, i32 new_width, i32 new_height);
// internal init functions
void DefaultPipelinesInit(Renderer* renderer);
diff --git a/src/new_render/skybox.c b/src/new_render/skybox.c
index 8ac8356..b054366 100644
--- a/src/new_render/skybox.c
+++ b/src/new_render/skybox.c
@@ -128,7 +128,8 @@ void Skybox_Draw(Skybox* skybox, Camera camera) {
// Shader data
Mat4 view, proj;
- Camera_ViewProj(&camera, 1000, 1000, &view, &proj);
+ u32x2 dimensions = GPU_Swapchain_GetDimensions();
+ Camera_ViewProj(&camera, dimensions.x, dimensions.y, &view, &proj);
Mat4 new = mat4_ident();
new.data[0] = view.data[0];
new.data[1] = view.data[1];
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c
index 10a21d1..97c86dd 100644
--- a/src/ral/backends/opengl/backend_opengl.c
+++ b/src/ral/backends/opengl/backend_opengl.c
@@ -1,4 +1,5 @@
#include "backend_opengl.h"
+#include "maths_types.h"
#if defined(CEL_REND_BACKEND_OPENGL)
#include <assert.h>
#include "log.h"
@@ -14,6 +15,7 @@
typedef struct OpenglCtx {
GLFWwindow* window;
arena pool_arena;
+ GPU_Swapchain swapchain;
GPU_CmdEncoder main_encoder;
GPU_BackendPools gpu_pools;
ResourcePools* resource_pools;
@@ -48,12 +50,13 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window,
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
+ context.swapchain = (GPU_Swapchain){ .dimensions = u32x2(1000, 1000) };
+
return true;
}
// All of these are no-ops in OpenGL
-void GPU_Backend_Shutdown() { /* TODO */
-}
+void GPU_Backend_Shutdown() { /* TODO */ }
bool GPU_Device_Create(GPU_Device* out_device) { return true; }
void GPU_Device_Destroy(GPU_Device* device) {}
bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain) { return true; }
@@ -64,6 +67,12 @@ void GPU_CmdEncoder_EndRender(GPU_CmdEncoder* encoder) {}
GPU_CmdEncoder* GPU_GetDefaultEncoder() { return &context.main_encoder; }
void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer) {}
+void GPU_Swapchain_Resize(i32 new_width, i32 new_height) {
+ context.swapchain.dimensions = u32x2(new_width, new_height);
+}
+
+u32x2 GPU_Swapchain_GetDimensions() { return context.swapchain.dimensions; }
+
GPU_Renderpass* GPU_Renderpass_Create(GPU_RenderpassDesc description) {
// allocate new pass
GPU_Renderpass* renderpass = Renderpass_pool_alloc(&context.gpu_pools.renderpasses, NULL);
@@ -382,6 +391,7 @@ void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count) {
}
bool GPU_Backend_BeginFrame() {
+ glViewport(0, 0, context.swapchain.dimensions.x * 2, context.swapchain.dimensions.y * 2);
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return true;
diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h
index 63816b1..2bcc013 100644
--- a/src/ral/ral_common.h
+++ b/src/ral/ral_common.h
@@ -41,6 +41,10 @@ void ResourcePools_Init(arena* a, struct ResourcePools* res_pools);
PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to
// default framebuffer with default depth
+// --
+// window resize callback
+void GPU_WindowResizedCallback(u32 x, u32 y);
+
// --- Vertex formats
VertexDescription static_3d_vertex_description();
diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h
index 6676b6c..5376920 100644
--- a/src/ral/ral_impl.h
+++ b/src/ral/ral_impl.h
@@ -29,6 +29,8 @@ void GPU_Device_Destroy(GPU_Device* device);
bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain);
void GPU_Swapchain_Destroy(GPU_Swapchain* swapchain);
+void GPU_Swapchain_Resize(i32 new_width, i32 new_height);
+u32x2 GPU_Swapchain_GetDimensions();
PUB GPU_Renderpass* GPU_Renderpass_Create(GPU_RenderpassDesc description);
PUB void GPU_Renderpass_Destroy(GPU_Renderpass* pass);
diff --git a/src/render/render.c b/src/render/render.c
index f52e2be..22542df 100644
--- a/src/render/render.c
+++ b/src/render/render.c
@@ -47,6 +47,9 @@ bool renderer_init(renderer* ren) {
glfwMakeContextCurrent(ren->window);
+ DEBUG("Set up GLFW window callbacks");
+
+
DEBUG("Start gpu backend init");
if (!gpu_backend_init("Celeritas Engine - Vulkan", window)) {