Kohi Game Engine
shader_system.h File Reference

A system to manage shaders. Respondible for working with the renderer to create, destroy, bind/unbind and set shader properties such as uniforms. More...

Go to the source code of this file.

Data Structures

struct  shader_system_config
 Configuration for the shader system. More...
 

Typedefs

typedef struct shader_system_config shader_system_config
 Configuration for the shader system. More...
 

Functions

b8 shader_system_initialize (u64 *memory_requirement, void *memory, void *config)
 Initializes the shader system using the supplied configuration. NOTE: Call this twice, once to obtain memory requirement (memory = 0) and a second time including allocated memory. More...
 
void shader_system_shutdown (void *state)
 Shuts down the shader system. More...
 
KAPI khandle shader_system_get (kname name, kname package_name)
 Returns a handle to a shader with the given name. Attempts to load the shader if not already loaded. More...
 
KAPI khandle shader_system_get_from_source (kname name, const char *shader_config_source)
 Returns a handle to a shader with the given name based on the provided config source. Attempts to load the shader if not already loaded. More...
 
KAPI void shader_system_destroy (khandle *shader)
 Attempts to destroy the shader with the given handle. Handle will be invalidated. More...
 
KAPI b8 shader_system_set_wireframe (khandle shader, b8 wireframe_enabled)
 Attempts to set wireframe mode on the given shader. If the renderer backend, or the shader does not support this , it will fail when attempting to enable. Disabling will always succeed. More...
 
KAPI b8 shader_system_use (khandle shader)
 Uses the shader with the given handle. More...
 
KAPI u16 shader_system_uniform_location (khandle shader, kname uniform_name)
 Returns the uniform location for a uniform with the given name, if found. More...
 
KAPI b8 shader_system_uniform_set (khandle shader, kname uniform_name, const void *value)
 Sets the value of a uniform with the given name to the supplied value. More...
 
KAPI b8 shader_system_uniform_set_arrayed (khandle shader, kname uniform_name, u32 array_index, const void *value)
 Sets the value of an arrayed uniform with the given name to the supplied value. More...
 
KAPI b8 shader_system_texture_set (khandle shader, kname sampler_name, ktexture t)
 Sets the texture uniform with the given name to the supplied texture. More...
 
KAPI b8 shader_system_texture_set_arrayed (khandle shader, kname uniform_name, u32 array_index, ktexture t)
 Sets the arrayed texture uniform with the given name to the supplied texture at the given index. More...
 
KAPI b8 shader_system_uniform_set_by_location (khandle shader, u16 location, const void *value)
 Sets a uniform value by location. More...
 
KAPI b8 shader_system_uniform_set_by_location_arrayed (khandle shader, u16 location, u32 array_index, const void *value)
 Sets a uniform value by location. More...
 
KAPI b8 shader_system_texture_set_by_location (khandle shader, u16 location, ktexture t)
 Sets a texture value by location. More...
 
KAPI b8 shader_system_texture_set_by_location_arrayed (khandle shader, u16 location, u32 array_index, ktexture value)
 Sets a texture value by location. More...
 
KAPI b8 shader_system_sampler_set_by_location_arrayed (khandle shader, u16 location, u32 array_index, ktexture t)
 Sets a sampler value by location. More...
 
KAPI b8 shader_system_bind_frame (khandle shader)
 Binds the shader at per-frame frequency for use. Must be done before setting frame-scoped uniforms. More...
 
KAPI b8 shader_system_bind_group (khandle shader, u32 group_id)
 Binds the instance with the given id for use. Must be done before setting instance-scoped uniforms. More...
 
KAPI b8 shader_system_bind_draw_id (khandle shader, u32 draw_id)
 Binds the local with the given id for use. Must be done before setting local-scoped uniforms. More...
 
KAPI b8 shader_system_apply_per_frame (khandle shader)
 Applies per-frame uniforms. More...
 
KAPI b8 shader_system_apply_per_group (khandle shader)
 Applies per-group uniforms. More...
 
KAPI b8 shader_system_apply_per_draw (khandle shader)
 Applies per-draw uniforms. Updates the generation pointed to. More...
 
KAPI b8 shader_system_shader_group_acquire (khandle shader, u32 *out_group_id)
 Attempts to acquire new group resources from the given shader using the collection of maps passed. More...
 
KAPI b8 shader_system_shader_group_release (khandle shader, u32 instance_id)
 Releases group resources and texture map resources from the provided shader. More...
 
KAPI b8 shader_system_shader_per_draw_acquire (khandle shader, u32 *out_per_draw_id)
 Attempts to acquire new per-draw resources from the given shader using the collection of maps passed. More...
 
KAPI b8 shader_system_shader_per_draw_release (khandle shader, u32 per_draw_id)
 Releases per-draw resources and texture map resources from the provided shader. More...
 

Detailed Description

A system to manage shaders. Respondible for working with the renderer to create, destroy, bind/unbind and set shader properties such as uniforms.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-03-09

Typedef Documentation

◆ shader_system_config

