Kohi Game Engine
renderer_frontend.h File Reference

The renderer frontend, which is the only thing the rest of the engine sees. This is responsible for transferring any data to and from the renderer backend in an agnostic way. More...

#include "renderer_types.h"

Go to the source code of this file.

Data Structures

struct  renderer_system_config
 

Typedefs

typedef struct renderer_system_config renderer_system_config
 

Functions

KAPI b8 renderer_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the renderer frontend/system. Should be called twice - once to obtain the memory requirement (passing state=0), and a second time passing allocated memory to state. More...
 
KAPI void renderer_system_shutdown (void *state)
 Shuts the renderer system/frontend down. More...
 
KAPI void renderer_on_resized (u16 width, u16 height)
 Handles resize events. More...
 
KAPI b8 renderer_frame_prepare (struct frame_data *p_frame_data)
 Performs setup routines required at the start of a frame. More...
 
KAPI b8 renderer_begin (struct frame_data *p_frame_data)
 Begins a render. There must be at least one of these and a matching end per frame. More...
 
KAPI b8 renderer_end (struct frame_data *p_frame_data)
 Ends a render. More...
 
KAPI b8 renderer_present (struct frame_data *p_frame_data)
 Performs routines required to draw a frame, such as presentation. Should only be called after a successful return of begin_frame. More...
 
KAPI void renderer_viewport_set (vec4 rect)
 Sets the renderer viewport to the given rectangle. Must be done within a renderpass. More...
 
KAPI void renderer_viewport_reset (void)
 Resets the viewport to the default, which matches the application window. Must be done within a renderpass. More...
 
KAPI void renderer_scissor_set (vec4 rect)
 Sets the renderer scissor to the given rectangle. Must be done within a renderpass. More...
 
KAPI void renderer_scissor_reset (void)
 Resets the scissor to the default, which matches the application window. Must be done within a renderpass. More...
 
KAPI void renderer_winding_set (renderer_winding winding)
 Set the renderer to use the given winding direction. More...
 
KAPI void renderer_texture_create (const u8 *pixels, struct texture *texture)
 Creates a new texture. More...
 
KAPI void renderer_texture_destroy (struct texture *texture)
 Destroys the given texture, releasing internal resources from the GPU. More...
 
KAPI void renderer_texture_create_writeable (texture *t)
 Creates a new writeable texture with no data written to it. More...
 
KAPI void renderer_texture_resize (texture *t, u32 new_width, u32 new_height)
 Resizes a texture. There is no check at this level to see if the texture is writeable. Internal resources are destroyed and re-created at the new resolution. Data is lost and would need to be reloaded. More...
 
KAPI void renderer_texture_write_data (texture *t, u32 offset, u32 size, const u8 *pixels)
 Writes the given data to the provided texture. More...
 
KAPI void renderer_texture_read_data (texture *t, u32 offset, u32 size, void **out_memory)
 Reads the given data from the provided texture. More...
 
KAPI void renderer_texture_read_pixel (texture *t, u32 x, u32 y, u8 **out_rgba)
 Reads a pixel from the provided texture at the given x/y coordinate. More...
 
KAPI b8 renderer_geometry_create (geometry *geometry, u32 vertex_size, u32 vertex_count, const void *vertices, u32 index_size, u32 index_count, const void *indices)
 Creates geometry, taking a copy of the provided data and setting up the data structure. More...
 
KAPI b8 renderer_geometry_upload (geometry *geometry)
 Acquires GPU resources and uploads geometry data. More...
 
KAPI void renderer_geometry_vertex_update (geometry *g, u32 offset, u32 vertex_count, void *vertices)
 Updates vertex data in the given geometry with the provided data in the given range. More...
 
KAPI void renderer_geometry_destroy (geometry *geometry)
 Destroys the given geometry, releasing GPU resources. More...
 
KAPI void renderer_geometry_draw (geometry_render_data *data)
 Draws the given geometry. Should only be called inside a renderpass, within a frame. More...
 
KAPI b8 renderer_renderpass_begin (renderpass *pass, render_target *target)
 Begins the given renderpass. More...
 
