$darkmode
#include "shader.h"#include "app_settings.h"#include "glad/glad.h"#include "io.h"#include "log.h"#include "utils.h"#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Data Structures | |
| struct | LoadedBuffer |
| struct | Chunk |
| struct | IncludeContext |
Macros | |
| #define | CLEANUP_CTX __attribute__((cleanup(ctx_free))) |
Enumerations | |
| enum | { INFO_LOG_SIZE = 512 } |
| enum | { MAX_SHADER_NAME_LEN = 256 } |
| enum | { SHADER_LABEL_BUFFER_SIZE = 512 } |
| enum | { MAX_INCLUDE_DEPTH = 16 } |
| enum | { MAX_SHADER_SOURCE_SIZE = 16 * 1024 * 1024 } |
| enum | { PATH_BUFFER_SIZE = 256 } |
| enum | { RESOLVED_PATH_BUFFER_SIZE = 512 } |
| enum | { HEADER_TAG_LEN = 7 } |
| enum | { MAX_DEFINES = 32 } |
Functions | |
| static bool | process_source (IncludeContext *ctx, const char *current_file_src, const char *current_file_path) |
| static void | ctx_add_buffer (IncludeContext *ctx, char *data) |
| static bool | ctx_add_chunk (IncludeContext *ctx, const char *ptr, size_t len) |
| static void | ctx_free (IncludeContext *ctx) |
| static bool | get_dir_from_path (const char *path, char *out_dir, size_t size) |
| static bool | resolve_and_parse_include (IncludeContext *ctx, const char *path_term, const char *current_file_path) |
| static const char * | parse_include_path (const char *args, char *out_path, size_t size) |
| static char * | inject_defines_into_source (const char *buffer, size_t file_size, const char **defines, int count) |
| char * | shader_read_file_with_defines (const char *path, const char **defines, int count) |
| Reads a shader file and injects defines. More... | |
| char * | shader_read_file (const char *path) |
| Reads a shader file into RAM, processing all includes. More... | |
| static GLuint | shader_compile_with_defines (const char *path, GLenum type, const char **defines, int count) |
| GLuint | shader_compile (const char *path, GLenum type) |
| Compiles a single shader stage from a file. More... | |
| static GLuint | shader_load_program_with_defines (const char *vertex_path, const char *fragment_path, const char **defines, int count) |
| GLuint | shader_load_program (const char *vertex_path, const char *fragment_path) |
| Helper to load a classic Vertex+Fragment program from disk. More... | |
| GLuint | shader_load_compute (const char *compute_path) |
| Helper to load a compute program from disk. More... | |
| static int | cmp_uniform_entry (const void *lhs, const void *rhs) |
| static void | shader_cache_uniforms (Shader *shader) |
| static Shader * | shader_create_from_program (GLuint program, const char *name) |
| Shader * | shader_load (const char *vertex_path, const char *fragment_path) |
| Loads a linked program and caches all its active uniforms. More... | |
| Shader * | shader_load_with_defines (const char *vertex_path, const char *fragment_path, const char **defines, int count) |
Special loader that injects #define directives before compilation. More... | |
| Shader * | shader_load_compute_program (const char *compute_path) |
| Loads a compute program and caches its uniforms. More... | |
| void | shader_destroy (Shader *shader) |
| Destroys the shader wrapper and deletes the GL program. More... | |
| void | shader_use (Shader *shader) |
Activates the program for subsequent draw calls (glUseProgram). More... | |
| GLint | shader_get_uniform_location (Shader *shader, const char *name) |
| Retrieves a uniform location via binary search on the cache. More... | |
| void | shader_set_int (Shader *shader, const char *name, int val) |
| void | shader_set_float (Shader *shader, const char *name, float val) |
| void | shader_set_vec2 (Shader *shader, const char *name, const float *val) |
| void | shader_set_vec3 (Shader *shader, const char *name, const float *val) |
| void | shader_set_vec4 (Shader *shader, const char *name, const float *val) |
| void | shader_set_mat4 (Shader *shader, const char *name, const float *val) |
| void | shader_set_int_loc (GLint loc, int val) |
| void | shader_set_float_loc (GLint loc, float val) |
| void | shader_set_vec2_loc (GLint loc, const float *val) |
| void | shader_set_vec3_loc (GLint loc, const float *val) |
| void | shader_set_vec4_loc (GLint loc, const float *val) |
| void | shader_set_mat4_loc (GLint loc, const float *val) |
| #define CLEANUP_CTX __attribute__((cleanup(ctx_free))) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| GLuint shader_compile | ( | const char * | path, |
| GLenum | type | ||
| ) |
Compiles a single shader stage from a file.
Supports recursive @header inclusion syntax.
| path | Path to the shader source file. |
| type | GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, or GL_COMPUTE_SHADER. |
|
static |
|
static |
| void shader_destroy | ( | Shader * | shader | ) |
Destroys the shader wrapper and deletes the GL program.
| shader | Pointer to the object to free. |
| GLint shader_get_uniform_location | ( | Shader * | shader, |
| const char * | name | ||
| ) |
Retrieves a uniform location via binary search on the cache.
| shader | Pointer to the wrapper. |
| name | Uniform identifier. |
| Shader* shader_load | ( | const char * | vertex_path, |
| const char * | fragment_path | ||
| ) |
Loads a linked program and caches all its active uniforms.
| vertex_path | Path to vertex source. |
| fragment_path | Path to fragment source. |
| GLuint shader_load_compute | ( | const char * | compute_path | ) |
Helper to load a compute program from disk.
| Shader* shader_load_compute_program | ( | const char * | compute_path | ) |
Loads a compute program and caches its uniforms.
| compute_path | Path to compute source. |
| GLuint shader_load_program | ( | const char * | vertex_path, |
| const char * | fragment_path | ||
| ) |
Helper to load a classic Vertex+Fragment program from disk.
|
static |
| Shader* shader_load_with_defines | ( | const char * | vertex_path, |
| const char * | fragment_path, | ||
| const char ** | defines, | ||
| int | count | ||
| ) |
Special loader that injects #define directives before compilation.
| vertex_path | Vertex source. |
| fragment_path | Fragment source. |
| defines | Array of macro strings (e.g. "BLOOM_ENABLED"). |
| count | Number of macros. |
| char* shader_read_file | ( | const char * | path | ) |
Reads a shader file into RAM, processing all includes.
| path | Absolute or relative path. |
| char* shader_read_file_with_defines | ( | const char * | path, |
| const char ** | defines, | ||
| int | count | ||
| ) |
Reads a shader file and injects defines.
| path | Path to source. |
| defines | Array of macro strings. |
| count | Number of macros. |
| void shader_set_float | ( | Shader * | shader, |
| const char * | name, | ||
| float | val | ||
| ) |
| void shader_set_float_loc | ( | GLint | loc, |
| float | val | ||
| ) |
| void shader_set_int | ( | Shader * | shader, |
| const char * | name, | ||
| int | val | ||
| ) |
| void shader_set_int_loc | ( | GLint | loc, |
| int | val | ||
| ) |
| void shader_set_mat4 | ( | Shader * | shader, |
| const char * | name, | ||
| const float * | val | ||
| ) |
| void shader_set_mat4_loc | ( | GLint | loc, |
| const float * | val | ||
| ) |
| void shader_set_vec2 | ( | Shader * | shader, |
| const char * | name, | ||
| const float * | val | ||
| ) |
| void shader_set_vec2_loc | ( | GLint | loc, |
| const float * | val | ||
| ) |
| void shader_set_vec3 | ( | Shader * | shader, |
| const char * | name, | ||
| const float * | val | ||
| ) |
| void shader_set_vec3_loc | ( | GLint | loc, |
| const float * | val | ||
| ) |
| void shader_set_vec4 | ( | Shader * | shader, |
| const char * | name, | ||
| const float * | val | ||
| ) |
| void shader_set_vec4_loc | ( | GLint | loc, |
| const float * | val | ||
| ) |
| void shader_use | ( | Shader * | shader | ) |
Activates the program for subsequent draw calls (glUseProgram).
| shader | Pointer to the wrapper. |