Configuration for the shader system.

Function Documentation

◆ shader_system_apply_per_draw()

KAPI b8 shader_system_apply_per_draw ( khandle  shader)

Applies per-draw uniforms. Updates the generation pointed to.

Parameters
shaderA handle to the shader to update.
Returns
True on success; otherwise false.

◆ shader_system_apply_per_frame()

KAPI b8 shader_system_apply_per_frame ( khandle  shader)

Applies per-frame uniforms.

Parameters
shaderA handle to the shader to update.
Returns
True on success; otherwise false.

◆ shader_system_apply_per_group()

KAPI b8 shader_system_apply_per_group ( khandle  shader)

Applies per-group uniforms.

Parameters
shaderA handle to the shader to update.
Returns
True on success; otherwise false.

◆ shader_system_bind_draw_id()

KAPI b8 shader_system_bind_draw_id ( khandle  shader,
u32  draw_id 
)

Binds the local with the given id for use. Must be done before setting local-scoped uniforms.

Parameters
shaderA handle to the shader to update.
draw_idThe identifier of the per-draw resources to bind.
Returns
True on success; otherwise false.

◆ shader_system_bind_frame()

KAPI b8 shader_system_bind_frame ( khandle  shader)

Binds the shader at per-frame frequency for use. Must be done before setting frame-scoped uniforms.

Parameters
shaderA handle to the shader to update.
instance_idThe identifier of the instance to bind.
Returns
True on success; otherwise false.

◆ shader_system_bind_group()

KAPI b8 shader_system_bind_group ( khandle  shader,
u32  group_id 
)

Binds the instance with the given id for use. Must be done before setting instance-scoped uniforms.

Parameters
shaderA handle to the shader to update.
group_idThe identifier of the group to bind.
Returns
True on success; otherwise false.

◆ shader_system_destroy()

KAPI void shader_system_destroy ( khandle shader)

Attempts to destroy the shader with the given handle. Handle will be invalidated.

Parameters
shader_nameA pointer to a handle to the shader to destroy. Handle will be invalidated.

◆ shader_system_get()

KAPI khandle shader_system_get ( kname  name,
kname  package_name 
)

Returns a handle to a shader with the given name. Attempts to load the shader if not already loaded.

Parameters
shader_nameThe kname to search for.
package_nameThe package to get the shader from if not already loaded. Pass INVALID_KNAME to search all packages.
Returns
A handle to a shader, if found/loaded; otherwise an invalid handle.

◆ shader_system_get_from_source()

KAPI khandle shader_system_get_from_source ( kname  name,
const char *  shader_config_source 
)

Returns a handle to a shader with the given name based on the provided config source. Attempts to load the shader if not already loaded.

Parameters
shader_nameThe name of the new shader.
shader_config_sourceA string containing the shader's configuration source as if it were loaded from an asset.
Returns
A handle to a shader, if loaded; otherwise an invalid handle.

◆ shader_system_initialize()

b8 shader_system_initialize ( u64 memory_requirement,
void *  memory,
void *  config 
)

Initializes the shader system using the supplied configuration. NOTE: Call this twice, once to obtain memory requirement (memory = 0) and a second time including allocated memory.

Parameters
memory_requirementA pointer to hold the memory requirement of this system in bytes.
memoryA memory block to be used to hold the state of this system. Pass 0 on the first call to get memory requirement.
configThe configuration (shader_system_config) to be used when initializing the system.
Returns
b8 True on success; otherwise false.

◆ shader_system_sampler_set_by_location_arrayed()

KAPI b8 shader_system_sampler_set_by_location_arrayed ( khandle  shader,
u16  location,
u32  array_index,
ktexture  t 
)

Sets a sampler value by location.

Parameters
shaderA handle to the shader to update.
indexThe location of the uniform.
array_indexThe index into the uniform array, if the uniform is in fact an array. Otherwise ignored.
valueA pointer to the texture to be set.
Returns
True on success; otherwise false.

◆ shader_system_set_wireframe()

KAPI b8 shader_system_set_wireframe ( khandle  shader,
b8  wireframe_enabled 
)

Attempts to set wireframe mode on the given shader. If the renderer backend, or the shader does not support this , it will fail when attempting to enable. Disabling will always succeed.

Parameters
shaderA handle to the shader to set wireframe mode for.
wireframe_enabledIndicates if wireframe mode should be enabled.
Returns
True on success; otherwise false.

◆ shader_system_shader_group_acquire()

KAPI b8 shader_system_shader_group_acquire ( khandle  shader,
u32 out_group_id 
)

Attempts to acquire new group resources from the given shader using the collection of maps passed.

Parameters
shaderA handle to the shader to acquire group resources for.
out_group_idA pointer to hold the group id once resources are acquired.
Returns
True on success; otherwise false.

◆ shader_system_shader_group_release()

KAPI b8 shader_system_shader_group_release ( khandle  shader,
u32  instance_id 
)

Releases group resources and texture map resources from the provided shader.

