diff options
| -rw-r--r-- | assets/base.vs | 26 | ||||
| -rw-r--r-- | assets/grayscale.fs | 16 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/shader_sys.c | 24 | ||||
| -rw-r--r-- | src/shader_sys.h | 2 |
5 files changed, 28 insertions, 42 deletions
diff --git a/assets/base.vs b/assets/base.vs deleted file mode 100644 index 8cc2abb..0000000 --- a/assets/base.vs +++ /dev/null @@ -1,26 +0,0 @@ -#version 330 - -// Input vertex attributes -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; -in vec4 vertexColor; - -// Input uniform values -uniform mat4 mvp; - -// Output vertex attributes (to fragment shader) -out vec2 fragTexCoord; -out vec4 fragColor; - -// NOTE: Add here your custom variables - -void main() -{ - // Send vertex attributes to fragment shader - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - - // Calculate final vertex position - gl_Position = mvp*vec4(vertexPosition, 1.0); -}
\ No newline at end of file diff --git a/assets/grayscale.fs b/assets/grayscale.fs deleted file mode 100644 index 979a81c..0000000 --- a/assets/grayscale.fs +++ /dev/null @@ -1,16 +0,0 @@ -#version 330 - -in vec2 fragTexCoord; -in vec4 fragColor; - -uniform sampler2D texture0; -uniform vec4 colDiffuse; - -out vec4 finalColor; - -void main() -{ - vec4 texelColor = texture(texture0, fragTexCoord) * colDiffuse * fragColor; - float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); - finalColor = vec4(gray, gray, gray, texelColor.a); -}
\ No newline at end of file @@ -18,6 +18,8 @@ int main() while(!WindowShouldClose()){ update_textures(); + update_shaders(); + ClearBackground(WHITE); BeginDrawing(); DrawText("Wow, boilerplate, my favorite.", 4, 4, 20, BLACK); 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) diff --git a/src/shader_sys.h b/src/shader_sys.h index 114e53d..3df03c2 100644 --- a/src/shader_sys.h +++ b/src/shader_sys.h @@ -6,6 +6,8 @@ int load_new_shader(const char* path); void set_active_shader(int idx); +void update_shaders(void); + void reset_active_shader(void); void unload_shader(int idx); |