KAPI b8 renderer_renderpass_end (renderpass *pass)
 Ends the given renderpass. More...
 
KAPI b8 renderer_shader_create (struct shader *s, const shader_config *config, renderpass *pass, u8 stage_count, const char **stage_filenames, shader_stage *stages)
 Creates internal shader resources using the provided parameters. More...
 
KAPI void renderer_shader_destroy (struct shader *s)
 Destroys the given shader and releases any resources held by it. More...
 
KAPI b8 renderer_shader_initialize (struct shader *s)
 Initializes a configured shader. Will be automatically destroyed if this step fails. Must be done after vulkan_shader_create(). More...
 
KAPI b8 renderer_shader_use (struct shader *s)
 Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls. More...
 
KAPI b8 renderer_shader_bind_globals (struct shader *s)
 Binds global resources for use and updating. More...
 
KAPI b8 renderer_shader_bind_instance (struct shader *s, u32 instance_id)
 Binds instance resources for use and updating. More...
 
KAPI b8 renderer_shader_apply_globals (struct shader *s, b8 needs_update)
 Applies global data to the uniform buffer. More...
 
KAPI b8 renderer_shader_apply_instance (struct shader *s, b8 needs_update)
 Applies data for the currently bound instance. More...
 
KAPI b8 renderer_shader_instance_resources_acquire (struct shader *s, u32 texture_map_count, texture_map **maps, u32 *out_instance_id)
 Acquires internal instance-level resources and provides an instance id. More...
 
KAPI b8 renderer_shader_instance_resources_release (struct shader *s, u32 instance_id)
 Releases internal instance-level resources for the given instance id. More...
 
KAPI b8 renderer_shader_uniform_set (struct shader *s, struct shader_uniform *uniform, const void *value)
 Sets the uniform of the given shader to the provided value. More...
 
KAPI b8 renderer_texture_map_resources_acquire (struct texture_map *map)
 Acquires internal resources for the given texture map. More...
 
KAPI void renderer_texture_map_resources_release (struct texture_map *map)
 Releases internal resources for the given texture map. More...
 
KAPI void renderer_render_target_create (u8 attachment_count, render_target_attachment *attachments, renderpass *pass, u32 width, u32 height, render_target *out_target)
 Creates a new render target using the provided data. More...
 
KAPI void renderer_render_target_destroy (render_target *target, b8 free_internal_memory)
 Destroys the provided render target. More...
 
KAPI texturerenderer_window_attachment_get (u8 index)
 Attempts to get the window render target at the given index. More...
 
KAPI texturerenderer_depth_attachment_get (u8 index)
 Returns a pointer to the main depth texture target. More...
 
KAPI u8 renderer_window_attachment_index_get (void)
 Returns the current window attachment index. More...
 
KAPI u8 renderer_window_attachment_count_get (void)
 Returns the number of attachments required for window-based render targets. More...
 
KAPI b8 renderer_renderpass_create (const renderpass_config *config, renderpass *out_renderpass)
 Creates a new renderpass. More...
 
KAPI void renderer_renderpass_destroy (renderpass *pass)
 Destroys the given renderpass. More...
 
KAPI b8 renderer_is_multithreaded (void)
 Indicates if the renderer is capable of multi-threading. More...
 
KAPI b8 renderer_flag_enabled_get (renderer_config_flags flag)
 Indicates if the provided renderer flag is enabled. If multiple flags are passed, all must be set for this to return true. More...
 
KAPI void renderer_flag_enabled_set (renderer_config_flags flag, b8 enabled)
 Sets whether the included flag(s) are enabled or not. If multiple flags are passed, multiple are set at once. More...
 
KAPI b8 renderer_renderbuffer_create (const char *name, renderbuffer_type type, u64 total_size, renderbuffer_track_type track_type, renderbuffer *out_buffer)
 Creates a new renderbuffer to hold data for a given purpose/use. Backed by a renderer-backend-specific buffer resource. More...
 
KAPI void renderer_renderbuffer_destroy (renderbuffer *buffer)
 Destroys the given renderbuffer. More...
 
