generalization of deferred commands and any_gl rendering where appropriate

This commit is contained in:
veclavtalica
2025-01-03 21:01:26 +03:00
parent edcb7fc39c
commit 33471b4c46
8 changed files with 347 additions and 321 deletions

View File

@ -4,6 +4,7 @@
#include "twn_camera_c.h"
#include "twn_types.h"
#include "twn_vec.h"
#include "twn_deferred_commands.h"
#include <SDL2/SDL.h>
#include <stb_ds.h>
@ -18,6 +19,8 @@
#include <tgmath.h>
DeferredCommand *deferred_commands;
/* TODO: have a default initialized one */
Matrix4 camera_projection_matrix;
Matrix4 camera_look_at_matrix;
@ -401,3 +404,125 @@ DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 position,
.up = camera.up,
};
}
void set_depth_range(double low, double high) {
DeferredCommand const command = {
.type = DEFERRED_COMMAND_TYPE_DEPTH_RANGE,
.depth_range = {
.low = low,
.high = high
}
};
arrpush(deferred_commands, command);
}
void clear_draw_buffer(void) {
/* TODO: we can optimize a rectangle drawn over whole window to a clear color call*/
DeferredCommand command = {
.type = DEFERRED_COMMAND_TYPE_CLEAR,
.clear = (DeferredCommandClear) {
.clear_color = true,
.clear_depth = true,
.clear_stencil = true,
.color = (Color) { 230, 230, 230, 1 }
}
};
arrpush(deferred_commands, command);
}
void use_texture_mode(TextureMode mode) {
DeferredCommand const command = {
.type = DEFERRED_COMMAND_TYPE_USE_TEXTURE_MODE,
.use_texture_mode = { mode }
};
arrpush(deferred_commands, command);
}
void use_2d_pipeline(void) {
DeferredCommand const command = {
.type = DEFERRED_COMMAND_TYPE_USE_PIPIELINE,
.use_pipeline = { PIPELINE_2D }
};
arrpush(deferred_commands, command);
}
void use_space_pipeline(void) {
DeferredCommand const command = {
.type = DEFERRED_COMMAND_TYPE_USE_PIPIELINE,
.use_pipeline = { PIPELINE_SPACE }
};
arrpush(deferred_commands, command);
}
void issue_deferred_draw_commands(void) {
for (size_t i = 0; i < arrlenu(deferred_commands); ++i) {
switch (deferred_commands[i].type) {
case DEFERRED_COMMAND_TYPE_DEPTH_RANGE: {
finally_set_depth_range(deferred_commands[i].depth_range);
break;
}
case DEFERRED_COMMAND_TYPE_CLEAR: {
finally_clear_draw_buffer(deferred_commands[i].clear);
break;
}
case DEFERRED_COMMAND_TYPE_DRAW: {
finally_draw_command(deferred_commands[i].draw);
break;
}
case DEFERRED_COMMAND_TYPE_DRAW_SKYBOX: {
finally_render_skybox(deferred_commands[i].draw_skybox);
break;
}
case DEFERRED_COMMAND_TYPE_USE_PIPIELINE: {
switch (deferred_commands[i].use_pipeline.pipeline) {
case PIPELINE_2D:
finally_use_2d_pipeline();
break;
case PIPELINE_SPACE:
finally_use_space_pipeline();
break;
case PIPELINE_NO:
default:
SDL_assert(false);
}
break;
}
case DEFERRED_COMMAND_TYPE_USE_TEXTURE_MODE: {
finally_use_texture_mode(deferred_commands[i].use_texture_mode.mode);
break;
}
case DEFERRED_COMMAND_TYPE_APPLY_FOG: {
finally_apply_fog(deferred_commands[i].apply_fog);
break;
}
case DEFERRED_COMMAND_TYPE_POP_FOG: {
finally_pop_fog();
break;
}
default:
SDL_assert(false);
}
}
}