summaryrefslogtreecommitdiff
path: root/src/rendering.c
diff options
context:
space:
mode:
authoronelin <oscar@nelin.dk>2025-11-26 20:22:27 +0000
committeronelin <oscar@nelin.dk>2025-11-26 21:45:06 +0000
commitce51f1634af7ec5a7710d59b82716fda72607ca8 (patch)
treef36629accd5fc47980f81a0575ba3be8c6db7564 /src/rendering.c
parent51587ec974d532b68bb323a14d18f857ed357d74 (diff)
Add render pipeline customization
Diffstat (limited to 'src/rendering.c')
-rw-r--r--src/rendering.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/rendering.c b/src/rendering.c
index 25ee1fd..76df988 100644
--- a/src/rendering.c
+++ b/src/rendering.c
@@ -551,9 +551,8 @@ void window_reset_drawing(void) {
memset(drawcalls, 0, sizeof(RenderDrawCall) * drawcall_limit);
}
-void r_perspective(f32 fov, Camera *c) {
- const f32 ratio = (f32)GLOBAL_PLATFORM->window->windowsize[0]
- / (f32)GLOBAL_PLATFORM->window->windowsize[1];
+void r_perspective(Camera *c, f32 fov, ivec2 windowsize) {
+ const f32 ratio = (f32)windowsize[0] / (f32)windowsize[1];
c->type = Camera_Perspective;
c->parameters.perspective.fov = fov;
@@ -561,9 +560,8 @@ void r_perspective(f32 fov, Camera *c) {
glm_perspective(glm_rad(fov), ratio, 0.1f, 100.0f, c->per);
}
-void r_perspective_ortho(f32 sz, Camera *c) {
- const f32 ratio = (f32)GLOBAL_PLATFORM->window->windowsize[0]
- / (f32)GLOBAL_PLATFORM->window->windowsize[1];
+void r_perspective_ortho(Camera *c, f32 sz, ivec2 windowsize) {
+ const f32 ratio = (f32)windowsize[0] / (f32)windowsize[1];
c->type = Camera_Orthogonal;
c->parameters.orthogonal.sz = sz;
@@ -576,24 +574,24 @@ void r_set_camera(Camera* c) {
}
-void r_reset_camera(Camera* c) {
+void r_reset_camera(Camera* c, ivec2 windowsize) {
if (c->type == Camera_Perspective) {
- r_perspective(c->parameters.perspective.fov, c);
+ r_perspective(c, c->parameters.perspective.fov, windowsize);
}
else if (c->type == Camera_Orthogonal) {
- r_perspective_ortho(c->parameters.orthogonal.sz, c);
+ r_perspective_ortho(c, c->parameters.orthogonal.sz, windowsize);
}
}
-void engine_draw_model(RenderObject* o, vec3 pos) {
+void engine_draw_model(RenderObject* o, vec4 pos) {
if (drawcall_len + 1 >= drawcall_limit) return;
#ifdef _DEBUG
if (o == NULL) __asm__("int3;");
#endif
RenderDrawCall dc = {
.model = o,
- .scale = 1.f,
+ .scale = pos[3],
};
glm_vec3_copy(pos, dc.pos);
@@ -669,3 +667,46 @@ Texture createTextureFromImageData(unsigned char* image_data, i32 width, i32 hei
return t;
}
+
+void r_init_renderstack(
+ usize num_fbuf, usize num_buf,
+ FramebufferParameters *restrict fb_params,
+ u32 *restrict buffer_params
+ ) {
+ window_init_renderstack(GLOBAL_PLATFORM->window, num_fbuf, num_buf, fb_params, buffer_params);
+}
+
+void r_create_framebuffers(void* restrict ctx, u32* restrict framebuffer_array,
+ usize num_targets) {
+ const GladGLContext* gl = (GladGLContext*)ctx;
+
+ gl->CreateFramebuffers(num_targets, framebuffer_array);
+}
+
+void r_destroy_framebuffers(void* restrict ctx, u32* restrict framebuffer_array,
+ usize num_targets) {
+ const GladGLContext* gl = (GladGLContext*)ctx;
+
+ gl->DeleteFramebuffers(num_targets, framebuffer_array);
+}
+
+void r_create_textures(void* restrict ctx, u32* restrict texture_array,
+ u32* restrict texture_types,
+ ivec4* restrict texture_size, usize num_targets) {
+ const GladGLContext* gl = (GladGLContext*)ctx;
+
+ gl->CreateTextures(GL_TEXTURE_2D, num_targets, texture_array);
+
+ for (usize i = 0; i < num_targets; i++) {
+ ASSERT("SWITCH CASE ON BUFFER DIMENSIONALITY");
+ ASSERT("SWITCH CASE ON TEXTURE DATA TYPE");
+ gl->TextureStorage2D(texture_array[i], 1, texture_types[i], *texture_size[0], *texture_size[1]);
+ gl->TextureParameteri(texture_array[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ gl->TextureParameteri(texture_array[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ }
+}
+
+void r_destroy_textures(void *restrict ctx, u32* textures, usize num_textures) {
+ const GladGLContext* gl = (GladGLContext*)ctx;
+ gl->DeleteTextures(num_textures, textures);
+}