KAPI b8 renderer_renderbuffer_bind (renderbuffer *buffer, u64 offset)
 Binds the given buffer at the provided offset. More...
 
KAPI b8 renderer_renderbuffer_unbind (renderbuffer *buffer)
 Unbinds the given buffer. More...
 
KAPI void * renderer_renderbuffer_map_memory (renderbuffer *buffer, u64 offset, u64 size)
 Maps memory from the given buffer in the provided range to a block of memory and returns it. This memory should be considered invalid once unmapped. More...
 
KAPI void renderer_renderbuffer_unmap_memory (renderbuffer *buffer, u64 offset, u64 size)
 Unmaps memory from the given buffer in the provided range to a block of memory. This memory should be considered invalid once unmapped. More...
 
KAPI b8 renderer_renderbuffer_flush (renderbuffer *buffer, u64 offset, u64 size)
 Flushes buffer memory at the given range. Should be done after a write. More...
 
KAPI b8 renderer_renderbuffer_read (renderbuffer *buffer, u64 offset, u64 size, void **out_memory)
 Reads memory from the provided buffer at the given range to the output variable. More...
 
KAPI b8 renderer_renderbuffer_resize (renderbuffer *buffer, u64 new_total_size)
 Resizes the given buffer to new_total_size. new_total_size must be greater than the current buffer size. Data from the old internal buffer is copied over. More...
 
KAPI b8 renderer_renderbuffer_allocate (renderbuffer *buffer, u64 size, u64 *out_offset)
 Attempts to allocate memory from the given buffer. Should only be used on buffers that were created with use_freelist = true. More...
 
KAPI b8 renderer_renderbuffer_free (renderbuffer *buffer, u64 size, u64 offset)
 Frees memory from the given buffer. More...
 
KAPI b8 renderer_renderbuffer_clear (renderbuffer *buffer, b8 zero_memory)
 Clears the given buffer. Internally, resets the free list if one is used. More...
 
KAPI b8 renderer_renderbuffer_load_range (renderbuffer *buffer, u64 offset, u64 size, const void *data)
 Loads provided data into the specified rage of the given buffer. More...
 
KAPI b8 renderer_renderbuffer_copy_range (renderbuffer *source, u64 source_offset, renderbuffer *dest, u64 dest_offset, u64 size)
 Copies data in the specified rage fron the source to the destination buffer. More...
 
KAPI b8 renderer_renderbuffer_draw (renderbuffer *buffer, u64 offset, u32 element_count, b8 bind_only)
 Attempts to draw the contents of the provided buffer at the given offset and element count. Only meant to be used with vertex and index buffers. More...
 
KAPI struct viewportrenderer_active_viewport_get (void)
 Returns a pointer to the currently active viewport. More...
 
KAPI void renderer_active_viewport_set (struct viewport *v)
 Sets the currently active viewport. More...
 

Detailed Description

The renderer frontend, which is the only thing the rest of the engine sees. This is responsible for transferring any data to and from the renderer backend in an agnostic way.

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

Typedef Documentation

◆ renderer_system_config

Function Documentation

◆ renderer_active_viewport_get()

KAPI struct viewport* renderer_active_viewport_get ( void  )

Returns a pointer to the currently active viewport.

◆ renderer_active_viewport_set()

KAPI void renderer_active_viewport_set ( struct viewport v)

Sets the currently active viewport.

Parameters
viewportA pointer to the viewport to be set.

◆ renderer_begin()

KAPI b8 renderer_begin ( struct frame_data p_frame_data)

Begins a render. There must be at least one of these and a matching end per frame.

Parameters
p_frame_dataA pointer to the current frame's data.
Returns
True if successful; otherwise false.

◆ renderer_depth_attachment_get()

KAPI texture* renderer_depth_attachment_get ( u8  index)

Returns a pointer to the main depth texture target.

Parameters
indexThe index of the attachment to get. Must be within the range of window render target count.
Returns
A pointer to a texture attachment if successful; otherwise 0.

◆ renderer_end()

KAPI b8 renderer_end ( struct frame_data p_frame_data)

Ends a render.