Parameters
shaderA handle to the shader to release group resources for.
instance_idThe identifier of the group to release.
Returns
True on success; otherwise false.

◆ shader_system_shader_per_draw_acquire()

KAPI b8 shader_system_shader_per_draw_acquire ( khandle  shader,
u32 out_per_draw_id 
)

Attempts to acquire new per-draw resources from the given shader using the collection of maps passed.

Parameters
shaderA handle to the shader to acquire per-draw resources for.
out_per_draw_idA pointer to hold the per-draw id once resources are acquired.
Returns
True on success; otherwise false.

◆ shader_system_shader_per_draw_release()

KAPI b8 shader_system_shader_per_draw_release ( khandle  shader,
u32  per_draw_id 
)

Releases per-draw resources and texture map resources from the provided shader.

Parameters
shaderA handle to the shader to release per-draw resources for.
per_draw_idThe identifier of the per-draw to release.
Returns
True on success; otherwise false.

◆ shader_system_shutdown()

void shader_system_shutdown ( void *  state)

Shuts down the shader system.

Parameters
stateA pointer to the system state.

◆ shader_system_texture_set()

KAPI b8 shader_system_texture_set ( khandle  shader,
kname  sampler_name,
ktexture  t 
)

Sets the texture uniform with the given name to the supplied texture.

Parameters
shaderA handle to the shader to update.
uniform_nameThe name of the uniform to be set.
tA pointer to the texture to be set.
Returns
True on success; otherwise false.

◆ shader_system_texture_set_arrayed()

KAPI b8 shader_system_texture_set_arrayed ( khandle  shader,
kname  uniform_name,
u32  array_index,
ktexture  t 
)

Sets the arrayed texture uniform with the given name to the supplied texture at the given index.

Parameters
shaderA handle to the shader to update.
uniform_nameThe name of the uniform to be set.
array_indexThe index into the uniform array, if the uniform is in fact an array. Otherwise ignored.
tA pointer to the texture to be set.
Returns
True on success; otherwise false.

◆ shader_system_texture_set_by_location()

KAPI b8 shader_system_texture_set_by_location ( khandle  shader,
u16  location,
ktexture  t 
)

Sets a texture value by location.

Parameters
shaderA handle to the shader to update.
locationThe location of the uniform.
valueA pointer to the texture to be set.
Returns
True on success; otherwise false.

◆ shader_system_texture_set_by_location_arrayed()

KAPI b8 shader_system_texture_set_by_location_arrayed ( khandle  shader,
u16  location,
u32  array_index,
ktexture  value 
)

Sets a texture value by location.

Parameters
shaderA handle to the shader to update.
locationThe location of the uniform.
array_indexThe index into the uniform array, if the uniform is in fact an array. Otherwise ignored.
valueA pointer to the texture to be set.
Returns
True on success; otherwise false.

◆ shader_system_uniform_location()

KAPI u16 shader_system_uniform_location ( khandle  shader,
kname  uniform_name 
)

Returns the uniform location for a uniform with the given name, if found.

Parameters
shaderA handle to the shader to obtain the location from.
uniform_nameThe name of the uniform to search for.
Returns
The uniform location, if found; otherwise INVALID_ID_U16.

◆ shader_system_uniform_set()

KAPI b8 shader_system_uniform_set ( khandle  shader,
kname  uniform_name,
const void *  value 
)

Sets the value of a uniform with the given name to the supplied value.

Parameters
shaderA handle to the shader to update.
uniform_nameThe name of the uniform to be set.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ shader_system_uniform_set_arrayed()

KAPI b8 shader_system_uniform_set_arrayed ( khandle  shader,
kname  uniform_name,
u32  array_index,
const void *  value 
)

Sets the value of an arrayed uniform with the given name to the supplied value.

Parameters
shaderA handle to the shader to update.
uniform_nameThe name of the uniform to be set.
array_indexThe index into the uniform array, if the uniform is in fact an array. Otherwise ignored.
valueThe value to be set.
Returns
True on success; otherwise false.

◆ shader_system_uniform_set_by_location()

KAPI b8 shader_system_uniform_set_by_location ( khandle  shader,
u16  location,
const void *  value 
)

Sets a uniform value by location.

Parameters
shaderA handle to the shader to update.
indexThe location of the uniform.
valueThe value of the uniform.
Returns
True on success; otherwise false.

◆ shader_system_uniform_set_by_location_arrayed()

KAPI b8 shader_system_uniform_set_by_location_arrayed ( khandle  shader,
u16  location,
u32  array_index,
const void *  value 
)

Sets a uniform value by location.

Parameters
shaderA handle to the shader to update.
locationThe location of the uniform.
array_indexThe index into the uniform array, if the uniform is in fact an array. Otherwise ignored.
valueThe value of the uniform.
Returns
True on success; otherwise false.

◆ shader_system_use()

KAPI b8 shader_system_use ( khandle  shader)

Uses the shader with the given handle.

Parameters
shaderA handle to the shader to be used.
Returns
True on success; otherwise false.