aboutsummaryrefslogtreecommitdiff
path: root/src/shader_sys.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-07-19 17:59:06 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-07-19 17:59:06 -0300
commit1f291678048efe0c117909ae7e2d2ec706377a23 (patch)
treef6488be8d64e502a1bfcbd9b6eecca47198927f4 /src/shader_sys.c
parent13b721b4db38b310bc644ce2922687fda1433ab1 (diff)
Shader reloading implemented
Diffstat (limited to 'src/shader_sys.c')
-rw-r--r--src/shader_sys.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shader_sys.c b/src/shader_sys.c
index cd8de3e..180bdef 100644
--- a/src/shader_sys.c
+++ b/src/shader_sys.c
@@ -81,11 +81,15 @@ vertex_err:
}
static Shader shader_slots[MAX_SHADER_SIZE] = {0};
+static long shader_modtimes[MAX_SHADER_SIZE] = {0};
+static const char* shader_paths[MAX_SHADER_SIZE] = {0};
void init_shader_sys(void)
{
for(int i = 0; i < MAX_SHADER_SIZE; ++i){
shader_slots[i] = (Shader){0};
+ shader_modtimes[i] = BLANK_DEFAULT;
+ shader_paths[i] = NULL;
}
}
@@ -96,6 +100,8 @@ int load_new_shader(const char* path)
if(shader_slots[i].id <= 0){
current_idx = i;
shader_slots[current_idx] = load_joined_shader(path);
+ shader_modtimes[current_idx] = GetFileModTime(path);
+ shader_paths[current_idx] = path;
break;
}
}
@@ -114,6 +120,22 @@ void set_active_shader(int idx)
BeginShaderMode(shader_slots[idx]);
}
+void update_shaders(void)
+{
+ for(int i = 0; i < MAX_SHADER_SIZE; ++i){
+ if(shader_slots[i].id > 0){
+ long current_mod = GetFileModTime(shader_paths[i]);
+
+ if(current_mod != shader_modtimes[i]){
+ shader_modtimes[i] = current_mod;
+
+ UnloadShader(shader_slots[i]);
+ shader_slots[i] = load_joined_shader(shader_paths[i]);
+ }
+ }
+ }
+}
+
void reset_active_shader(void)
{
EndShaderMode();
@@ -128,6 +150,8 @@ void unload_shader(int idx)
UnloadShader(shader_slots[idx]);
shader_slots[idx] = (Shader){0};
+ shader_modtimes[idx] = BLANK_DEFAULT;
+ shader_paths[idx] = NULL;
}
void unload_active_shaders(void)