Parameters
p_frame_dataA pointer to the current frame's data.
Returns
True if successful; otherwise false.

◆ renderer_flag_enabled_get()

KAPI b8 renderer_flag_enabled_get ( renderer_config_flags  flag)

Indicates if the provided renderer flag is enabled. If multiple flags are passed, all must be set for this to return true.

Parameters
flagThe flag to be checked.
Returns
True if the flag(s) set; otherwise false.

◆ renderer_flag_enabled_set()

KAPI void renderer_flag_enabled_set ( renderer_config_flags  flag,
b8  enabled 
)

Sets whether the included flag(s) are enabled or not. If multiple flags are passed, multiple are set at once.

Parameters
flagThe flag to be checked.
enabledIndicates whether or not to enable the flag(s).

◆ renderer_frame_prepare()

KAPI b8 renderer_frame_prepare ( struct frame_data p_frame_data)

Performs setup routines required at the start of a frame.

Note
A false result does not necessarily indicate failure. It can also specify that the backend is simply not in a state capable of drawing a frame at the moment, and that it should be attempted again on the next loop. End frame does not need to (and should not) be called if this is the case.
Parameters
p_frame_dataA pointer to the current frame's data.
Returns
True if successful; otherwise false.

◆ renderer_geometry_create()

KAPI b8 renderer_geometry_create ( geometry geometry,
u32  vertex_size,
u32  vertex_count,
const void *  vertices,
u32  index_size,
u32  index_count,
const void *  indices 
)

Creates geometry, taking a copy of the provided data and setting up the data structure.

Parameters
geometryA pointer to the geometry to create.
vertex_sizeThe size of each vertex.
vertex_countThe number of vertices.
verticesThe vertex array.
index_sizeThe size of each index.
index_countThe number of indices.
indicesThe index array.
Returns
True on success; otherwise false.

◆ renderer_geometry_destroy()

KAPI void renderer_geometry_destroy ( geometry geometry)

Destroys the given geometry, releasing GPU resources.

Parameters
geometryA pointer to the geometry to be destroyed.

◆ renderer_geometry_draw()

KAPI void renderer_geometry_draw ( geometry_render_data data)

Draws the given geometry. Should only be called inside a renderpass, within a frame.

Parameters
dataThe render data of the geometry to be drawn.

◆ renderer_geometry_upload()

KAPI b8 renderer_geometry_upload ( geometry geometry)

Acquires GPU resources and uploads geometry data.

Parameters
geometryA pointer to the geometry to upload.
Returns
True on success; otherwise false.

◆ renderer_geometry_vertex_update()

KAPI void renderer_geometry_vertex_update ( geometry g,
u32  offset,
u32  vertex_count,
void *  vertices 
)

Updates vertex data in the given geometry with the provided data in the given range.

Parameters
gA pointer to the geometry to be created.
offsetThe offset in bytes to update. 0 if updating from the beginning.
vertex_countThe number of vertices which will be updated.
verticesThe vertex data.

◆ renderer_is_multithreaded()

KAPI b8 renderer_is_multithreaded ( void  )

Indicates if the renderer is capable of multi-threading.

◆ renderer_on_resized()

KAPI void renderer_on_resized ( u16  width,
u16  height 
)

Handles resize events.

Parameters
widthThe new window width.
heightThe new window height.

◆ renderer_present()

KAPI b8 renderer_present ( struct frame_data p_frame_data)

Performs routines required to draw a frame, such as presentation. Should only be called after a successful return of begin_frame.

Parameters
p_frame_dataA constant pointer to the current frame's data.
Returns
True on success; otherwise false.

◆ renderer_render_target_create()

KAPI void renderer_render_target_create ( u8  attachment_count,
render_target_attachment attachments,
renderpass pass,
u32  width,
u32  height,
render_target out_target 
)

Creates a new render target using the provided data.

Parameters
attachment_countThe number of attachments.
attachmentsAn array of attachments.
renderpassA pointer to the renderpass the render target is associated with.
widthThe width of the render target in pixels.
heightThe height of the render target in pixels.
out_targetA pointer to hold the newly created render target.

