diff options
| author | onelin <oscar@nelin.dk> | 2025-11-26 20:22:27 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2025-11-26 21:45:06 +0000 |
| commit | ce51f1634af7ec5a7710d59b82716fda72607ca8 (patch) | |
| tree | f36629accd5fc47980f81a0575ba3be8c6db7564 /src/window.c | |
| parent | 51587ec974d532b68bb323a14d18f857ed357d74 (diff) | |
Add render pipeline customization
Diffstat (limited to 'src/window.c')
| -rw-r--r-- | src/window.c | 121 |
1 files changed, 116 insertions, 5 deletions
diff --git a/src/window.c b/src/window.c index fc688b7..9702a7f 100644 --- a/src/window.c +++ b/src/window.c @@ -10,8 +10,6 @@ #include <daw/window.h> #undef ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS -#include <glad/gl.h> - #undef GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> @@ -50,14 +48,13 @@ Window* Window_new(const struct Platform* p, const char *restrict title, Window_ * out of struct Instance */ w = p->window_init(title, size, flags); + // Manually reset bindings et. al. w->bindings = NULL; w->bindings_sz = 0; w->bindings_len = 0; - /// TODO - //w->cam = &default_camera; + w->render_targets = NULL; return w; - break; default: ERROR("Unsupported renderer."); } @@ -68,6 +65,38 @@ Window* Window_new(const struct Platform* p, const char *restrict title, Window_ return NULL; } + +void window_reset_cameras(Window* w, RenderTargets* restrict targets) { + // Question, would it be better to check both callbacks and continue early, + // instead of resizing the texture first, then check the camera callback? + for (usize i = 0; i < targets->framebuffer_len; i++) { + //if (targets->framebuffer_size_callback[i] == NULL) continue; + + //ivec2 newsz; + //targets->framebuffer_size_callback[i](&newsz, w->windowsize); + + // Destroy & Create framebuffers (and related buffers?) + + if (targets->camera_reset_callback[i] == NULL) continue; + (*targets->camera_reset_callback)(&targets->cam[i], w->windowsize); + } +} + +//void window_reset_texture_sizes(Window* w, RenderTargets* restrict targets) { +// // Question, would it be more efficient to just wipe all of them at once +// // instead of doing this? Not all are necessarily deleted. +// for (usize i = 0; i < targets->texture_len; i++) { +// if (targets->framebuffer_size_callback[i] == NULL) continue; +// +// ivec2 newsz; +// targets->framebuffer_size_callback[i](&newsz, w->windowsize); +// +// r_destroy_framebuffers(w->context, targets->framebuffer, 1); +// r_create_framebuffers(w->context, &targets->framebuffer[i], &targets->framebuffer_parameters[i].framebuffer_type, &newsz, 1); +// } +//} + + void get_mousepos(double *x, double *y) { Window* w = GLOBAL_PLATFORM->window; @@ -84,3 +113,85 @@ void get_mousepos(double *x, double *y) { void window_get_size(ivec2* dst) { glm_ivec2_copy(GLOBAL_PLATFORM->window->windowsize, *dst); } + + +// Assume framebuffer_len and texture_len is already set +void window_init_renderstack(Window *restrict w, + usize num_fbuf, usize num_buf, + FramebufferParameters *restrict fb_params, + u32 *restrict buffer_params + ) { + + ASSERT(w != NULL); + ASSERT(fb_params != NULL); + ASSERT(buffer_params != NULL); + + RenderTargets *t = NULL; + void* allocation = malloc( + sizeof(RenderTargets) + + sizeof(*t->framebuffer) * num_fbuf + + sizeof(*t->buffer) * num_buf + + sizeof(*t->framebuffer_parameters) * num_fbuf + + sizeof(*t->buffer_parameters) * num_buf + + sizeof(*t->cam) * num_fbuf + // TODO: callbacks + ); + +#define ADVANCE_PTR(target, count)\ + t->target = (void*)((u64)allocation + acc); \ + acc += sizeof(*t->target) * count + + t = allocation; + + t->framebuffer_len = num_fbuf; + t->buffer_len = num_buf; + + u64 acc = sizeof(RenderTargets); + ADVANCE_PTR(framebuffer, num_fbuf); + ADVANCE_PTR(buffer, num_buf); + ADVANCE_PTR(framebuffer_parameters, num_fbuf); + ADVANCE_PTR(buffer_parameters, num_buf); + ADVANCE_PTR(cam, num_fbuf); + // TODO: callbacks +#undef ADVANCE_PTR + + memcpy(t->framebuffer_parameters, fb_params, sizeof(*t->framebuffer_parameters) * num_fbuf); + memcpy(t->buffer_parameters, buffer_params, sizeof(*t->buffer_parameters) * num_buf); + + // Iteratively set up each framebuffer and framebuffer-attached objects + usize buffer_offset = 0; + for (usize fb_idx = 0; fb_idx < num_fbuf; fb_idx++) { + FramebufferParameters *p = &t->framebuffer_parameters[fb_idx]; + // Check everything is a texture, cuz rn. we don't support anything else + for (isize buffer_idx = 0; buffer_idx < p->num_attached_buffers; buffer_idx++) { + ASSERT(BUFFERPARAMETER_GET_TYPE(t->buffer_parameters[buffer_idx + buffer_offset]) == BufferType_texture); + } + r_create_textures(w->context, &t->buffer[buffer_offset], + &t->buffer_parameters[buffer_offset], + &t->framebuffer_parameters[fb_idx].dimensions, + t->framebuffer_parameters[fb_idx].num_attached_buffers); + //if (BUFFERPARAMETER_GET_TYPE(buffer_params[i]) != BufferType_texture) continue; + //u32 texture_type = BUFFERPARAMETER_GET_PARAMETER(buffer_params[i]); + + //usize span = 0; + //while ( + // (i + span < targets->buffer_len) && + // (BUFFERPARAMETER_GET_TYPE(buffer_params[i + span]) == BufferType_texture) && + // (buffer_params[i + span].buffer_param & 3) == textureType + //) { + // span++; + //} + //if (span == 0) continue; + //r_create_textures(w->context, &targets->buffer[i], texture_type, texturesizes, span); + } + //r_create_renderbuffers(c, targets->renderbuffer, renderbuffertypes, renderbuffersizes, targets->renderbuffer_len); + // Skip `texture` (??) + + w->render_targets = t; +} + + +void window_free_renderstack(RenderTargets *restrict t) { + // Everything is in the same buffer anyways + free(t->framebuffer); +} |
