Kohi Game Engine
|
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 <defines.h>
#include <identifiers/khandle.h>
#include <kresources/kresource_types.h>
#include <math/geometry.h>
#include <strings/kname.h>
#include "core/frame_data.h"
#include "core_render_types.h"
#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 | |
b8 | renderer_system_deserialize_config (const char *config_str, renderer_system_config *out_config) |
KAPI b8 | renderer_system_initialize (u64 *memory_requirement, struct renderer_system_state *state, const renderer_system_config *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 (struct renderer_system_state *state) |
Shuts the renderer system/frontend down. More... | |
KAPI u16 | renderer_system_frame_number_get (struct renderer_system_state *state) |
KAPI b8 | renderer_on_window_created (struct renderer_system_state *state, struct kwindow *window) |
KAPI void | renderer_on_window_destroyed (struct renderer_system_state *state, struct kwindow *window) |
KAPI void | renderer_on_window_resized (struct renderer_system_state *state, const struct kwindow *window) |
Handles window resize events. More... | |
KAPI void | renderer_begin_debug_label (const char *label_text, vec3 colour) |
Begins the marking of a section of commands, listed under a given name and colour. Becomes a no-op in non-debug builds. NOTE: Each renderer backend will have different or possibly non-existant implementations of this. More... | |
KAPI void | renderer_end_debug_label (void) |
Ends the last debug section of commands. Becomes a no-op in non-debug builds. NOTE: Each renderer backend will have different or possibly non-existant implementations of this. More... | |
KAPI b8 | renderer_frame_prepare (struct renderer_system_state *state, struct frame_data *p_frame_data) |
Performs setup routines required at the start of a frame. More... | |
KAPI b8 | renderer_frame_prepare_window_surface (struct renderer_system_state *state, struct kwindow *window, struct frame_data *p_frame_data) |
Prepares a window's surface for drawing. More... | |
KAPI b8 | renderer_frame_command_list_begin (struct renderer_system_state *state, 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_frame_command_list_end (struct renderer_system_state *state, struct frame_data *p_frame_data) |
Ends a render. More... | |
KAPI b8 | renderer_frame_submit (struct renderer_system_state *state, struct frame_data *p_frame_data) |
KAPI b8 | renderer_frame_present (struct renderer_system_state *state, struct kwindow *window, 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. More... | |
KAPI void | renderer_viewport_reset (void) |
Resets the viewport to the default, which matches the application window. More... | |
KAPI void | renderer_scissor_set (vec4 rect) |
Sets the renderer scissor to the given rectangle. More... | |
KAPI void | renderer_scissor_reset (void) |
Resets the scissor to the default, which matches the application window. More... | |
KAPI void | renderer_winding_set (renderer_winding winding) |
Set the renderer to use the given winding direction. More... | |
KAPI void | renderer_cull_mode_set (renderer_cull_mode cull_mode) |
Set the renderer to use the given cull mode. More... | |
KAPI void | renderer_set_stencil_test_enabled (b8 enabled) |
Set stencil testing enabled/disabled. More... | |
KAPI void | renderer_set_stencil_reference (u32 reference) |
Set the stencil reference for testing. More... | |
KAPI void | renderer_set_depth_test_enabled (b8 enabled) |
Set depth testing enabled/disabled. More... | |
KAPI void | renderer_set_depth_write_enabled (b8 enabled) |
Set depth write enabled/disabled. More... | |
KAPI void | renderer_set_stencil_op (renderer_stencil_op fail_op, renderer_stencil_op pass_op, renderer_stencil_op depth_fail_op, renderer_compare_op compare_op) |
Set stencil operation. More... | |
KAPI void | renderer_begin_rendering (struct renderer_system_state *state, struct frame_data *p_frame_data, rect_2d render_area, u32 colour_target_count, khandle *colour_targets, khandle depth_stencil_target, u32 depth_stencil_layer) |
Begins rendering against the given targets. More... | |
KAPI void | renderer_end_rendering (struct renderer_system_state *state, struct frame_data *p_frame_data) |
KAPI void | renderer_set_stencil_compare_mask (u32 compare_mask) |
Set stencil compare mask. More... | |
KAPI void | renderer_set_stencil_write_mask (u32 write_mask) |
Set stencil write mask. More... | |
KAPI b8 | renderer_texture_resources_acquire (struct renderer_system_state *state, kname name, ktexture_type type, u32 width, u32 height, u8 channel_count, u8 mip_levels, u16 array_size, ktexture_flag_bits flags, khandle *out_renderer_texture_handle) |
KAPI void | renderer_texture_resources_release (struct renderer_system_state *state, khandle *handle) |
KAPI b8 | renderer_texture_resize (struct renderer_system_state *state, khandle renderer_texture_handle, 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 b8 | renderer_texture_write_data (struct renderer_system_state *state, khandle renderer_texture_handle, u32 offset, u32 size, const u8 *pixels) |
Writes the given data to the provided texture. More... | |
KAPI b8 | renderer_texture_read_data (struct renderer_system_state *state, khandle renderer_texture_handle, u32 offset, u32 size, u8 **out_memory) |
Reads the given data from the provided texture. More... | |
KAPI b8 | renderer_texture_read_pixel (struct renderer_system_state *state, khandle renderer_texture_handle, u32 x, u32 y, u8 **out_rgba) |
Reads a pixel from the provided texture at the given x/y coordinate. More... | |
KAPI void | renderer_default_texture_register (struct renderer_system_state *state, renderer_default_texture default_texture, khandle renderer_texture_handle) |
Registers a texture with the given handle to the default texture slot specified. More... | |
KAPI khandle | renderer_default_texture_get (struct renderer_system_state *state, renderer_default_texture default_texture) |
Gets a texture handle with the default texture slot specified. More... | |
KAPI renderbuffer * | renderer_renderbuffer_get (renderbuffer_type type) |
Attempts retrieve the renderer's internal buffer of the given type. More... | |
KAPI b8 | renderer_geometry_upload (kgeometry *geometry) |
Acquires GPU resources and uploads geometry data. More... | |
KAPI void | renderer_geometry_vertex_update (kgeometry *g, u32 offset, u32 vertex_count, void *vertices, b8 include_in_frame_workload) |
Updates vertex data in the given geometry with the provided data in the given range. More... | |
KAPI void | renderer_geometry_destroy (kgeometry *geometry) |
Destroys the given geometry, releasing GPU resources. More... | |
KAPI void | renderer_geometry_draw (geometry_render_data *data) |
Draws the given geometry. More... | |
KAPI void | renderer_clear_colour_set (struct renderer_system_state *state, vec4 colour) |
Sets the value to be used on the colour buffer clear. More... | |
KAPI void | renderer_clear_depth_set (struct renderer_system_state *state, f32 depth) |
Sets the value to be used on the depth buffer clear. More... | |
KAPI void | renderer_clear_stencil_set (struct renderer_system_state *state, u32 stencil) |
Sets the value to be used on the stencil buffer clear. More... | |
KAPI b8 | renderer_clear_colour (struct renderer_system_state *state, khandle texture_handle) |
Clears the colour buffer using the previously set clear colour. More... | |
KAPI b8 | renderer_clear_depth_stencil (struct renderer_system_state *state, khandle texture_handle) |
Clears the depth/stencil buffer using the previously set clear values. More... | |
KAPI void | renderer_colour_texture_prepare_for_present (struct renderer_system_state *state, khandle texture_handle) |
Performs operations required on the supplied colour texture before presentation. More... | |
KAPI void | renderer_texture_prepare_for_sampling (struct renderer_system_state *state, khandle texture_handle, ktexture_flag_bits flags) |
Performs operations required on the supplied texture before being used for sampling. More... | |
KAPI b8 | renderer_shader_create (struct renderer_system_state *state, khandle shader, kname name, shader_flags flags, u32 topology_types, face_cull_mode cull_mode, u32 stage_count, shader_stage *stages, kname *stage_names, const char **stage_sources, u32 max_groups, u32 max_draw_ids, u32 attribute_count, const shader_attribute *attributes, u32 uniform_count, const shader_uniform *d_uniforms) |
Creates internal shader resources using the provided parameters. More... | |
KAPI void | renderer_shader_destroy (struct renderer_system_state *state, khandle shader) |
Destroys the given shader and releases any resources held by it. More... | |
KAPI b8 | renderer_shader_reload (struct renderer_system_state *state, khandle shader, u32 stage_count, shader_stage *stages, kname *names, const char **sources) |
Reloads the internals of the given shader. More... | |
KAPI b8 | renderer_shader_use (struct renderer_system_state *state, khandle shader) |
Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls. More... | |
KAPI b8 | renderer_shader_supports_wireframe (struct renderer_system_state *state, khandle shader) |
Determines if the given shader supports wireframe mode. More... | |
KAPI b8 | renderer_shader_flag_get (struct renderer_system_state *state, khandle shader, shader_flags flag) |
Indicates if the given shader flag is set. More... | |
KAPI void | renderer_shader_flag_set (struct renderer_system_state *state, khandle shader, shader_flags flag, b8 enabled) |
Sets the given shader flag. More... | |
KAPI b8 | renderer_shader_bind_per_frame (struct renderer_system_state *state, khandle shader) |
Binds the per-frame frequency. More... | |
KAPI b8 | renderer_shader_bind_per_group (struct renderer_system_state *state, khandle shader, u32 group_id) |
Binds the given per-group frequency id. More... | |
KAPI b8 | renderer_shader_bind_per_draw (struct renderer_system_state *state, khandle shader, u32 draw_id) |
Binds the given per-draw frequency id. More... | |
KAPI b8 | renderer_shader_apply_per_frame (struct renderer_system_state *state, khandle shader) |
Applies per-frame data to the uniform buffer. More... | |
KAPI b8 | renderer_shader_apply_per_group (struct renderer_system_state *state, khandle shader) |
Applies data for the currently bound group. More... | |
KAPI b8 | renderer_shader_apply_per_draw (struct renderer_system_state *state, khandle shader) |
Triggers the upload of per-draw uniform data to the GPU. More... | |
KAPI b8 | renderer_shader_per_group_resources_acquire (struct renderer_system_state *state, khandle shader, u32 *out_group_id) |
Acquires internal per-group resources and provides a group id. More... | |
KAPI b8 | renderer_shader_per_group_resources_release (struct renderer_system_state *state, khandle shader, u32 group_id) |
Releases internal per-group resources for the given group id. More... | |
KAPI b8 | renderer_shader_per_draw_resources_acquire (struct renderer_system_state *state, khandle shader, u32 *out_draw_id) |
Acquires internal per-draw resources and provides a per-draw id. More... | |
KAPI b8 | renderer_shader_per_draw_resources_release (struct renderer_system_state *state, khandle shader, u32 draw_id) |
Releases internal per-draw resources for the given per-draw id. More... | |
KAPI b8 | renderer_shader_uniform_set (struct renderer_system_state *state, khandle shader, struct shader_uniform *uniform, u32 array_index, const void *value) |
Sets the uniform of the given shader to the provided value. More... | |
KAPI khandle | renderer_generic_sampler_get (struct renderer_system_state *state, shader_generic_sampler sampler) |
Gets a handle to a generic sampler of the given type. More... | |
KAPI khandle | renderer_sampler_acquire (struct renderer_system_state *state, kname name, texture_filter filter, texture_repeat repeat, f32 anisotropy) |
Acquires a internal sampler and returns a handle to it. More... | |
KAPI void | renderer_sampler_release (struct renderer_system_state *state, khandle *sampler) |
Releases the internal sampler for the given handle. More... | |
KAPI b8 | renderer_sampler_refresh (struct renderer_system_state *state, khandle *sampler, texture_filter filter, texture_repeat repeat, f32 anisotropy, u32 mip_levels) |
Recreates the internal sampler pointed to by the given handle. Modifies the handle. More... | |
KAPI kname | renderer_sampler_name_get (struct renderer_system_state *state, khandle sampler) |
Attempts to obtain the name of a sampler with the given handle. Returns INVALID_KNAME if not found. 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 f32 | renderer_max_anisotropy_get (void) |
Obtains the max anisotropy level available from the renderer. 0 means not available. 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, b8 include_in_frame_workload) |
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, b8 include_in_frame_workload) |
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 viewport * | renderer_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... | |
KAPI void | renderer_wait_for_idle (void) |
KAPI b8 | renderer_pcf_enabled (struct renderer_system_state *state) |
KAPI u16 | renderer_max_bound_texture_count_get (struct renderer_system_state *state) |
Returns the max number of textures that can be bound at once for a single draw call. More... | |
KAPI u16 | renderer_max_bound_sampler_count_get (struct renderer_system_state *state) |
Returns the max number of samplers that can be bound at once for a single draw call. More... | |
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.
The lifecycle of a single frame (including mult. monitors) should look something like this:
frame_prepare - Increments renderer frame number
frame_prepare_window_surface - verifies swapchain, gets image index, etc. frame_commands_begin - begins command list/buffer <insert renderpasses, draws, etc. here> frame_commands_end - ends command list/buffer frame_submit - submits command list/buffer for execution. frame_present - once frame execution is complete, presents swapchain image.
typedef struct renderer_system_config renderer_system_config |
Returns a pointer to the currently active viewport.
Sets the currently active viewport.
viewport | A pointer to the viewport to be set. |
Begins the marking of a section of commands, listed under a given name and colour. Becomes a no-op in non-debug builds. NOTE: Each renderer backend will have different or possibly non-existant implementations of this.
label_text | The text to be used for the label. |
colour | The colour to be used for the label. |
KAPI void renderer_begin_rendering | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data, | ||
rect_2d | render_area, | ||
u32 | colour_target_count, | ||
khandle * | colour_targets, | ||
khandle | depth_stencil_target, | ||
u32 | depth_stencil_layer | ||
) |
Begins rendering against the given targets.
state | A pointer to the renderer system state. |
p_frame_data | A pointer to the current frame data. |
render_area | A rectangle representing the area of the attachments to render to. |
colour_target_count | The number of colour targets to be drawn to. |
colour_targets | An array of handles to colour targets. Required unless colour_target_count is 0. |
depth_stencil_target | A handle to a depth stencil target to render to. |
depth_stencil_layer | For layered depth targets, the layer index to render to. Ignored otherwise. |
Clears the colour buffer using the previously set clear colour.
state | A pointer to the renderer system state. |
texture_handle | A handle to the texture to clear. |
Sets the value to be used on the colour buffer clear.
state | A pointer to the renderer system state. |
colour | the RGBA colour to be used for the next clear operation. Each element is clamped to [0-1] |
Sets the value to be used on the depth buffer clear.
state | A pointer to the renderer system state. |
depth | The depth value to be used for the next clear operation. Clamped to [0-1]. |
KAPI b8 renderer_clear_depth_stencil | ( | struct renderer_system_state * | state, |
khandle | texture_handle | ||
) |
Clears the depth/stencil buffer using the previously set clear values.
state | A pointer to the renderer system state. |
texture_handle | A handle to the texture to clear. |
Sets the value to be used on the stencil buffer clear.
state | A pointer to the renderer system state. |
stencil | The depth value to be used for the next clear operation. |
KAPI void renderer_colour_texture_prepare_for_present | ( | struct renderer_system_state * | state, |
khandle | texture_handle | ||
) |
Performs operations required on the supplied colour texture before presentation.
state | A pointer to the renderer system state. |
texture_handle | A handle to the texture to prepare for presentation. |
KAPI void renderer_cull_mode_set | ( | renderer_cull_mode | cull_mode | ) |
Set the renderer to use the given cull mode.
cull_mode | The cull mode. |
KAPI khandle renderer_default_texture_get | ( | struct renderer_system_state * | state, |
renderer_default_texture | default_texture | ||
) |
Gets a texture handle with the default texture slot specified.
state | A pointer to the renderer system state. |
default_texture | The texture slot to register to. |
KAPI void renderer_default_texture_register | ( | struct renderer_system_state * | state, |
renderer_default_texture | default_texture, | ||
khandle | renderer_texture_handle | ||
) |
Registers a texture with the given handle to the default texture slot specified.
state | A pointer to the renderer system state. |
default_texture | The texture slot to register to. |
renderer_texture_handle | A handle to the texture to be registered. |
KAPI void renderer_end_debug_label | ( | void | ) |
Ends the last debug section of commands. Becomes a no-op in non-debug builds. NOTE: Each renderer backend will have different or possibly non-existant implementations of this.
KAPI void renderer_end_rendering | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data | ||
) |
state | A pointer to the renderer system state. |
p_frame_data | A pointer to the current frame data. |
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.
flag | The flag to be checked. |
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.
flag | The flag to be checked. |
enabled | Indicates whether or not to enable the flag(s). |
KAPI b8 renderer_frame_command_list_begin | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data | ||
) |
Begins a render. There must be at least one of these and a matching end per frame.
p_frame_data | A pointer to the current frame's data. |
KAPI b8 renderer_frame_command_list_end | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data | ||
) |
Ends a render.
p_frame_data | A pointer to the current frame's data. |
KAPI b8 renderer_frame_prepare | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data | ||
) |
Performs setup routines required at the start of a frame.
p_frame_data | A pointer to the current frame's data. |
KAPI b8 renderer_frame_prepare_window_surface | ( | struct renderer_system_state * | state, |
struct kwindow * | window, | ||
struct frame_data * | p_frame_data | ||
) |
Prepares a window's surface for drawing.
p_frame_data | A pointer to the current frame's data. d |
KAPI b8 renderer_frame_present | ( | struct renderer_system_state * | state, |
struct kwindow * | window, | ||
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.
p_frame_data | A constant pointer to the current frame's data. |
KAPI b8 renderer_frame_submit | ( | struct renderer_system_state * | state, |
struct frame_data * | p_frame_data | ||
) |
KAPI khandle renderer_generic_sampler_get | ( | struct renderer_system_state * | state, |
shader_generic_sampler | sampler | ||
) |
Gets a handle to a generic sampler of the given type.
state | A pointer to the renderer state. |
sampler | The shader sampler to get a handle to. |
Destroys the given geometry, releasing GPU resources.
geometry | A pointer to the geometry to be destroyed. |
KAPI void renderer_geometry_draw | ( | geometry_render_data * | data | ) |
Draws the given geometry.
data | The render data of the geometry to be drawn. |
Acquires GPU resources and uploads geometry data.
geometry | A pointer to the geometry to upload. |
KAPI void renderer_geometry_vertex_update | ( | kgeometry * | g, |
u32 | offset, | ||
u32 | vertex_count, | ||
void * | vertices, | ||
b8 | include_in_frame_workload | ||
) |
Updates vertex data in the given geometry with the provided data in the given range.
g | A pointer to the geometry to be created. |
offset | The offset in bytes to update. 0 if updating from the beginning. |
vertex_count | The number of vertices which will be updated. |
vertices | The vertex data. |
Obtains the max anisotropy level available from the renderer. 0 means not available.
Returns the max number of samplers that can be bound at once for a single draw call.
Returns the max number of textures that can be bound at once for a single draw call.
KAPI b8 renderer_on_window_created | ( | struct renderer_system_state * | state, |
struct kwindow * | window | ||
) |
KAPI void renderer_on_window_destroyed | ( | struct renderer_system_state * | state, |
struct kwindow * | window | ||
) |
KAPI void renderer_on_window_resized | ( | struct renderer_system_state * | state, |
const struct kwindow * | window | ||
) |
Handles window resize events.
state | A pointer to the state block of memory. |
window | A const pointer to the window that was resized. |
Indicates if PCF filtering is enabled for shadow maps.
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.
buffer | A pointer to the buffer to be allocated from. |
size | The size in bytes to allocate. |
out_offset | A pointer to hold the offset in bytes of the allocation from the beginning of the buffer. |
KAPI b8 renderer_renderbuffer_bind | ( | renderbuffer * | buffer, |
u64 | offset | ||
) |
Binds the given buffer at the provided offset.
buffer | A pointer to the buffer to bind. |
offset | The offset in bytes from the beginning of the buffer. |
KAPI b8 renderer_renderbuffer_clear | ( | renderbuffer * | buffer, |
b8 | zero_memory | ||
) |
Clears the given buffer. Internally, resets the free list if one is used.
buffer | A pointer to the buffer to be freed from. |
zero_memory | True if memory should be zeroed; otherwise false. NOTE: this can be an expensive operation on large sums of memory. |
KAPI b8 renderer_renderbuffer_copy_range | ( | renderbuffer * | source, |
u64 | source_offset, | ||
renderbuffer * | dest, | ||
u64 | dest_offset, | ||
u64 | size, | ||
b8 | include_in_frame_workload | ||
) |
Copies data in the specified rage fron the source to the destination buffer.
source | A pointer to the source buffer to copy data from. |
source_offset | The offset in bytes from the beginning of the source buffer. |
dest | A pointer to the destination buffer to copy data to. |
dest_offset | The offset in bytes from the beginning of the destination buffer. |
size | The size of the data in bytes to be copied. |
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.
name | The name of the renderbuffer, used for debugging purposes. |
type | The type of buffer, indicating it's use (i.e. vertex/index data, uniforms, etc.) |
total_size | The total size in bytes of the buffer. |
track_type | Indicates what type of allocation tracking should be used. |
out_buffer | A pointer to hold the newly created buffer. |
KAPI void renderer_renderbuffer_destroy | ( | renderbuffer * | buffer | ) |
Destroys the given renderbuffer.
buffer | A pointer to the buffer to be destroyed. |
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.
buffer | A pointer to the buffer to be drawn. |
offset | The offset in bytes from the beginning of the buffer. |
element_count | The number of elements to be drawn. |
bind_only | Only bind the buffer, but don't draw. |
KAPI b8 renderer_renderbuffer_flush | ( | renderbuffer * | buffer, |
u64 | offset, | ||
u64 | size | ||
) |
Flushes buffer memory at the given range. Should be done after a write.
buffer | A pointer to the buffer to unmap. |
offset | The number of bytes from the beginning of the buffer to flush. |
size | The amount of memory in the buffer to flush. |
KAPI b8 renderer_renderbuffer_free | ( | renderbuffer * | buffer, |
u64 | size, | ||
u64 | offset | ||
) |
Frees memory from the given buffer.
buffer | A pointer to the buffer to be freed from. |
size | The size in bytes to free. |
offset | The offset in bytes from the beginning of the buffer to free. |
KAPI renderbuffer* renderer_renderbuffer_get | ( | renderbuffer_type | type | ) |
Attempts retrieve the renderer's internal buffer of the given type.
type | The type of buffer to retrieve. @returnshader A handle to the buffer on success; otherwise 0/null. |
KAPI b8 renderer_renderbuffer_load_range | ( | renderbuffer * | buffer, |
u64 | offset, | ||
u64 | size, | ||
const void * | data, | ||
b8 | include_in_frame_workload | ||
) |
Loads provided data into the specified rage of the given buffer.
buffer | A pointer to the buffer to load data into. |
offset | The offset in bytes from the beginning of the buffer. |
size | The size of the data in bytes to be loaded. |
data | The data to be loaded. |
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.
buffer | A pointer to the buffer to map. |
offset | The number of bytes from the beginning of the buffer to map. |
size | The amount of memory in the buffer to map. |
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.
buffer | A pointer to the buffer to read from. |
offset | The number of bytes from the beginning of the buffer to read. |
size | The amount of memory in the buffer to read. |
out_memory | A pointer to a block of memory to read to. Must be of appropriate size. |
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.
buffer | A pointer to the buffer to be resized. |
new_total_size | The new size in bytes. Must be larger than the current size. |
KAPI b8 renderer_renderbuffer_unbind | ( | renderbuffer * | buffer | ) |
Unbinds the given buffer.
buffer | A pointer to the buffer to be unbound. |
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.
buffer | A pointer to the buffer to unmap. |
offset | The number of bytes from the beginning of the buffer to unmap. |
size | The amount of memory in the buffer to unmap. |
KAPI khandle renderer_sampler_acquire | ( | struct renderer_system_state * | state, |
kname | name, | ||
texture_filter | filter, | ||
texture_repeat | repeat, | ||
f32 | anisotropy | ||
) |
Acquires a internal sampler and returns a handle to it.
state | A pointer to the renderer state. |
name | The name of the sampler. |
filter | The min/mag filter. |
repeat | The repeat mode. |
anisotropy | The anisotropy level, if needed; otherwise 0. |
Attempts to obtain the name of a sampler with the given handle. Returns INVALID_KNAME if not found.
state | A pointer to the renderer state. |
sampler | A handle to the sampler whose name to get. |
KAPI b8 renderer_sampler_refresh | ( | struct renderer_system_state * | state, |
khandle * | sampler, | ||
texture_filter | filter, | ||
texture_repeat | repeat, | ||
f32 | anisotropy, | ||
u32 | mip_levels | ||
) |
Recreates the internal sampler pointed to by the given handle. Modifies the handle.
state | A pointer to the renderer state. |
sampler | A pointer to the handle of the sampler to be refreshed. |
filter | The min/mag filter. |
repeat | The repeat mode. |
anisotropy | The anisotropy level, if needed; otherwise 0. |
mip_levels | The mip levels, if used; otherwise 0. |
Releases the internal sampler for the given handle.
state | A pointer to the renderer state. |
map | A pointer to the handle whose sampler is to be released. Handle is invalidated upon release. |
KAPI void renderer_scissor_reset | ( | void | ) |
Resets the scissor to the default, which matches the application window.
Sets the renderer scissor to the given rectangle.
rect | The scissor rectangle to be set. |
Set depth testing enabled/disabled.
enabled | Indicates if depth testing should be enabled/disabled for subsequent draws. |
Set depth write enabled/disabled.
enabled | Indicates if depth write should be enabled/disabled for subsequent draws. |
Set stencil compare mask.
compare_mask | The new value to use as the stencil compare mask. |
KAPI void renderer_set_stencil_op | ( | renderer_stencil_op | fail_op, |
renderer_stencil_op | pass_op, | ||
renderer_stencil_op | depth_fail_op, | ||
renderer_compare_op | compare_op | ||
) |
Set stencil operation.
fail_op | Specifys the action performed on samples that fail the stencil test. |
pass_op | Specifys the action performed on samples that pass both the depth and stencil tests. |
depth_fail_op | Specifys the action performed on samples that pass the stencil test and fail the depth test. |
compare_op | Specifys the comparison operator used in the stencil test. |
Set the stencil reference for testing.
reference | The reference to use when stencil testing/writing. |
Set stencil testing enabled/disabled.
enabled | Indicates if stencil testing should be enabled/disabled for subsequent draws. |
Set stencil write mask.
write_mask | The new value to use as the stencil write mask. |
Triggers the upload of per-draw uniform data to the GPU.
state | A pointer to the renderer state. |
shader | A handle to the shader. |
Applies per-frame data to the uniform buffer.
state | A pointer to the renderer state. |
shader | A handle to the shader to apply the global data for. |
Applies data for the currently bound group.
state | A pointer to the renderer state. |
shader | A handle to the shader to apply the instance data for. |
KAPI b8 renderer_shader_bind_per_draw | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 | draw_id | ||
) |
Binds the given per-draw frequency id.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
draw_id | The per-draw frequency id. |
Binds the per-frame frequency.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
KAPI b8 renderer_shader_bind_per_group | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 | group_id | ||
) |
Binds the given per-group frequency id.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
group_id | The per-group frequency id. |
KAPI b8 renderer_shader_create | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
kname | name, | ||
shader_flags | flags, | ||
u32 | topology_types, | ||
face_cull_mode | cull_mode, | ||
u32 | stage_count, | ||
shader_stage * | stages, | ||
kname * | stage_names, | ||
const char ** | stage_sources, | ||
u32 | max_groups, | ||
u32 | max_draw_ids, | ||
u32 | attribute_count, | ||
const shader_attribute * | attributes, | ||
u32 | uniform_count, | ||
const shader_uniform * | d_uniforms | ||
) |
Creates internal shader resources using the provided parameters.
state | A pointer to the renderer state. |
shader | A handle to the shader. |
shader_asset | A constant pointer to the shader asset. |
Destroys the given shader and releases any resources held by it.
state | A pointer to the renderer state. |
shader | A handle to the shader to be destroyed. |
KAPI b8 renderer_shader_flag_get | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
shader_flags | flag | ||
) |
Indicates if the given shader flag is set.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
flag | The flag to check. |
KAPI void renderer_shader_flag_set | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
shader_flags | flag, | ||
b8 | enabled | ||
) |
Sets the given shader flag.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
flag | The flag to set. |
enabled | Indicates whether the flag should be set or unset. |
KAPI b8 renderer_shader_per_draw_resources_acquire | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 * | out_draw_id | ||
) |
Acquires internal per-draw resources and provides a per-draw id.
state | A pointer to the renderer state. |
shader | A handle to the shader to acquire resources from. |
texture_map_count | The number of texture maps used. |
maps | An array of pointers to texture maps. Must be one map for each per-group texture. |
out_draw_id | A pointer to hold the new per-draw identifier. |
KAPI b8 renderer_shader_per_draw_resources_release | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 | draw_id | ||
) |
Releases internal per-draw resources for the given per-draw id.
state | A pointer to the renderer state. |
shader | A handle to the shader to release resources from. |
draw_id | The per-draw identifier whose resources are to be released. |
KAPI b8 renderer_shader_per_group_resources_acquire | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 * | out_group_id | ||
) |
Acquires internal per-group resources and provides a group id.
state | A pointer to the renderer state. |
shader | A handle to the shader to acquire resources from. |
config | A constant pointer to the configuration of the group to be used while acquiring resources. |
out_group_id | A pointer to hold the new per-group identifier. |
KAPI b8 renderer_shader_per_group_resources_release | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 | group_id | ||
) |
Releases internal per-group resources for the given group id.
state | A pointer to the renderer state. |
shader | A handle to the shader to release resources from. |
group_id | The per-group identifier whose resources are to be released. |
KAPI b8 renderer_shader_reload | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
u32 | stage_count, | ||
shader_stage * | stages, | ||
kname * | names, | ||
const char ** | sources | ||
) |
Reloads the internals of the given shader.
state | A pointer to the renderer state. |
shader | A handle to the shader to be reloaded. |
shader_stage_count | The number of shader stages. |
shader_stages | An array of shader stages configs. |
Determines if the given shader supports wireframe mode.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
KAPI b8 renderer_shader_uniform_set | ( | struct renderer_system_state * | state, |
khandle | shader, | ||
struct shader_uniform * | uniform, | ||
u32 | array_index, | ||
const void * | value | ||
) |
Sets the uniform of the given shader to the provided value.
state | A pointer to the renderer state. |
shader | A handle to the shader. |
uniform | A constant pointer to the uniform. |
array_index | The index of the uniform array to be set, if it is an array. For non-array types, this value is ignored. |
value | A pointer to the value to be set. |
Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls.
state | A pointer to the renderer state. |
shader | A handle to the shader to be used. |
b8 renderer_system_deserialize_config | ( | const char * | config_str, |
renderer_system_config * | out_config | ||
) |
KAPI b8 renderer_system_initialize | ( | u64 * | memory_requirement, |
struct renderer_system_state * | state, | ||
const renderer_system_config * | 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.
memory_requirement | A pointer to hold the memory requirement for this system. |
state | A block of memory to hold state data, or 0 if obtaining memory requirement. |
config | A constant pointer to the configuration for the renderer. |
KAPI void renderer_system_shutdown | ( | struct renderer_system_state * | state | ) |
Shuts the renderer system/frontend down.
state | A pointer to the state block of memory. |
KAPI void renderer_texture_prepare_for_sampling | ( | struct renderer_system_state * | state, |
khandle | texture_handle, | ||
ktexture_flag_bits | flags | ||
) |
Performs operations required on the supplied texture before being used for sampling.
state | A pointer to the renderer system state. |
texture_handle | A handle to the texture to prepare for sampling. |
flags | Texture flags from the texture itself, used to determine format/layout, etc. |
KAPI b8 renderer_texture_read_data | ( | struct renderer_system_state * | state, |
khandle | renderer_texture_handle, | ||
u32 | offset, | ||
u32 | size, | ||
u8 ** | out_memory | ||
) |
Reads the given data from the provided texture.
state | A pointer to the renderer system state. |
renderer_texture_handle | A handle to the texture to be read from. |
offset | The offset in bytes from the beginning of the data to be read. |
size | The number of bytes to be read. |
out_pixelshader | A handle to a block of memory to write the read data to. |
KAPI b8 renderer_texture_read_pixel | ( | struct renderer_system_state * | state, |
khandle | renderer_texture_handle, | ||
u32 | x, | ||
u32 | y, | ||
u8 ** | out_rgba | ||
) |
Reads a pixel from the provided texture at the given x/y coordinate.
state | A pointer to the renderer system state. |
renderer_texture_handle | A handle to the texture to be read from. |
x | The pixel x-coordinate. |
y | The pixel y-coordinate. |
out_rgba | A pointer to an array of u8s to hold the pixel data (should be sizeof(u8) * 4) |
KAPI b8 renderer_texture_resize | ( | struct renderer_system_state * | state, |
khandle | renderer_texture_handle, | ||
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.
state | A pointer to the renderer system state. |
renderer_texture_handle | A handle to the texture to be resized. |
new_width | The new width in pixels. |
new_height | The new height in pixels. |
KAPI b8 renderer_texture_resources_acquire | ( | struct renderer_system_state * | state, |
kname | name, | ||
ktexture_type | type, | ||
u32 | width, | ||
u32 | height, | ||
u8 | channel_count, | ||
u8 | mip_levels, | ||
u16 | array_size, | ||
ktexture_flag_bits | flags, | ||
khandle * | out_renderer_texture_handle | ||
) |
Attempts to acquire renderer-specific resources to back a texture.
state | A pointer to the renderer system state. |
name | The name of the texture. |
type | The type of texture. |
width | The texture width in pixels. |
height | The texture height in pixels. |
channel_count | The number of channels in the texture (i.e. RGBA = 4) |
mip_levels | The number of mip maps the internal texture has. Must always be at least 1. |
array_size | For arrayed textures, how many "layers" there are. Otherwise this is 1. |
flags | Various property flags to be used in creating this texture. |
out_renderer_texture_handle | A pointer to hold the renderer texture handle, which points to the backing resource(s) of the texture. |
KAPI void renderer_texture_resources_release | ( | struct renderer_system_state * | state, |
khandle * | handle | ||
) |
Releases backing renderer-specific resources for the given renderer_texture_id.
state | A pointer to the renderer system state. |
handle | A pointer to the handle of the renderer texture whose resources are to be released. Handle is automatically invalidated. |
KAPI b8 renderer_texture_write_data | ( | struct renderer_system_state * | state, |
khandle | renderer_texture_handle, | ||
u32 | offset, | ||
u32 | size, | ||
const u8 * | pixels | ||
) |
Writes the given data to the provided texture.
state | A pointer to the renderer system state. |
renderer_texture_handle | A handle to the texture to be written to. NOTE: Must be a writeable texture. |
offset | The offset in bytes from the beginning of the data to be written. |
size | The number of bytes to be written. |
pixels | The raw image data to be written. |
KAPI void renderer_viewport_reset | ( | void | ) |
Resets the viewport to the default, which matches the application window.
Sets the renderer viewport to the given rectangle.
rect | The viewport rectangle to be set. |
KAPI void renderer_wait_for_idle | ( | void | ) |
Waits for the renderer backend to be completely idle of work before returning. NOTE: This incurs a lot of overhead/waits, and should be used sparingly.
KAPI void renderer_winding_set | ( | renderer_winding | winding | ) |
Set the renderer to use the given winding direction.
winding | The winding direction. |