◆ renderer_render_target_destroy()

KAPI void renderer_render_target_destroy ( render_target target,
b8  free_internal_memory 
)

Destroys the provided render target.

Parameters
targetA pointer to the render target to be destroyed.
free_internal_memoryIndicates if internal memory should be freed.

◆ renderer_renderbuffer_allocate()

KAPI b8 renderer_renderbuffer_allocate ( renderbuffer buffer,
u64  size,
u64 out_offset 
)

Attempts to allocate memory from the given buffer. Should only be used on buffers that were created with use_freelist = true.

Parameters
bufferA pointer to the buffer to be allocated from.
sizeThe size in bytes to allocate.
out_offsetA pointer to hold the offset in bytes of the allocation from the beginning of the buffer.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_bind()

KAPI b8 renderer_renderbuffer_bind ( renderbuffer buffer,
u64  offset 
)

Binds the given buffer at the provided offset.

Parameters
bufferA pointer to the buffer to bind.
offsetThe offset in bytes from the beginning of the buffer.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_clear()

KAPI b8 renderer_renderbuffer_clear ( renderbuffer buffer,
b8  zero_memory 
)

Clears the given buffer. Internally, resets the free list if one is used.

Parameters
bufferA pointer to the buffer to be freed from.
zero_memoryTrue if memory should be zeroed; otherwise false. NOTE: this can be an expensive operation on large sums of memory.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_copy_range()

KAPI b8 renderer_renderbuffer_copy_range ( renderbuffer source,
u64  source_offset,
renderbuffer dest,
u64  dest_offset,
u64  size 
)

Copies data in the specified rage fron the source to the destination buffer.

Parameters
sourceA pointer to the source buffer to copy data from.
source_offsetThe offset in bytes from the beginning of the source buffer.
destA pointer to the destination buffer to copy data to.
dest_offsetThe offset in bytes from the beginning of the destination buffer.
sizeThe size of the data in bytes to be copied.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_create()

KAPI b8 renderer_renderbuffer_create ( const char *  name,
renderbuffer_type  type,
u64  total_size,
renderbuffer_track_type  track_type,
renderbuffer out_buffer 
)

Creates a new renderbuffer to hold data for a given purpose/use. Backed by a renderer-backend-specific buffer resource.

Parameters
nameThe name of the renderbuffer, used for debugging purposes.
typeThe type of buffer, indicating it's use (i.e. vertex/index data, uniforms, etc.)
total_sizeThe total size in bytes of the buffer.
track_typeIndicates what type of allocation tracking should be used.
out_bufferA pointer to hold the newly created buffer.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_destroy()

KAPI void renderer_renderbuffer_destroy ( renderbuffer buffer)

Destroys the given renderbuffer.

Parameters
bufferA pointer to the buffer to be destroyed.

◆ renderer_renderbuffer_draw()

KAPI b8 renderer_renderbuffer_draw ( renderbuffer buffer,
u64  offset,
u32  element_count,
b8  bind_only 
)

Attempts to draw the contents of the provided buffer at the given offset and element count. Only meant to be used with vertex and index buffers.

Parameters
bufferA pointer to the buffer to be drawn.
offsetThe offset in bytes from the beginning of the buffer.
element_countThe number of elements to be drawn.
bind_onlyOnly bind the buffer, but don't draw.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_flush()

KAPI b8 renderer_renderbuffer_flush ( renderbuffer buffer,
u64  offset,
u64  size 
)

Flushes buffer memory at the given range. Should be done after a write.

Parameters
bufferA pointer to the buffer to unmap.
offsetThe number of bytes from the beginning of the buffer to flush.
sizeThe amount of memory in the buffer to flush.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_free()

KAPI b8 renderer_renderbuffer_free ( renderbuffer buffer,
u64  size,
u64  offset 
)

Frees memory from the given buffer.

Parameters
bufferA pointer to the buffer to be freed from.
sizeThe size in bytes to free.
offsetThe offset in bytes from the beginning of the buffer to free.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_load_range()

