Kohi Game Engine
|
The material system is responsible for managing materials in the engine, including reference counting and auto-unloading. More...
Go to the source code of this file.
Data Structures | |
struct | material_system_config |
The configuration for the material system. More... | |
Macros | |
#define | DEFAULT_MATERIAL_NAME "default" |
The name of the default material. More... | |
#define | DEFAULT_UI_MATERIAL_NAME "default_ui" |
The name of the default UI material. More... | |
#define | DEFAULT_TERRAIN_MATERIAL_NAME "default_terrain" |
The name of the default terrain material. More... | |
Typedefs | |
typedef struct material_system_config | material_system_config |
The configuration for the material system. More... | |
Functions | |
b8 | material_system_initialize (u64 *memory_requirement, void *state, void *config) |
Initializes the material system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system. More... | |
void | material_system_shutdown (void *state) |
Shuts down the material system. More... | |
KAPI material * | material_system_acquire (const char *name) |
Attempts to acquire a material with the given name. If it has not yet been loaded, this triggers it to load. If the material is not found, a pointer to the default material is returned. If the material is found and loaded, its reference counter is incremented. More... | |
KAPI material * | material_system_acquire_terrain_material (const char *material_name, u32 material_count, const char **material_names, b8 auto_release) |
Attempts to acquire a terrain material with the given name. If it has not yet been loaded, this triggers it to be loaded from using the provided standard material names. If the material is not able to be loaded, a pointer to the default terrain material is returned. If the material is found and loaded, its reference counter is incremented. More... | |
KAPI material * | material_system_acquire_from_config (material_config *config) |
Attempts to acquire a material from the given configuration. If it has not yet been loaded, this triggers it to load. If the material is not found, a pointer to the default material is returned. If the material is found and loaded, its reference counter is incremented. More... | |
KAPI void | material_system_release (const char *name) |
Releases a material with the given name. Ignores non-existant materials. Decreases the reference counter by 1. If the reference counter reaches 0 and auto_release was set to true, the material is unloaded, releasing internal resources. More... | |
KAPI material * | material_system_get_default (void) |
Gets a pointer to the default material. Does not reference count. More... | |
KAPI material * | material_system_get_default_ui (void) |
Gets a pointer to the default UI material. Does not reference count. More... | |
KAPI material * | material_system_get_default_terrain (void) |
Gets a pointer to the default terrain material. Does not reference count. More... | |
KAPI b8 | material_system_apply_global (u32 shader_id, const struct frame_data *p_frame_data, const mat4 *projection, const mat4 *view, const vec4 *ambient_colour, const vec3 *view_position, u32 render_mode) |
Applies global-level data for the material shader id. More... | |
KAPI b8 | material_system_apply_instance (material *m, struct frame_data *p_frame_data, b8 needs_update) |
Applies instance-level material data for the given material. More... | |
KAPI b8 | material_system_apply_local (material *m, const mat4 *model) |
Applies local-level material data (typically just model matrix). More... | |
KAPI void | material_system_dump (void) |
Dumps all of the registered materials and their reference counts/handles. More... | |
The material system is responsible for managing materials in the engine, including reference counting and auto-unloading.
#define DEFAULT_MATERIAL_NAME "default" |
The name of the default material.
#define DEFAULT_TERRAIN_MATERIAL_NAME "default_terrain" |
The name of the default terrain material.
#define DEFAULT_UI_MATERIAL_NAME "default_ui" |
The name of the default UI material.
typedef struct material_system_config material_system_config |
The configuration for the material system.
Attempts to acquire a material with the given name. If it has not yet been loaded, this triggers it to load. If the material is not found, a pointer to the default material is returned. If the material is found and loaded, its reference counter is incremented.
name | The name of the material to find. |
KAPI material* material_system_acquire_from_config | ( | material_config * | config | ) |
Attempts to acquire a material from the given configuration. If it has not yet been loaded, this triggers it to load. If the material is not found, a pointer to the default material is returned. If the material is found and loaded, its reference counter is incremented.
config | The config of the material to load. |
KAPI material* material_system_acquire_terrain_material | ( | const char * | material_name, |
u32 | material_count, | ||
const char ** | material_names, | ||
b8 | auto_release | ||
) |
Attempts to acquire a terrain material with the given name. If it has not yet been loaded, this triggers it to be loaded from using the provided standard material names. If the material is not able to be loaded, a pointer to the default terrain material is returned. If the material is found and loaded, its reference counter is incremented.
name | The name of the terrain material to find. |
material_count | The number of standard source material names. |
material_names | The names of the source materials to be used. |
KAPI b8 material_system_apply_global | ( | u32 | shader_id, |
const struct frame_data * | p_frame_data, | ||
const mat4 * | projection, | ||
const mat4 * | view, | ||
const vec4 * | ambient_colour, | ||
const vec3 * | view_position, | ||
u32 | render_mode | ||
) |
Applies global-level data for the material shader id.
shader_id | The identifier of the shader to apply globals for. |
p_frame_data | A constant pointer to the current frame's data. |
projection | A constant pointer to a projection matrix. |
view | A constant pointer to a view matrix. |
ambient_colour | The ambient colour of the scene. |
view_position | The camera position. |
render_mode | The render mode. |
KAPI b8 material_system_apply_instance | ( | material * | m, |
struct frame_data * | p_frame_data, | ||
b8 | needs_update | ||
) |
Applies instance-level material data for the given material.
m | A pointer to the material to be applied. |
p_frame_data | A pointer to the current frame's data. |
needs_update | Indicates if material internals require updating, or if they should just be bound. |
Applies local-level material data (typically just model matrix).
m | A pointer to the material to be applied. |
model | A constant pointer to the model matrix to be applied. |
KAPI void material_system_dump | ( | void | ) |
Dumps all of the registered materials and their reference counts/handles.
Gets a pointer to the default material. Does not reference count.
Gets a pointer to the default terrain material. Does not reference count.
Gets a pointer to the default UI material. Does not reference count.
Initializes the material system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system.
memory_requirement | A pointer to hold the memory requirement as it is calculated. |
state | A block of memory to hold the state or, if gathering the memory requirement, 0. |
config | The configuration (material_system_config) for this system. |
KAPI void material_system_release | ( | const char * | name | ) |
Releases a material with the given name. Ignores non-existant materials. Decreases the reference counter by 1. If the reference counter reaches 0 and auto_release was set to true, the material is unloaded, releasing internal resources.
name | The name of the material to unload. |
void material_system_shutdown | ( | void * | state | ) |
Shuts down the material system.
state | The state block of memory. |