diff options
author | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-26 16:37:53 +1000 |
---|---|---|
committer | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-26 16:37:53 +1000 |
commit | f083cacb259054ce996b70f8b9dc0d9eb0bdbfb8 (patch) | |
tree | cfec9813483e139d8f4ca71eefb4ec9a0450826f /src | |
parent | 9d11440c145cef897853576b509316bf952cb121 (diff) |
wip egui
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core.c | 10 | ||||
-rw-r--r-- | src/defines.h | 3 | ||||
-rw-r--r-- | src/maths/maths.c | 5 | ||||
-rw-r--r-- | src/maths/maths.h | 4 | ||||
-rw-r--r-- | src/new_render/pbr.c | 29 | ||||
-rw-r--r-- | src/new_render/render.c | 12 | ||||
-rw-r--r-- | src/new_render/shadows.c | 4 | ||||
-rw-r--r-- | src/new_render/skybox.c | 8 | ||||
-rw-r--r-- | src/new_render/skybox.h | 2 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 8 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.h | 2 | ||||
-rw-r--r-- | src/systems/input.c | 2 |
12 files changed, 63 insertions, 26 deletions
diff --git a/src/core/core.c b/src/core/core.c index d508de8..a46e395 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -68,10 +68,18 @@ bool ShouldExit() { } void Frame_Begin() { - Input_Update(&g_core.input); + // Input_Update(&g_core.input); Render_FrameBegin(g_core.renderer); } void Frame_Draw() {} void Frame_End() { Render_FrameEnd(g_core.renderer); } +Core* get_global_core() { + return &g_core; +} + +GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { + return g_core.window; +} + struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; }
\ No newline at end of file diff --git a/src/defines.h b/src/defines.h index b147327..ce947d8 100644 --- a/src/defines.h +++ b/src/defines.h @@ -55,7 +55,8 @@ CORE_DEFINE_HANDLE( Handle); // Untyped handle that can be casted to a strongly typed resource handle #define PUB // For collecting public APIs to expose in an amalgamation header file -#define c_static_inline static inline +// #define c_static_inline static inline +#define c_static_inline static #define KB(x) ((size_t)x * 1000) #define MB(x) ((size_t)x * 1000 * 1000) diff --git a/src/maths/maths.c b/src/maths/maths.c new file mode 100644 index 0000000..bfe0b5b --- /dev/null +++ b/src/maths/maths.c @@ -0,0 +1,5 @@ +#include "maths.h" + +Mat4 mat4_ident() { + return (Mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; +}
\ No newline at end of file diff --git a/src/maths/maths.h b/src/maths/maths.h index 9b3813c..d235ca8 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -143,9 +143,7 @@ c_static_inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { // --- Matrix Implementations -c_static_inline Mat4 mat4_ident() { - return (Mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; -} +Mat4 mat4_ident(); c_static_inline Mat4 mat4_translation(Vec3 position) { Mat4 out_matrix = mat4_ident(); diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c index 0a19ee1..2393aa9 100644 --- a/src/new_render/pbr.c +++ b/src/new_render/pbr.c @@ -25,13 +25,17 @@ GPU_Renderpass* PBR_RPassCreate() { GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass) { arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - Str8 vert_path = str8("assets/shaders/pbr_textured.vert"); - Str8 frag_path = str8("assets/shaders/pbr_textured.frag"); - 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") - } + const char* vert_path = "assets/shaders/pbr_textured.vert"; + const char* frag_path = "assets/shaders/pbr_textured.frag"; + // Str8 vert_path = str8("assets/shaders/pbr_textured.vert"); + // Str8 frag_path = str8("assets/shaders/pbr_textured.frag"); + // 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") + // } + char* vert_shader = string_from_file(vert_path); + char* frag_shader = string_from_file(frag_path); ShaderData camera_data = { .get_layout = &Binding_Camera_GetLayout }; ShaderData model_data = { .get_layout = &Binding_Model_GetLayout }; @@ -44,11 +48,14 @@ GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass) { .data_layouts = {camera_data,model_data,material_data, lights_data }, .data_layouts_count = 4, .vs = { .debug_name = "PBR (textured) Vertex Shader", - .filepath = vert_path, - .code = vertex_shader.contents }, + .filepath = str8(vert_path), + // .code = vertex_shader.contents + .code = vert_shader + }, .fs = { .debug_name = "PBR (textured) Fragment Shader", - .filepath = frag_path, - .code = fragment_shader.contents, + .filepath = str8(frag_path), + .code = frag_shader + // .code = fragment_shader.contents, }, .depth_test = true, .wireframe = false, diff --git a/src/new_render/render.c b/src/new_render/render.c index a5eae33..c8660a3 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -4,6 +4,7 @@ #include "render.h" #include <assert.h> +#include "glad/glad.h" #include <glfw3.h> #include "camera.h" #include "core.h" @@ -73,8 +74,8 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); #endif - GLFWwindow* window = - glfwCreateWindow(config.scr_width, config.scr_height, config.window_name, NULL, NULL); + window = glfwCreateWindow(config.scr_width, config.scr_height, config.window_name, NULL, NULL); + INFO("Window created"); if (window == NULL) { ERROR("Failed to create GLFW window\n"); glfwTerminate(); @@ -94,7 +95,7 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window ren->window = window; *out_window = window; - glfwMakeContextCurrent(ren->window); + // glfwMakeContextCurrent(ren->window); // FIXME // DEBUG("Set up GLFW window callbacks"); @@ -117,13 +118,13 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window // create our renderpasses ren->shadows = malloc(sizeof(Shadow_Storage)); - Shadow_Init(ren->shadows, 1024, 1024); + // Shadow_Init(ren->shadows, 1024, 1024); ren->pbr = malloc(sizeof(PBR_Storage)); PBR_Init(ren->pbr); ren->terrain = malloc(sizeof(Terrain_Storage)); - Terrain_Init(ren->terrain); + // Terrain_Init(ren->terrain); return true; } @@ -170,6 +171,7 @@ void Render_RenderEntities(RenderEnt* entities, size_t entity_count) { RenderScene scene = ren->scene; Shadow_Storage* shadow_storage = Render_GetShadowStorage(); + shadow_storage->enabled = false; TextureHandle depthmap = shadow_storage->enabled ? Shadow_GetShadowMapTexture(shadow_storage) : INVALID_TEX_HANDLE; diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c index f62950b..6a9fe02 100644 --- a/src/new_render/shadows.c +++ b/src/new_render/shadows.c @@ -12,6 +12,7 @@ #include "render.h" #include "render_scene.h" #include "render_types.h" +#include "str.h" ShaderDataLayout ShadowUniforms_GetLayout(void* data) { ShadowUniforms* d = (ShadowUniforms*)data; @@ -56,6 +57,7 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei TextureDesc depthmap_desc = { .extents = u32x2(shadowmap_width, shadowmap_height), .format = TEXTURE_FORMAT_DEPTH_DEFAULT, .tex_type = TEXTURE_TYPE_2D }; + DEBUG("Creating depth map texture for shadows"); TextureHandle depthmap = GPU_TextureCreate(depthmap_desc, false, NULL); storage->depth_texture = depthmap; @@ -67,6 +69,8 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei storage->shadowmap_pass = GPU_Renderpass_Create(rpass_desc); + WARN("About to laod shaders"); + WARN("Shader paths: %s %s", "assets/shaders/shadows.vert", "assets/shaders/shadows.frag"); Str8 vert_path = str8("assets/shaders/shadows.vert"); Str8 frag_path = str8("assets/shaders/shadows.frag"); str8_opt vertex_shader = str8_from_file(&scratch, vert_path); diff --git a/src/new_render/skybox.c b/src/new_render/skybox.c index 882123d..8ba4da9 100644 --- a/src/new_render/skybox.c +++ b/src/new_render/skybox.c @@ -33,6 +33,10 @@ float skyboxVertices[] = { 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f }; +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/front.jpg", "assets/demo/skybox/back.jpg" }; + Skybox Skybox_Create(const char** face_paths, int n) { INFO("Creating a skybox"); assert(n == 6); // ! we're only supporting a full cubemap for now @@ -118,6 +122,10 @@ Skybox Skybox_Create(const char** face_paths, int n) { return (Skybox){ .cube = cube, .texture = handle, .pipeline = pipeline }; } +Skybox Skybox_Default() { + return Skybox_Create(faces, 6); +} + void Skybox_Draw(Skybox* skybox, Camera camera) { GPU_CmdEncoder* enc = GPU_GetDefaultEncoder(); glDepthFunc(GL_LEQUAL); diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h index 465d603..3b5b55b 100644 --- a/src/new_render/skybox.h +++ b/src/new_render/skybox.h @@ -37,3 +37,5 @@ static ShaderDataLayout Skybox_GetLayout(void* data) { } return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } + +Skybox Skybox_Default();
\ No newline at end of file diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 7929a16..9122e15 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -37,10 +37,10 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, BackendPools_Init(&context.pool_arena, &context.gpu_pools); context.resource_pools = res_pools; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // glad: load all opengl function pointers if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h index 98ffe95..b27d782 100644 --- a/src/ral/backends/opengl/backend_opengl.h +++ b/src/ral/backends/opengl/backend_opengl.h @@ -16,6 +16,7 @@ typedef struct GPU_Swapchain { } GPU_Swapchain; typedef struct GPU_Device { + u32 pad; } GPU_Device; typedef struct GPU_PipelineLayout { @@ -64,6 +65,7 @@ typedef struct GPU_Texture { } GPU_Texture; typedef struct opengl_support { + u32 pad; } opengl_support; // u32 shader_create_separate(const char *vert_shader, const char *frag_shader); diff --git a/src/systems/input.c b/src/systems/input.c index 1122576..fa76273 100644 --- a/src/systems/input.c +++ b/src/systems/input.c @@ -32,7 +32,7 @@ bool Input_Init(Input_State *input, GLFWwindow *window) { void Input_Shutdown(Input_State *input) {} void Input_Update(Input_State *input) { - glfwPollEvents(); + // glfwPollEvents(); // --- update keyboard input // if we go from un-pressed -> pressed, set as "just pressed" |