KAPI b8 renderer_renderbuffer_load_range ( renderbuffer buffer,
u64  offset,
u64  size,
const void *  data 
)

Loads provided data into the specified rage of the given buffer.

Parameters
bufferA pointer to the buffer to load data into.
offsetThe offset in bytes from the beginning of the buffer.
sizeThe size of the data in bytes to be loaded.
dataThe data to be loaded.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_map_memory()

KAPI void* renderer_renderbuffer_map_memory ( renderbuffer buffer,
u64  offset,
u64  size 
)

Maps memory from the given buffer in the provided range to a block of memory and returns it. This memory should be considered invalid once unmapped.

Parameters
bufferA pointer to the buffer to map.
offsetThe number of bytes from the beginning of the buffer to map.
sizeThe amount of memory in the buffer to map.
Returns
A mapped block of memory. Freed and invalid once unmapped.

◆ renderer_renderbuffer_read()

KAPI b8 renderer_renderbuffer_read ( renderbuffer buffer,
u64  offset,
u64  size,
void **  out_memory 
)

Reads memory from the provided buffer at the given range to the output variable.

Parameters
bufferA pointer to the buffer to read from.
offsetThe number of bytes from the beginning of the buffer to read.
sizeThe amount of memory in the buffer to read.
out_memoryA pointer to a block of memory to read to. Must be of appropriate size.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_resize()

KAPI b8 renderer_renderbuffer_resize ( renderbuffer buffer,
u64  new_total_size 
)

Resizes the given buffer to new_total_size. new_total_size must be greater than the current buffer size. Data from the old internal buffer is copied over.

Parameters
bufferA pointer to the buffer to be resized.
new_total_sizeThe new size in bytes. Must be larger than the current size.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_unbind()

KAPI b8 renderer_renderbuffer_unbind ( renderbuffer buffer)

Unbinds the given buffer.

Parameters
bufferA pointer to the buffer to be unbound.
Returns
True on success; otherwise false.

◆ renderer_renderbuffer_unmap_memory()

KAPI void renderer_renderbuffer_unmap_memory ( renderbuffer buffer,
u64  offset,
u64  size 
)

Unmaps memory from the given buffer in the provided range to a block of memory. This memory should be considered invalid once unmapped.

Parameters
bufferA pointer to the buffer to unmap.
offsetThe number of bytes from the beginning of the buffer to unmap.
sizeThe amount of memory in the buffer to unmap.

◆ renderer_renderpass_begin()

KAPI b8 renderer_renderpass_begin ( renderpass pass,
render_target target 
)

Begins the given renderpass.

Parameters
passA pointer to the renderpass to begin.
targetA pointer to the render target to be used.
Returns
True on success; otherwise false.

◆ renderer_renderpass_create()

KAPI b8 renderer_renderpass_create ( const renderpass_config config,
renderpass out_renderpass 
)

Creates a new renderpass.

Parameters
configA constant pointer to the configuration to be used when creating the renderpass.
out_renderpassA pointer to the generic renderpass.

◆ renderer_renderpass_destroy()

KAPI void renderer_renderpass_destroy ( renderpass pass)

Destroys the given renderpass.

Parameters
passA pointer to the renderpass to be destroyed.

◆ renderer_renderpass_end()

KAPI b8 renderer_renderpass_end ( renderpass pass)

Ends the given renderpass.

Parameters
passA pointer to the renderpass to end.
Returns
True on success; otherwise false.

◆ renderer_scissor_reset()

KAPI void renderer_scissor_reset ( void  )

Resets the scissor to the default, which matches the application window. Must be done within a renderpass.

◆ renderer_scissor_set()

KAPI void renderer_scissor_set ( vec4  rect)

Sets the renderer scissor to the given rectangle. Must be done within a renderpass.

Parameters
rectThe scissor rectangle to be set.

◆ renderer_shader_apply_globals()

KAPI b8 renderer_shader_apply_globals ( struct shader s,
b8  needs_update 
)

Applies global data to the uniform buffer.

Parameters
sA pointer to the shader to apply the global data for.
needs_updateIndicates if the shader uniforms need to be updated or just bound.
Returns
True on success; otherwise false.

