summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-20 19:47:25 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-20 19:47:25 +1000
commit58a748dcd77d0caacc9d6ef7a7e7e073ac849ad3 (patch)
tree054108cf40ad4e9c147db4e8723485e72d9a7b98
parent0a984656f5fec68c90acc612b01f897918c0070b (diff)
resize viewport and fix skybox
-rw-r--r--assets/shaders/skybox.vert4
-rw-r--r--examples/game_demo/game_demo.c3
-rw-r--r--scripts/amalgamation/gen_amalgamation.py24
-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
11 files changed, 63 insertions, 8 deletions
diff --git a/assets/shaders/skybox.vert b/assets/shaders/skybox.vert
index 8db1f4f..6b56527 100644
--- a/assets/shaders/skybox.vert
+++ b/assets/shaders/skybox.vert
@@ -1,8 +1,8 @@
#version 410 core
layout(location = 0) in vec3 inPosition;
-layout(location = 1) in vec3 inNormal;
-layout(location = 2) in vec2 inTexCoords;
+// layout(location = 1) in vec3 inNormal;
+// layout(location = 2) in vec2 inTexCoords;
uniform Camera {
mat4 view;
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index cb969cf..f4cf643 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -13,11 +13,10 @@
#include "render_scene.h"
#include "render_types.h"
#include "skybox.h"
-#include "str.h"
static const char* faces[6] = { "assets/demo/skybox/right.jpg", "assets/demo/skybox/left.jpg",
"assets/demo/skybox/top.jpg", "assets/demo/skybox/bottom.jpg",
- "assets/demo/skybox/back.jpg", "assets/demo/skybox/front.jpg" };
+ "assets/demo/skybox/front.jpg", "assets/demo/skybox/back.jpg" };
int main() {
Core_Bringup();
diff --git a/scripts/amalgamation/gen_amalgamation.py b/scripts/amalgamation/gen_amalgamation.py
new file mode 100644
index 0000000..45a1c21
--- /dev/null
+++ b/scripts/amalgamation/gen_amalgamation.py
@@ -0,0 +1,24 @@
+# Generates a single amalgamation C header file that includes all public types and functions.
+#
+# This makes including and linking Celeritas very easy.
+import re
+import sys
+
+def find_pub_functions(filepath):
+ pattern = r'PUB\s+(\w+\s+)*(\w+)\s+(\w+)\s*\((.*?)\)'
+
+ with open(filepath, 'r') as file:
+ content = file.read()
+
+ matches = re.finditer(pattern, content, re.MULTILINE)
+
+ for match in matches:
+ print(match.group(0))
+
+if __name__ == "__main__":
+ if len(sys.argv) != 2:
+ print("Usage: python script.py <path_to_c_file>")
+ sys.exit(1)
+
+ file_path = sys.argv[1]
+ find_pub_functions(file_path)
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)) {