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/new_render | |
parent | 9d11440c145cef897853576b509316bf952cb121 (diff) |
wip egui
Diffstat (limited to 'src/new_render')
-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 |
5 files changed, 39 insertions, 16 deletions
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 |