◆ renderer_shader_apply_instance()

KAPI b8 renderer_shader_apply_instance ( struct shader s,
b8  needs_update 
)

Applies data for the currently bound instance.

Parameters
sA pointer to the shader to apply the instance data for.
needs_updateIndicates if the shader uniforms need to be updated or just bound.
Returns
True on success; otherwise false.

◆ renderer_shader_bind_globals()

KAPI b8 renderer_shader_bind_globals ( struct shader s)

Binds global resources for use and updating.

Parameters
sA pointer to the shader whose globals are to be bound.
Returns
True on success; otherwise false.

◆ renderer_shader_bind_instance()

KAPI b8 renderer_shader_bind_instance ( struct shader s,
u32  instance_id 
)

Binds instance resources for use and updating.

Parameters
sA pointer to the shader whose instance resources are to be bound.
instance_idThe identifier of the instance to be bound.
Returns
True on success; otherwise false.

◆ renderer_shader_create()

KAPI b8 renderer_shader_create ( struct shader s,
const shader_config config,
renderpass pass,
u8  stage_count,
const char **  stage_filenames,
shader_stage stages 
)

Creates internal shader resources using the provided parameters.

Parameters
sA pointer to the shader.
configA constant pointer to the shader config.
passA pointer to the renderpass to be associated with the shader.
stage_countThe total number of stages.
stage_filenamesAn array of shader stage filenames to be loaded. Should align with stages array.
stagesA array of shader_stages indicating what render stages (vertex, fragment, etc.) used in this shader.
Returns
b8 True on success; otherwise false.

◆ renderer_shader_destroy()

KAPI void renderer_shader_destroy ( struct shader s)

Destroys the given shader and releases any resources held by it.

Parameters
sA pointer to the shader to be destroyed.

◆ renderer_shader_initialize()

KAPI b8 renderer_shader_initialize ( struct shader s)

Initializes a configured shader. Will be automatically destroyed if this step fails. Must be done after vulkan_shader_create().

Parameters
sA pointer to the shader to be initialized.
Returns
True on success; otherwise false.

◆ renderer_shader_instance_resources_acquire()

KAPI b8 renderer_shader_instance_resources_acquire ( struct shader s,
u32  texture_map_count,
texture_map **  maps,
u32 out_instance_id 
)

Acquires internal instance-level resources and provides an instance id.

Parameters
sA pointer to the shader to acquire resources from.
texture_map_countThe number of texture maps used.
mapsAn array of texture map pointers. Must be one per texture in the instance.
out_instance_idA pointer to hold the new instance identifier.
Returns
True on success; otherwise false.

◆ renderer_shader_instance_resources_release()

KAPI b8 renderer_shader_instance_resources_release ( struct shader s,
u32  instance_id 
)

Releases internal instance-level resources for the given instance id.

Parameters
sA pointer to the shader to release resources from.
instance_idThe instance identifier whose resources are to be released.
Returns
True on success; otherwise false.

◆ renderer_shader_uniform_set()

KAPI b8 renderer_shader_uniform_set ( struct shader s,
struct shader_uniform uniform,
const void *  value 
)

Sets the uniform of the given shader to the provided value.

Parameters
sA ponter to the shader.
uniformA constant pointer to the uniform.
valueA pointer to the value to be set.
Returns
b8 True on success; otherwise false.

◆ renderer_shader_use()

KAPI b8 renderer_shader_use ( struct shader s)

Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls.

Parameters
sA pointer to the shader to be used.
Returns
True on success; otherwise false.

◆ renderer_system_initialize()

KAPI b8 renderer_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the renderer frontend/system. Should be called twice - once to obtain the memory requirement (passing state=0), and a second time passing allocated memory to state.

Parameters
memory_requirementA pointer to hold the memory requirement for this system.
stateA block of memory to hold state data, or 0 if obtaining memory requirement.
configThe configuration (renderer_system_config) for the renderer.
Returns
True on success; otherwise false.

◆ renderer_system_shutdown()

KAPI void renderer_system_shutdown ( void *  state)

