|
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 <math/geometry.h>#include <strings/kname.h>#include "core/frame_data.h"#include "core_render_types.h"#include "math/math_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) |
| void | renderer_system_destroy_config (renderer_system_config *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 (rect_2di 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 (rect_2di 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_depth_bias (f32 constant_factor, f32 clamp, f32 slope_factor) |
| Sets depth bias factors and clamp dynamically. More... | |
| KAPI void | renderer_set_depth_bias_enabled (b8 enabled) |
| Enables/disables depth bias. 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_2di render_area, u32 colour_target_count, ktexture *colour_targets, ktexture 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, ktexture t, kname name, ktexture_type type, u32 width, u32 height, u8 channel_count, u8 mip_levels, u16 array_size, ktexture_flag_bits flags) |
| KAPI void | renderer_texture_resources_release (struct renderer_system_state *state, ktexture t) |
| KAPI b8 | renderer_texture_resize (struct renderer_system_state *state, ktexture 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 b8 | renderer_texture_write_data (struct renderer_system_state *state, ktexture t, 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, ktexture t, 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, ktexture t, 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, ktexture t) |
| Registers a texture with the given handle to the default texture slot specified. More... | |
| KAPI ktexture | 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 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. NOTE: Does NOT release index and vertex data arrays. Call geometry_destroy() to do that. 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, ktexture t) |
| Clears the colour buffer using the previously set clear colour. More... | |
| KAPI b8 | renderer_clear_depth_stencil (struct renderer_system_state *state, ktexture t) |
| 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, ktexture t) |
| Performs operations required on the supplied colour texture before presentation. More... | |
| KAPI void | renderer_texture_prepare_for_sampling (struct renderer_system_state *state, ktexture t, 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, kshader shader, kname name, shader_flags flags, primitive_topology_type_bits topology_types, primitive_topology_type default_topology, u8 colour_attachment_count, kpixel_format *colour_attachment_formats, kpixel_format depth_attachment_format, kpixel_format stencil_attachment_format, u8 pipeline_count, shader_pipeline_config *pipelines, u8 binding_set_count, const shader_binding_set_config *binding_sets) |
| Creates internal shader resources using the provided parameters. More... | |
| KAPI void | renderer_shader_destroy (struct renderer_system_state *state, kshader shader) |
| Destroys the given shader and releases any resources held by it. More... | |
| KAPI b8 | renderer_shader_reload (struct renderer_system_state *state, kshader shader, u8 pipeline_count, shader_pipeline_config *pipelines) |
| Reloads the internals of the given shader. More... | |
| KAPI b8 | renderer_shader_use (struct renderer_system_state *state, kshader shader, u8 vertex_layout_index) |
| Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls. Uses the default topology configured by the shader. More... | |
| KAPI b8 | renderer_shader_use_with_topology (struct renderer_system_state *state, kshader shader, primitive_topology_type type, u8 vertex_layout_index) |
| Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls using the provided topology. More... | |
| KAPI b8 | renderer_shader_supports_wireframe (struct renderer_system_state *state, kshader shader) |
| Determines if the given shader supports wireframe mode. More... | |
| KAPI b8 | renderer_shader_flag_get (struct renderer_system_state *state, kshader shader, shader_flags flag) |
| Indicates if the given shader flag is set. More... | |
| KAPI void | renderer_shader_flag_set (struct renderer_system_state *state, kshader shader, shader_flags flag, b8 enabled) |
| Sets the given shader flag. More... | |
| KAPI void | renderer_shader_set_immediate_data (struct renderer_system_state *state, kshader shader, const void *data, u8 size) |
| KAPI void | renderer_shader_set_binding_data (struct renderer_system_state *state, kshader shader, u8 binding_set, u32 instance_id, u8 binding_index, u64 offset, void *data, u64 size) |
| KAPI void | renderer_shader_set_binding_texture (struct renderer_system_state *state, kshader shader, u8 binding_set, u32 instance_id, u8 binding_index, u8 array_index, ktexture texture) |
| KAPI void | renderer_shader_set_binding_sampler (struct renderer_system_state *state, kshader shader, u8 binding_set, u32 instance_id, u8 binding_index, u8 array_index, ksampler_backend sampler) |
| KAPI b8 | renderer_shader_apply_binding_set (struct renderer_system_state *state, kshader shader, u8 binding_set, u32 instance_id) |
| KAPI u32 | renderer_shader_acquire_binding_set_instance (struct renderer_system_state *state, kshader shader, u8 binding_set) |
| KAPI void | renderer_shader_release_binding_set_instance (struct renderer_system_state *state, kshader shader, u8 binding_set, u32 instance_id) |
| KAPI u32 | renderer_shader_binding_set_get_max_instance_count (struct renderer_system_state *state, kshader shader, u8 binding_set) |
| KAPI ksampler_backend | 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 ksampler_backend | 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, ksampler_backend *sampler) |
| Releases the internal sampler for the given handle. More... | |
| KAPI b8 | renderer_sampler_refresh (struct renderer_system_state *state, ksampler_backend *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, ksampler_backend 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 krenderbuffer | renderer_renderbuffer_create (struct renderer_system_state *state, kname name, renderbuffer_type type, u64 total_size, renderbuffer_track_type track_type, renderbuffer_flags) |
| 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 (struct renderer_system_state *state, krenderbuffer buffer) |
| Destroys the given renderbuffer. More... | |
| KAPI b8 | renderer_renderbuffer_bind (struct renderer_system_state *state, krenderbuffer buffer, u64 offset, u32 binding_index) |
| Binds the given buffer at the provided offset. More... | |
| KAPI b8 | renderer_renderbuffer_unbind (struct renderer_system_state *state, krenderbuffer buffer) |
| Unbinds the given buffer. More... | |
| KAPI void | renderer_renderbuffer_map_memory (struct renderer_system_state *state, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer 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 void * | renderer_renderbuffer_get_mapped_memory (struct renderer_system_state *state, krenderbuffer buffer) |
| Obtains the mapped memory of the buffer, if mapped. This memory should be considered invalid once unmapped. More... | |
| KAPI b8 | renderer_renderbuffer_flush (struct renderer_system_state *state, krenderbuffer buffer, u64 offset, u64 size) |
| Flushes buffer memory at the given range. Should be done after a write. More... | |
| KAPI b8 | renderer_renderbuffer_read (struct renderer_system_state *state, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer buffer, u64 size, u64 offset) |
| Frees memory from the given buffer. More... | |
| KAPI b8 | renderer_renderbuffer_clear (struct renderer_system_state *state, krenderbuffer buffer, b8 zero_memory) |
| Clears the given buffer. Internally, resets the free list if one is used. More... | |
| KAPI b8 | renderer_renderbuffer_load_range (struct renderer_system_state *state, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer source, u64 source_offset, krenderbuffer 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 (struct renderer_system_state *state, krenderbuffer buffer, u64 offset, u32 element_count, u32 binding_index, 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 krenderbuffer | renderer_renderbuffer_get (struct renderer_system_state *state, kname name) |
| Attempts retrieve the renderer's internal buffer of the given name. 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 |
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_2di | render_area, | ||
| u32 | colour_target_count, | ||
| ktexture * | colour_targets, | ||
| ktexture | 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. |
| t | 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]. |
Clears the depth/stencil buffer using the previously set clear values.
| state | A pointer to the renderer system state. |
| t | 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, |
| ktexture | t | ||
| ) |
Performs operations required on the supplied colour texture before presentation.
| state | A pointer to the renderer system state. |
| t | 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 ktexture 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, | ||
| ktexture | t | ||
| ) |
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. |
| t | 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 ksampler_backend 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. NOTE: Does NOT release index and vertex data arrays. Call geometry_destroy() to do that.
| 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | 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.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | offset, | ||
| u32 | binding_index | ||
| ) |
Binds the given buffer at the provided offset.
| state | A pointer to the renderer state. |
| buffer | A handle to the buffer to bind. |
| offset | The offset in bytes from the beginning of the buffer. |
| binding_index | The index of which to bind the buffer. Unless using multiple buffers of the same time, pass 0 here. |
| KAPI b8 renderer_renderbuffer_clear | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| b8 | zero_memory | ||
| ) |
Clears the given buffer. Internally, resets the free list if one is used.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | source, | ||
| u64 | source_offset, | ||
| krenderbuffer | dest, | ||
| u64 | dest_offset, | ||
| u64 | size, | ||
| b8 | include_in_frame_workload | ||
| ) |
Copies data in the specified rage fron the source to the destination buffer.
| state | A pointer to the renderer state. |
| source | A handle 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 krenderbuffer renderer_renderbuffer_create | ( | struct renderer_system_state * | state, |
| kname | name, | ||
| renderbuffer_type | type, | ||
| u64 | total_size, | ||
| renderbuffer_track_type | track_type, | ||
| renderbuffer_flags | |||
| ) |
Creates a new renderbuffer to hold data for a given purpose/use. Backed by a renderer-backend-specific buffer resource.
| state | A pointer to the renderer state. |
| name | The name of the renderbuffer. |
| 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. |
| KAPI void renderer_renderbuffer_destroy | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer | ||
| ) |
Destroys the given renderbuffer.
| state | A pointer to the renderer state. |
| buffer | A handle to the buffer to be destroyed. |
| KAPI b8 renderer_renderbuffer_draw | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | offset, | ||
| u32 | element_count, | ||
| u32 | binding_index, | ||
| 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.
| state | A pointer to the renderer state. |
| buffer | A handle 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. |
| binding_index | The index of which to bind the buffer. Unless using multiple buffers of the same time, pass 0 here. |
| bind_only | Only bind the buffer, but don't draw. |
| KAPI b8 renderer_renderbuffer_flush | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | offset, | ||
| u64 | size | ||
| ) |
Flushes buffer memory at the given range. Should be done after a write.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | size, | ||
| u64 | offset | ||
| ) |
Frees memory from the given buffer.
| state | A pointer to the renderer state. |
| buffer | A handle 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 krenderbuffer renderer_renderbuffer_get | ( | struct renderer_system_state * | state, |
| kname | name | ||
| ) |
Attempts retrieve the renderer's internal buffer of the given name.
| state | A pointer to the renderer state. |
| type | The name of buffer to retrieve. @returnshader A handle to the buffer on success; otherwise 0/null. |
| KAPI void* renderer_renderbuffer_get_mapped_memory | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer | ||
| ) |
Obtains the mapped memory of the buffer, if mapped. This memory should be considered invalid once unmapped.
| state | A pointer to the renderer state. |
| buffer | A handle to the buffer whose mapped memory is to be obtained. |
| KAPI b8 renderer_renderbuffer_load_range | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | offset, | ||
| u64 | size, | ||
| const void * | data, | ||
| b8 | include_in_frame_workload | ||
| ) |
Loads provided data into the specified rage of the given buffer.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | 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.
| state | A pointer to the renderer state. |
| buffer | A handle 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. Use KWHOLE_SIZE to map the entire buffer. |
| KAPI b8 renderer_renderbuffer_read | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer, | ||
| u64 | offset, | ||
| u64 | size, | ||
| void ** | out_memory | ||
| ) |
Reads memory from the provided buffer at the given range to the output variable.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | 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.
| state | A pointer to the renderer state. |
| buffer | A handle 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 | ( | struct renderer_system_state * | state, |
| krenderbuffer | buffer | ||
| ) |
Unbinds the given buffer.
| state | A pointer to the renderer state. |
| buffer | A handle to the buffer to be unbound. |
| KAPI void renderer_renderbuffer_unmap_memory | ( | struct renderer_system_state * | state, |
| krenderbuffer | 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.
| state | A pointer to the renderer state. |
| buffer | A handle 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 ksampler_backend 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. |
| KAPI kname renderer_sampler_name_get | ( | struct renderer_system_state * | state, |
| ksampler_backend | sampler | ||
| ) |
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, |
| ksampler_backend * | 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. |
| KAPI void renderer_sampler_release | ( | struct renderer_system_state * | state, |
| ksampler_backend * | sampler | ||
| ) |
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. |
Sets depth bias factors and clamp dynamically.
| constant_factor | A scalar factor controlling the constant depth value added to each fragment. |
| clamp | The maximum (or minimum) depth bias of a fragment. |
| slope_factor | A scalar factor applied to a fragment’s slope in depth bias calculations. |
Enables/disables depth bias.
| enabled | True to enable; otherwise disable. |
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. |
| KAPI u32 renderer_shader_acquire_binding_set_instance | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set | ||
| ) |
| KAPI b8 renderer_shader_apply_binding_set | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set, | ||
| u32 | instance_id | ||
| ) |
| KAPI u32 renderer_shader_binding_set_get_max_instance_count | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set | ||
| ) |
| KAPI b8 renderer_shader_create | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| kname | name, | ||
| shader_flags | flags, | ||
| primitive_topology_type_bits | topology_types, | ||
| primitive_topology_type | default_topology, | ||
| u8 | colour_attachment_count, | ||
| kpixel_format * | colour_attachment_formats, | ||
| kpixel_format | depth_attachment_format, | ||
| kpixel_format | stencil_attachment_format, | ||
| u8 | pipeline_count, | ||
| shader_pipeline_config * | pipelines, | ||
| u8 | binding_set_count, | ||
| const shader_binding_set_config * | binding_sets | ||
| ) |
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, |
| kshader | 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, |
| kshader | 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 void renderer_shader_release_binding_set_instance | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set, | ||
| u32 | instance_id | ||
| ) |
| KAPI b8 renderer_shader_reload | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | pipeline_count, | ||
| shader_pipeline_config * | pipelines | ||
| ) |
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. |
| KAPI void renderer_shader_set_binding_data | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set, | ||
| u32 | instance_id, | ||
| u8 | binding_index, | ||
| u64 | offset, | ||
| void * | data, | ||
| u64 | size | ||
| ) |
| KAPI void renderer_shader_set_binding_sampler | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set, | ||
| u32 | instance_id, | ||
| u8 | binding_index, | ||
| u8 | array_index, | ||
| ksampler_backend | sampler | ||
| ) |
| KAPI void renderer_shader_set_binding_texture | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | binding_set, | ||
| u32 | instance_id, | ||
| u8 | binding_index, | ||
| u8 | array_index, | ||
| ktexture | texture | ||
| ) |
| KAPI void renderer_shader_set_immediate_data | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| const void * | data, | ||
| u8 | size | ||
| ) |
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_use | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| u8 | vertex_layout_index | ||
| ) |
Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls. Uses the default topology configured by the shader.
| state | A pointer to the renderer state. |
| shader | A handle to the shader to be used. |
| KAPI b8 renderer_shader_use_with_topology | ( | struct renderer_system_state * | state, |
| kshader | shader, | ||
| primitive_topology_type | type, | ||
| u8 | vertex_layout_index | ||
| ) |
Uses the given shader, activating it for updates to attributes, uniforms and such, and for use in draw calls using the provided topology.
| state | A pointer to the renderer state. |
| shader | A handle to the shader to be used. |
| type | The primitive topology type to use. |
| b8 renderer_system_deserialize_config | ( | const char * | config_str, |
| renderer_system_config * | out_config | ||
| ) |
| void renderer_system_destroy_config | ( | renderer_system_config * | 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, |
| ktexture | t, | ||
| ktexture_flag_bits | flags | ||
| ) |
Performs operations required on the supplied texture before being used for sampling.
| state | A pointer to the renderer system state. |
| t | 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, |
| ktexture | t, | ||
| u32 | offset, | ||
| u32 | size, | ||
| u8 ** | out_memory | ||
| ) |
Reads the given data from the provided texture.
| state | A pointer to the renderer system state. |
| t | 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, |
| ktexture | t, | ||
| 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. |
| t | 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, |
| ktexture | 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.
| state | A pointer to the renderer system state. |
| t | 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, |
| ktexture | t, | ||
| kname | name, | ||
| ktexture_type | type, | ||
| u32 | width, | ||
| u32 | height, | ||
| u8 | channel_count, | ||
| u8 | mip_levels, | ||
| u16 | array_size, | ||
| ktexture_flag_bits | flags | ||
| ) |
Attempts to acquire renderer-specific resources to back a texture.
| state | A pointer to the renderer system state. |
| t | The texture handle which also points to the backing resource(s) of the texture. |
| 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. |
Releases backing renderer-specific resources for the given texture.
| state | A pointer to the renderer system state. |
| t | A handle to the renderer texture whose resources are to be released. |
| KAPI b8 renderer_texture_write_data | ( | struct renderer_system_state * | state, |
| ktexture | t, | ||
| u32 | offset, | ||
| u32 | size, | ||
| const u8 * | pixels | ||
| ) |
Writes the given data to the provided texture.
| state | A pointer to the renderer system state. |
| t | 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. |