diff options
author | Omni <omniscient.oce@gmail.com> | 2024-06-23 17:22:36 +1000 |
---|---|---|
committer | Omni <omniscient.oce@gmail.com> | 2024-06-23 17:22:36 +1000 |
commit | 0cbc42e89dcdeb47aaa63bb21b5fb911768ea4df (patch) | |
tree | b28c0bf40d03bcda86289ef42e8df8ad67539fdd | |
parent | 17f0db6607534c5bf1ba96153fabd3fdbb399ed9 (diff) |
depth map is working again
-rw-r--r-- | assets/shaders/cube.frag | 1 | ||||
-rw-r--r-- | assets/shaders/debug_quad.frag | 3 | ||||
-rw-r--r-- | examples/cube/ex_cube.c | 4 | ||||
-rw-r--r-- | examples/shadow_maps/ex_shadow_maps.c | 129 | ||||
-rw-r--r-- | src/maths/primitives.c | 30 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.c | 74 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.h | 3 | ||||
-rw-r--r-- | src/renderer/ral.c | 6 | ||||
-rw-r--r-- | src/renderer/ral.h | 2 | ||||
-rw-r--r-- | src/renderer/render.c | 2 | ||||
-rw-r--r-- | src/renderer/renderpasses.c | 28 |
11 files changed, 204 insertions, 78 deletions
diff --git a/assets/shaders/cube.frag b/assets/shaders/cube.frag index cd6bb21..a405e6a 100644 --- a/assets/shaders/cube.frag +++ b/assets/shaders/cube.frag @@ -4,7 +4,6 @@ layout(location = 0) in vec3 fragColor; layout(location = 1) in vec2 fragTexCoord; uniform sampler2D texSampler; -// uniform sampler2D texSampler; layout(location = 0) out vec4 outColor; diff --git a/assets/shaders/debug_quad.frag b/assets/shaders/debug_quad.frag index ac7842d..877b26a 100644 --- a/assets/shaders/debug_quad.frag +++ b/assets/shaders/debug_quad.frag @@ -9,4 +9,5 @@ void main() { float depthValue = texture(depthMap, TexCoords).r; FragColor = vec4(vec3(depthValue), 1.0); // orthographic -}
\ No newline at end of file + //FragColor = vec4(1.0); +} diff --git a/examples/cube/ex_cube.c b/examples/cube/ex_cube.c index 3c98087..5a19f2c 100644 --- a/examples/cube/ex_cube.c +++ b/examples/cube/ex_cube.c @@ -46,7 +46,7 @@ shader_data_layout mvp_uniforms_layout(void* data) { .stores_data = has_data, .data = { .bytes = { .size = sizeof(mvp_uniforms) } } }; - shader_binding b2 = { .label = "texture_sampler", + shader_binding b2 = { .label = "texSampler", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; if (has_data) { @@ -75,7 +75,7 @@ int main() { shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout }; - gpu_renderpass_desc pass_description = {}; + gpu_renderpass_desc pass_description = { .default_framebuffer = true }; gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); str8 vert_path, frag_path; diff --git a/examples/shadow_maps/ex_shadow_maps.c b/examples/shadow_maps/ex_shadow_maps.c index 30df618..28cab86 100644 --- a/examples/shadow_maps/ex_shadow_maps.c +++ b/examples/shadow_maps/ex_shadow_maps.c @@ -2,6 +2,7 @@ #include "maths.h" #include "maths_types.h" #include "primitives.h" +#include "log.h" #include "ral.h" #include "ral_types.h" #include "render.h" @@ -21,14 +22,96 @@ transform s_transforms[5]; */ void draw_scene(); +void switch_view(); + +enum active_view { + SceneView, + LightView, + DebugQuad, +}; + +// Define the shader data +typedef struct mvp_uniforms { + mat4 model; + mat4 view; + mat4 projection; +} mvp_uniforms; +typedef struct my_shader_bind_group { + mvp_uniforms mvp; + texture_handle tex; +} my_shader_bind_group; + +// We also must create a function that knows how to return a `shader_data_layout` +shader_data_layout mvp_uniforms_layout(void* data) { + my_shader_bind_group* d = (my_shader_bind_group*)data; + bool has_data = data != NULL; + + shader_binding b1 = { .label = "Matrices", + .type = SHADER_BINDING_BYTES, + .stores_data = has_data, + .data = { .bytes = { .size = sizeof(mvp_uniforms) } } }; + + shader_binding b2 = { .label = "texSampler", + .type = SHADER_BINDING_TEXTURE, + .stores_data = has_data }; + if (has_data) { + b1.data.bytes.data = &d->mvp; + b2.data.texture.handle = d->tex; + } + return (shader_data_layout){ .name = "global_ubo", .bindings = { b1, b2 }, .bindings_count = 2 }; +} int main() { core_bringup(); arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - vec3 camera_pos = vec3(2., 2., 2.); + vec3 camera_pos = vec3(5,5,5); vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); + // TEMP + shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout }; + + gpu_renderpass_desc pass_description = { .default_framebuffer = true }; + gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); + + str8 vert_path, frag_path; +#ifdef CEL_REND_BACKEND_OPENGL + vert_path = str8lit("assets/shaders/cube.vert"); + frag_path = str8lit("assets/shaders/cube.frag"); +#else + vert_path = str8lit("build/linux/x86_64/debug/cube.vert.spv"); + frag_path = str8lit("build/linux/x86_64/debug/cube.frag.spv"); +#endif + 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") + } + + struct graphics_pipeline_desc pipeline_description = { + .debug_name = "Basic Pipeline", + .vertex_desc = static_3d_vertex_description(), + .data_layouts = { mvp_uniforms_data }, + .data_layouts_count = 1, + .vs = { .debug_name = "Cube Vertex Shader", + .filepath = vert_path, + .code = vertex_shader.contents, + .is_spirv = true }, + .fs = { .debug_name = "Cube Fragment Shader", + .filepath = frag_path, + .code = fragment_shader.contents, + .is_spirv = true }, + .renderpass = renderpass, + .wireframe = false, + .depth_test = false + }; + gpu_pipeline* gfx_pipeline = gpu_graphics_pipeline_create(pipeline_description); + + // Texture + texture_data tex_data = texture_data_load("assets/textures/texture.jpg", false); + texture_handle texture = texture_data_upload(tex_data, true); + + // END TEMP ren_shadowmaps shadows = { .width = 1000, .height = 1000 }; ren_shadowmaps_init(&shadows); @@ -39,14 +122,14 @@ int main() { // 2. lights // 3. some boxes for (int i = 0; i < 4; i++) { - geometry_data geo = geo_create_cuboid(f32x3(2, 2, 2)); + geometry_data geo = geo_create_cuboid(f32x3(1,1,1)); s_scene[i] = mesh_create(&geo, true); - s_transforms[i] = transform_create(vec3(4 * i, 0, 0), quat_ident(), 1.0); + s_transforms[i] = transform_create(vec3(-2 + (i * 1.2), 0, 0), quat_ident(), 1.0); } geometry_data plane = geo_create_plane(f32x2(20, 20)); s_scene[4] = mesh_create(&plane, true); - geometry_data quad_geo = geo_create_plane(f32x2(2,2)); + geometry_data quad_geo = geo_create_plane(f32x2(2, 2)); mesh quad = mesh_create(&quad_geo, true); shader_data model_data = { .data = NULL, .shader_data_get_layout = &model_uniform_layout }; @@ -61,7 +144,9 @@ int main() { continue; } gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); + gpu_cmd_encoder_begin(*enc); + // Shadow draw gpu_cmd_encoder_begin_render(enc, shadows.rpass); // calculations @@ -79,22 +164,49 @@ int main() { draw_scene(); gpu_cmd_encoder_end_render(enc); + // End + // Debug quad gpu_cmd_encoder_begin_render(enc, shadows.debug_quad->renderpass); + encode_bind_pipeline(enc, PIPELINE_GRAPHICS, shadows.debug_quad); - debug_quad_uniform dqu = {.depthMap = shadows.depth_tex}; - shader_data debug_quad_data = { .data = &dqu, .shader_data_get_layout = debug_quad_layout}; + debug_quad_uniform dqu = { .depthMap = shadows.depth_tex }; + shader_data debug_quad_data = { .data = &dqu, .shader_data_get_layout = debug_quad_layout }; encode_bind_shader_data(enc, 0, &debug_quad_data); encode_set_vertex_buffer(enc, quad.vertex_buffer); encode_set_index_buffer(enc, quad.index_buffer); encode_draw_indexed(enc, quad.geometry->indices->len); gpu_cmd_encoder_end_render(enc); + // End // gpu_cmd_encoder_begin_render(enc, static_opaque_rpass); // gpu_cmd_encoder_end_render(enc); + + /* gpu_cmd_encoder_begin_render(enc, renderpass); */ + /* encode_bind_pipeline(enc, PIPELINE_GRAPHICS, gfx_pipeline); */ + + /* mat4 view, proj; */ + /* camera_view_projection(&cam, 1000, 1000, */ + /* &view, &proj); */ + /* for (int i = 0; i < 4; i++) { */ + /* mat4 model = transform_to_mat(&s_transforms[i]); */ + /* mvp_uniforms mvp_data = { .model = model, .view = view, .projection = proj }; */ + /* my_shader_bind_group shader_bind_data = { .mvp = mvp_data, .tex = texture }; */ + /* mvp_uniforms_data.data = &shader_bind_data; */ + /* encode_bind_shader_data(enc, 0, &mvp_uniforms_data); */ + /* encode_set_vertex_buffer(enc, s_scene[i].vertex_buffer); */ + /* encode_set_index_buffer(enc, s_scene[i].index_buffer); */ + /* encode_draw_indexed(enc, s_scene[i].geometry->indices->len); */ + /* } */ + + /* gpu_cmd_encoder_end_render(enc); */ + + // END drawing + gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc); + gpu_queue_submit(&buf); gpu_backend_end_frame(); } @@ -105,8 +217,9 @@ int main() { void draw_scene() { gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - for (int i = 0; i < 5; i++) { - model_uniform mu = { .model = transform_to_mat(&s_transforms[i]) }; + for (int i = 0; i < 4; i++) { //FIXME: draw plane as well + mat4 model = transform_to_mat(&s_transforms[i]) ; + model_uniform mu = { .model = model}; shader_data model_data = { .data = &mu, .shader_data_get_layout = model_uniform_layout }; encode_bind_shader_data(enc, 0, &model_data); encode_set_vertex_buffer(enc, s_scene[i].vertex_buffer); diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 57e85a2..ce467ab 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -5,6 +5,7 @@ #include "ral_types.h" #include "render_types.h" +// --- Helpers #define VERT_3D(arr, pos, norm, uv) \ { \ vertex v = { .static_3d = { .position = pos, .normal = norm, .tex_coords = uv } }; \ @@ -21,13 +22,8 @@ void push_triangle(u32_darray* arr, u32 i0, u32 i1, u32 i2) { void geo_free_data(geometry_data* geo) { vertex_darray_free(geo->vertices); geo->vertices = NULL; - // TODO: do indices as well - /* if (geo->has_indices) { */ - /* u32_darray_free(&geo->indices); */ - /* } */ } -// vertices vec3 plane_vertex_positions[] = { (vec3){ -0.5, 0, -0.5 }, (vec3){ 0.5, 0, -0.5 }, @@ -50,8 +46,8 @@ geometry_data geo_create_plane(f32x2 extents) { VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1)); VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1, 1)); - push_triangle(indices, 2, 1, 0); - push_triangle(indices, 1, 2, 3); + push_triangle(indices, 0, 1, 2); + push_triangle(indices, 2, 1, 3); geometry_data geo = { .format = VERTEX_STATIC_3D, .vertices = vertices, @@ -62,8 +58,6 @@ geometry_data geo_create_plane(f32x2 extents) { return geo; } -// OLD - static const vec3 BACK_BOT_LEFT = (vec3){ 0, 0, 0 }; static const vec3 BACK_BOT_RIGHT = (vec3){ 1, 0, 0 }; static const vec3 BACK_TOP_LEFT = (vec3){ 0, 1, 0 }; @@ -74,7 +68,6 @@ static const vec3 FRONT_TOP_LEFT = (vec3){ 0, 1, 1 }; static const vec3 FRONT_TOP_RIGHT = (vec3){ 1, 1, 1 }; geometry_data geo_create_cuboid(f32x3 extents) { - /* static mesh prim_cube_mesh_create() { */ vertex_darray* vertices = vertex_darray_new(36); // back faces @@ -142,19 +135,6 @@ geometry_data geo_create_cuboid(f32x3 extents) { return geo; } -/* /\** @brief create a new model with the shape of a cube *\/ */ -/* static model_handle prim_cube_new(core* core) { */ -/* model model = { 0 }; */ -/* mesh cube = prim_cube_mesh_create(); */ - -/* mesh_darray_push(model.meshes, cube); */ -/* assert(mesh_darray_len(model.meshes) == 1); */ - -/* u32 index = (u32)model_darray_len(core->models); */ -/* model_darray_push_copy(core->models, &model); */ -/* return (model_handle){ .raw = index }; */ -/* } */ - // --- Spheres vec3 spherical_to_cartesian_coords(f32 rho, f32 theta, f32 phi) { @@ -252,10 +232,6 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we } } - for (int i = 0; i < vertices->len; i++) { - // print_vec3(vertices->data[i].static_3d.normal); - } - geometry_data geo = { .format = VERTEX_STATIC_3D, .vertices = vertices, diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 7d8aa01..02c27cd 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -70,7 +70,6 @@ void gpu_device_destroy() { /* No-op in OpenGL */ } // --- Render Pipeline gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc description) { - static u32 ubo_count = 0; gpu_pipeline* pipeline = pipeline_pool_alloc(&context.gpu_pools.pipelines, NULL); // Create shader program @@ -81,6 +80,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip pipeline->vertex_desc = description.vertex_desc; // Allocate uniform buffers if needed + u32 ubo_count = 0; // printf("data layouts %d\n", description.data_layouts_count); for (u32 layout_i = 0; layout_i < description.data_layouts_count; layout_i++) { shader_data_layout sdl = description.data_layouts[layout_i].shader_data_get_layout(NULL); @@ -95,11 +95,11 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip buffer_handle ubo_handle = gpu_buffer_create(binding.data.bytes.size, CEL_BUFFER_UNIFORM, CEL_BUFFER_FLAG_GPU, NULL); // no data right now - pipeline->uniform_bindings[binding_id] = ubo_handle; + pipeline->uniform_bindings[ubo_count++] = ubo_handle; gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle); i32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, binding.label); - printf("Block index for Matrices: %d", blockIndex); + printf("Block index for %s: %d", binding.label, blockIndex); if (blockIndex < 0) { WARN("Couldn't retrieve block index for uniform block '%s'", binding.label); } else { @@ -115,10 +115,12 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip glUniformBlockBinding(pipeline->shader_id, blockIndex, s_binding_point); } ubo_buf->ubo_binding_point = s_binding_point++; + ubo_buf->name = binding.label; assert(s_binding_point < GL_MAX_UNIFORM_BUFFER_BINDINGS); } } } + pipeline->uniform_count = ubo_count; pipeline->renderpass = description.renderpass; pipeline->wireframe = description.wireframe; @@ -151,7 +153,7 @@ gpu_renderpass* gpu_renderpass_create(const gpu_renderpass_desc* description) { } if (description->has_depth_stencil) { gpu_texture* depth_attachment = TEXTURE_GET(description->depth_stencil); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_attachment->id, 0); } @@ -178,13 +180,20 @@ gpu_cmd_encoder gpu_cmd_encoder_create() { void gpu_cmd_encoder_destroy(gpu_cmd_encoder* encoder) {} void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder) {} void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) { - // glBindFramebuffer(GL_FRAMEBUFFER, renderpass->fbo); + glViewport(0, 0, 1000, 1000); + glBindFramebuffer(GL_FRAMEBUFFER, renderpass->fbo); rgba clear_colour = STONE_800; - glClearColor(clear_colour.r, clear_colour.g, clear_colour.b, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + /* glClearColor(clear_colour.r, clear_colour.g, clear_colour.b, 1.0f); */ + /* glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); */ + // FIXME: account for both + if (renderpass->description.has_depth_stencil) { + glClear(GL_DEPTH_BUFFER_BIT); + } else { + glClear(GL_COLOR_BUFFER_BIT); + } } void gpu_cmd_encoder_end_render(gpu_cmd_encoder* encoder) { - // glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } void gpu_cmd_encoder_begin_compute() {} gpu_cmd_encoder* gpu_get_default_cmd_encoder() { return &context.command_buffer; } @@ -229,11 +238,24 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d for (u32 i = 0; i < sdl.bindings_count; i++) { shader_binding binding = sdl.bindings[i]; - // print_shader_binding(binding); + print_shader_binding(binding); if (binding.type == SHADER_BINDING_BYTES) { - buffer_handle b = encoder->pipeline->uniform_bindings[i]; - gpu_buffer* ubo_buf = BUFFER_GET(b); + buffer_handle b; + gpu_buffer* ubo_buf; + bool found = false; + for (u32 i = 0; i < encoder->pipeline->uniform_count; i++) { + b = encoder->pipeline->uniform_bindings[i]; + ubo_buf = BUFFER_GET(b); + assert(ubo_buf->name != NULL); + if (strcmp(ubo_buf->name, binding.label) == 0) { + found = true; + break; + } + } + if (!found) { + ERROR("Couldnt find uniform buffer object!!"); + } i32 blockIndex = glGetUniformBlockIndex(encoder->pipeline->shader_id, binding.label); if (blockIndex < 0) { @@ -247,7 +269,10 @@ void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* d } else if (binding.type == SHADER_BINDING_TEXTURE) { gpu_texture* tex = TEXTURE_GET(binding.data.texture.handle); - GLuint tex_slot = glGetUniformLocation(encoder->pipeline->shader_id, binding.label); + GLint tex_slot = glGetUniformLocation(encoder->pipeline->shader_id, binding.label); + if (tex_slot == GL_INVALID_VALUE || tex_slot < 0) { + WARN("Invalid binding label for texture - couldn't fetch texture slot uniform"); + } glUniform1i(tex_slot, i); glActiveTexture(GL_TEXTURE0 + i); glBindTexture(GL_TEXTURE_2D, tex->id); @@ -347,13 +372,19 @@ texture_handle gpu_texture_create(texture_desc desc, bool create_view, const voi GLenum format = desc.format == CEL_TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : GL_RGBA; GLenum data_type = desc.format == CEL_TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_FLOAT : GL_UNSIGNED_BYTE; - // set the texture wrapping parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - // set texture filtering parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + /* // set the texture wrapping parameters */ + /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, */ + /* GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) */ + /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); */ + /* // set texture filtering parameters */ + /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); */ + /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); */ + + // TEMP + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); if (data) { glTexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.extents.x, desc.extents.y, 0, format, @@ -377,7 +408,10 @@ void gpu_texture_upload(texture_handle texture, const void* data) {} bytebuffer vertices_as_bytebuffer(arena* a, vertex_format format, vertex_darray* vertices) {} // --- TEMP -bool gpu_backend_begin_frame() { return true; } +bool gpu_backend_begin_frame() { + glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + return true; } void gpu_backend_end_frame() { // TODO: Reset all bindings glfwSwapBuffers(context.window); diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h index a5a9140..8b88cf8 100644 --- a/src/renderer/backends/opengl/backend_opengl.h +++ b/src/renderer/backends/opengl/backend_opengl.h @@ -24,12 +24,12 @@ typedef struct gpu_pipeline { gpu_renderpass* renderpass; vertex_description vertex_desc; buffer_handle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS]; + u32 uniform_count; bool wireframe; } gpu_pipeline; typedef struct gpu_renderpass { u32 fbo; gpu_renderpass_desc description; - void *pad; } gpu_renderpass; typedef struct gpu_cmd_encoder { gpu_pipeline *pipeline; @@ -48,6 +48,7 @@ typedef struct gpu_buffer { u32 vao; u32 ubo_binding_point }; // Optional + char* name; u64 size; } gpu_buffer; typedef struct gpu_texture { diff --git a/src/renderer/ral.c b/src/renderer/ral.c index a52d605..9ca99ce 100644 --- a/src/renderer/ral.c +++ b/src/renderer/ral.c @@ -1,8 +1,8 @@ #include "ral.h" #include "file.h" #include "log.h" -#include "str.h" #include "mem.h" +#include "str.h" #if defined(CEL_REND_BACKEND_VULKAN) #include "backend_vulkan.h" @@ -88,10 +88,10 @@ shader_desc shader_quick_load(const char* filepath) { ERROR_EXIT("Failed to load shaders from disk"); } - return (shader_desc) { + return (shader_desc){ .debug_name = filepath, .code = shader.contents, .filepath = path, .is_spirv = true, }; -}
\ No newline at end of file +} diff --git a/src/renderer/ral.h b/src/renderer/ral.h index 9d6ed41..b76de27 100644 --- a/src/renderer/ral.h +++ b/src/renderer/ral.h @@ -77,6 +77,8 @@ typedef struct shader_desc { } shader_desc; shader_desc shader_quick_load(const char* filepath); +/** @brief Hot reloads shaders for the given pipeline. Returns how long it took in milliseconds */ +u64 gpu_pipeline_reload_shaders(gpu_pipeline* pipeline); // TODO struct graphics_pipeline_desc { const char* debug_name; diff --git a/src/renderer/render.c b/src/renderer/render.c index f52e2be..1c98b0b 100644 --- a/src/renderer/render.c +++ b/src/renderer/render.c @@ -62,7 +62,7 @@ bool renderer_init(renderer* ren) { resource_pools_init(&pool_arena, ren->resource_pools); // Create default rendering pipeline - default_pipelines_init(ren); + /* default_pipelines_init(ren); */ return true; } diff --git a/src/renderer/renderpasses.c b/src/renderer/renderpasses.c index 5193a1c..b93d487 100644 --- a/src/renderer/renderpasses.c +++ b/src/renderer/renderpasses.c @@ -25,26 +25,26 @@ shader_data_layout debug_quad_layout(void* data) { shader_binding b1 = { .label = "depthMap", .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data}; + .stores_data = has_data }; if (has_data) { b1.data.texture.handle = d->depthMap; } - return (shader_data_layout){ .name = "debug quad uniforms", .bindings = { b1 }, .bindings_count = 1 }; + return ( + shader_data_layout){ .name = "debug quad uniforms", .bindings = { b1 }, .bindings_count = 1 }; } gpu_pipeline* debug_quad_pipeline_create() { - gpu_renderpass_desc rpass_desc = {.default_framebuffer = true }; + gpu_renderpass_desc rpass_desc = { .default_framebuffer = true }; gpu_renderpass* rpass = gpu_renderpass_create(&rpass_desc); - shader_data shader_layout = {.data = NULL, .shader_data_get_layout = debug_quad_layout}; - struct graphics_pipeline_desc desc = { - .debug_name = "Shadow maps debug quad", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { shader_layout }, - .data_layouts_count = 1, - .vs = shader_quick_load("assets/shaders/debug_quad.vert"), - .fs = shader_quick_load("assets/shaders/debug_quad.frag"), - .renderpass = rpass, - }; + shader_data shader_layout = { .data = NULL, .shader_data_get_layout = debug_quad_layout }; + struct graphics_pipeline_desc desc = { .debug_name = "Shadow maps debug quad", + .vertex_desc = static_3d_vertex_description(), + .data_layouts = { shader_layout }, + .data_layouts_count = 1, + .vs = shader_quick_load("assets/shaders/debug_quad.vert"), + .fs = shader_quick_load("assets/shaders/debug_quad.frag"), + .renderpass = rpass, + .wireframe = false }; return gpu_graphics_pipeline_create(desc); } @@ -137,4 +137,4 @@ gpu_pipeline* shadowmaps_pipeline_create(gpu_renderpass* rpass) { } void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, - size_t entity_count) {}
\ No newline at end of file + size_t entity_count) {} |