Shuts the renderer system/frontend down.

Parameters
stateA pointer to the state block of memory.

◆ renderer_texture_create()

KAPI void renderer_texture_create ( const u8 pixels,
struct texture texture 
)

Creates a new texture.

Parameters
pixelsThe raw image data to be uploaded to the GPU.
textureA pointer to the texture to be loaded.

◆ renderer_texture_create_writeable()

KAPI void renderer_texture_create_writeable ( texture t)

Creates a new writeable texture with no data written to it.

Parameters
tA pointer to the texture to hold the resources.

◆ renderer_texture_destroy()

KAPI void renderer_texture_destroy ( struct texture texture)

Destroys the given texture, releasing internal resources from the GPU.

Parameters
textureA pointer to the texture to be destroyed.

◆ renderer_texture_map_resources_acquire()

KAPI b8 renderer_texture_map_resources_acquire ( struct texture_map map)

Acquires internal resources for the given texture map.

Parameters
mapA pointer to the texture map to obtain resources for.
Returns
True on success; otherwise false.

◆ renderer_texture_map_resources_release()

KAPI void renderer_texture_map_resources_release ( struct texture_map map)

Releases internal resources for the given texture map.

Parameters
mapA pointer to the texture map to release resources from.

◆ renderer_texture_read_data()

KAPI void renderer_texture_read_data ( texture t,
u32  offset,
u32  size,
void **  out_memory 
)

Reads the given data from the provided texture.

Parameters
tA pointer to the texture to be read from.
offsetThe offset in bytes from the beginning of the data to be read.
sizeThe number of bytes to be read.
out_memoryA pointer to a block of memory to write the read data to.

◆ renderer_texture_read_pixel()

KAPI void renderer_texture_read_pixel ( texture t,
u32  x,
u32  y,
u8 **  out_rgba 
)

Reads a pixel from the provided texture at the given x/y coordinate.

Parameters
tA pointer to the texture to be read from.
xThe pixel x-coordinate.
yThe pixel y-coordinate.
out_rgbaA pointer to an array of u8s to hold the pixel data (should be sizeof(u8) * 4)

◆ renderer_texture_resize()

KAPI void renderer_texture_resize ( texture t,
u32  new_width,
u32  new_height 
)

Resizes a texture. There is no check at this level to see if the texture is writeable. Internal resources are destroyed and re-created at the new resolution. Data is lost and would need to be reloaded.

Parameters
tA pointer to the texture to be resized.
new_widthThe new width in pixels.
new_heightThe new height in pixels.

◆ renderer_texture_write_data()

KAPI void renderer_texture_write_data ( texture t,
u32  offset,
u32  size,
const u8 pixels 
)

Writes the given data to the provided texture.

Parameters
tA pointer to the texture to be written to. NOTE: Must be a writeable texture.
offsetThe offset in bytes from the beginning of the data to be written.
sizeThe number of bytes to be written.
pixelsThe raw image data to be written.

◆ renderer_viewport_reset()

KAPI void renderer_viewport_reset ( void  )

Resets the viewport to the default, which matches the application window. Must be done within a renderpass.

◆ renderer_viewport_set()

KAPI void renderer_viewport_set ( vec4  rect)

Sets the renderer viewport to the given rectangle. Must be done within a renderpass.

Parameters
rectThe viewport rectangle to be set.

◆ renderer_winding_set()

KAPI void renderer_winding_set ( renderer_winding  winding)

Set the renderer to use the given winding direction.

Parameters
windingThe winding direction.

◆ renderer_window_attachment_count_get()

KAPI u8 renderer_window_attachment_count_get ( void  )

Returns the number of attachments required for window-based render targets.

◆ renderer_window_attachment_get()

KAPI texture* renderer_window_attachment_get ( u8  index)

Attempts to get the window render target at the given index.

Parameters
indexThe index of the attachment to get. Must be within the range of window render target count.
Returns
A pointer to a texture attachment if successful; otherwise 0.

◆ renderer_window_attachment_index_get()

KAPI u8 renderer_window_attachment_index_get ( void  )

Returns the current window attachment index.