#pragma once #include #include "rendertarget.h" #include "sampler.h" #include "texture.h" #include "textureunit.h" #include #include /*! \file commandlist.h \brief Contains functions for building command-lists to send commands to the GPU. */ #ifdef __cplusplus extern "C" { #endif #define KINC_G5_CLEAR_COLOR 1 #define KINC_G5_CLEAR_DEPTH 2 #define KINC_G5_CLEAR_STENCIL 4 struct kinc_g5_constant_buffer; struct kinc_g5_index_buffer; struct kinc_g5_pipeline; struct kinc_g5_render_target; struct kinc_g5_texture; struct kinc_g5_vertex_buffer; struct kinc_g5_render_target; /*typedef enum kinc_g5_render_target_format { KINC_G5_RENDER_TARGET_FORMAT_32BIT, KINC_G5_RENDER_TARGET_FORMAT_64BIT_FLOAT, KINC_G5_RENDER_TARGET_FORMAT_32BIT_RED_FLOAT, KINC_G5_RENDER_TARGET_FORMAT_128BIT_FLOAT, KINC_G5_RENDER_TARGET_FORMAT_16BIT_DEPTH, KINC_G5_RENDER_TARGET_FORMAT_8BIT_RED } kinc_g5_render_target_format_t;*/ // typedef kinc_g4_render_target_format_t kinc_g5_render_target_format_t; typedef struct kinc_g5_command_list { CommandList5Impl impl; } kinc_g5_command_list_t; /// /// Initializes a command-list. /// /// The command-list to initialize KINC_FUNC void kinc_g5_command_list_init(kinc_g5_command_list_t *list); /// /// Destroys a command-list. /// /// The command-list to destroy KINC_FUNC void kinc_g5_command_list_destroy(kinc_g5_command_list_t *list); /// /// Starts recording commands in a command-list. /// /// The list to use KINC_FUNC void kinc_g5_command_list_begin(kinc_g5_command_list_t *list); /// /// Ends recording commands for the list. Has to be called after kinc_g5_command_list_begin and before kinc_g5_command_list_execute. /// /// /// KINC_FUNC void kinc_g5_command_list_end(kinc_g5_command_list_t *list); /// /// Records a command to clear the color, depth and/or stencil-components of a render-target. /// /// The list to write the command to /// The render-target to clear /// Defines what components to clear /// The color-value to clear to /// The depth-value to clear to /// The stencil-value to clear to KINC_FUNC void kinc_g5_command_list_clear(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, unsigned flags, unsigned color, float depth, int stencil); /// /// Records a command that prepares a render-target to be used as the current framebuffer. /// /// The list to write the command to /// The render-target to use as the current framebuffer KINC_FUNC void kinc_g5_command_list_render_target_to_framebuffer_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget); /// /// Records a command that prepares a render-target for regular render-target-usage after being used as the current framebuffer. /// /// The list to write the command to /// The render-target to use in regular render-target-mode KINC_FUNC void kinc_g5_command_list_framebuffer_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget); /// /// Writes a command that prepares a render-target to be rendered to. /// /// The list to write the command to /// The render-target to render to KINC_FUNC void kinc_g5_command_list_texture_to_render_target_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget); /// /// Writes a command that prepares a render-target to be used for sampling/reading like a texture. /// /// The list to write the command to /// The render-target to be used like a texture KINC_FUNC void kinc_g5_command_list_render_target_to_texture_barrier(kinc_g5_command_list_t *list, struct kinc_g5_render_target *renderTarget); /// /// Writes a command that draws the entire content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices as /// this is what GPUs tend to be optimized for. /// /// The list to write the command to KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices(kinc_g5_command_list_t *list); /// /// Writes a command that draws a part of the content of the currently set index-buffer and vertex-buffer. G4 can only draw triangle-lists using vertex-indices /// as this is what GPUs tend to be optimized for. /// /// The list to write the command to /// The offset into the index-buffer /// The number of indices to use KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_from_to(kinc_g5_command_list_t *list, int start, int count); /// /// Writes a command that draws a part of the content of the currently set index-buffer and vertex-buffer and additionally applies a general offset into the /// vertex-buffer. G4 can only draw triangle-lists using vertex-indices as this is what GPUs tend to be optimized for. /// /// The list to write the command to /// The offset into the index-buffer /// The number of indices to use /// The offset into the vertex-buffer which is added to each index read from the index-buffer KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_from_to_from(kinc_g5_command_list_t *list, int start, int count, int vertex_offset); KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_instanced(kinc_g5_command_list_t *list, int instanceCount); KINC_FUNC void kinc_g5_command_list_draw_indexed_vertices_instanced_from_to(kinc_g5_command_list_t *list, int instanceCount, int start, int count); /// /// Writes a command that sets the viewport which defines the portion of the framebuffer or render-target things are rendered into. By default the viewport is /// equivalent to the full size of the current render-target or framebuffer. /// /// The list to write the command to /// The x-offset of the viewport from the left of the screen in pixels /// The y-offset of the viewport from the top of the screen in pixels /// The width of the viewport in pixels /// The height of the viewport in pixels KINC_FUNC void kinc_g5_command_list_viewport(kinc_g5_command_list_t *list, int x, int y, int width, int height); /// /// Writes a command that enables and defines the scissor-rect. When the scissor-rect is enabled, anything that's rendered outside of the scissor-rect will be /// ignored. /// /// The list to write the command to /// The x-offset of the scissor-rect from the left of the screen in pixels /// The y-offset of the scissor-rect from the top of the screen in pixels /// The width of the scissor-rect in pixels /// The height of the scissor-rect in pixels KINC_FUNC void kinc_g5_command_list_scissor(kinc_g5_command_list_t *list, int x, int y, int width, int height); /// /// Writes a command to disable the scissor-rect. /// /// The list to write the command to KINC_FUNC void kinc_g5_command_list_disable_scissor(kinc_g5_command_list_t *list); /// /// Writes a command to set the pipeline for the next draw-call. The pipeline defines most rendering-state including the shaders to be used. /// /// The list to write the command to /// The pipeline to set KINC_FUNC void kinc_g5_command_list_set_pipeline(kinc_g5_command_list_t *list, struct kinc_g5_pipeline *pipeline); /// /// Sets the blend constant used for `KINC_G5_BLEND_CONSTANT` or `KINC_G5_INV_BLEND_CONSTANT` /// KINC_FUNC void kinc_g5_command_list_set_blend_constant(kinc_g5_command_list_t *list, float r, float g, float b, float a); /// /// Writes a command which sets vertex-buffers for the next draw-call. /// /// The list to write the command to /// The buffers to set /// The offset to use for every buffer in number of vertices /// The number of buffers to set KINC_FUNC void kinc_g5_command_list_set_vertex_buffers(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer **buffers, int *offsets, int count); /// /// Writes a command to set an index-buffer to be used for the next draw-command. /// /// The list to write the command to /// The buffer to use KINC_FUNC void kinc_g5_command_list_set_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer); /// /// Writes a command that sets the render-targets to draw into in following draw-calls. /// /// The list to write the command to /// The render-targets to use for following-draw calls /// The number of render-targets to use KINC_FUNC void kinc_g5_command_list_set_render_targets(kinc_g5_command_list_t *list, struct kinc_g5_render_target **targets, int count); /// /// Writes a command to upload an index-buffer that's in main-memory to gpu-memory. Does nothing on unified-memory-systems. /// /// The list to write the command to /// The buffer to upload KINC_FUNC void kinc_g5_command_list_upload_index_buffer(kinc_g5_command_list_t *list, struct kinc_g5_index_buffer *buffer); /// /// Writes a command to upload a vertex-buffer that's in main-memory to gpu-memory. Does nothing on unified-memory-systems. /// /// The list to write the command to /// The buffer to upload KINC_FUNC void kinc_g5_command_list_upload_vertex_buffer(kinc_g5_command_list_t *list, struct kinc_g5_vertex_buffer *buffer); /// /// Writes a command to upload a texture that's in main-memory to gpu-memory. Does nothing on unified-memory-systems. /// /// The list to write the command to /// The texture to upload KINC_FUNC void kinc_g5_command_list_upload_texture(kinc_g5_command_list_t *list, struct kinc_g5_texture *texture); /// /// Writes a command that sets a constant-buffer for the vertex-shader-stage. /// /// The list to write the command to /// The buffer to set /// The offset into the buffer in bytes to use as the start /// The size of the buffer to use in bytes starting at the offset KINC_FUNC void kinc_g5_command_list_set_vertex_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size); /// /// Writes a command that sets a constant-buffer for the fragment-shader-stage. /// /// The list to write the command to /// The buffer to set /// The offset into the buffer in bytes to use as the start /// The size of the buffer to use in bytes starting at the offset KINC_FUNC void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size); /// /// Kicks off execution of the commands which have been recorded in the command-list. kinc_g5_command_list_end has to be called beforehand. /// /// The command-list to execute KINC_FUNC void kinc_g5_command_list_execute(kinc_g5_command_list_t *list); /// /// Waits for execution of the command_list to finish. Make sure the command-list is executing before you wait for it. /// Also take note that waiting for a command-list to finish executing completely is a very expensive operation. /// /// The command-list to execute KINC_FUNC void kinc_g5_command_list_wait_for_execution_to_finish(kinc_g5_command_list_t *list); /// /// Writes a command that copies the contents of a render-target into a cpu-side buffer. Beware: This is enormously slow. /// /// The list to write the command to /// The render-target to copy the data from /// The buffer to copy the data into KINC_FUNC void kinc_g5_command_list_get_render_target_pixels(kinc_g5_command_list_t *list, struct kinc_g5_render_target *render_target, uint8_t *data); /// /// Records a command that fires off a compute-run on x * y * z elements. /// /// The list to write the command to /// The x-size for the compute-run /// The y-size for the compute-run /// The z-size for the compute-run KINC_FUNC void kinc_g5_command_list_compute(kinc_g5_command_list_t *list, int x, int y, int z); /// /// Assigns a texture to a texture-unit for sampled access via GLSL's texture. /// /// The list to write the command to /// The unit to assign this texture to /// The texture to assign to the unit KINC_FUNC void kinc_g5_command_list_set_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture); /// /// Assigns a texture to a texture-unit for direct access via GLSL's texelFetch (as /// opposed to GLSL's texture). The name of this functions is unfortunately based /// on OpenGL's confusing terminology. /// /// The list to write the command to /// The unit to assign this texture to /// The texture to assign to the unit KINC_FUNC void kinc_g5_command_list_set_image_texture(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_texture_t *texture); /// /// Uses the color-component of a render-target as a texture. /// /// The list to write the command to /// The texture-unit to assign the render-target to /// The render-target to use KINC_FUNC void kinc_g5_command_list_set_texture_from_render_target(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *target); /// /// Uses the depth-component of a render-target as a texture. /// /// The list to write the command to /// The texture-unit to assign the render-target to /// The render-target to use KINC_FUNC void kinc_g5_command_list_set_texture_from_render_target_depth(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_render_target_t *target); KINC_FUNC void kinc_g5_command_list_set_render_target_face(kinc_g5_command_list_t *list, kinc_g5_render_target_t *texture, int face); KINC_FUNC void kinc_g5_command_list_set_sampler(kinc_g5_command_list_t *list, kinc_g5_texture_unit_t unit, kinc_g5_sampler_t *sampler); // Occlusion Query KINC_FUNC bool kinc_g5_command_list_init_occlusion_query(kinc_g5_command_list_t *list, unsigned *occlusionQuery); KINC_FUNC void kinc_g5_command_list_delete_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery); KINC_FUNC void kinc_g5_command_list_render_occlusion_query(kinc_g5_command_list_t *list, unsigned occlusionQuery, int triangles); KINC_FUNC bool kinc_g5_command_list_are_query_results_available(kinc_g5_command_list_t *list, unsigned occlusionQuery); KINC_FUNC void kinc_g5_command_list_get_query_result(kinc_g5_command_list_t *list, unsigned occlusionQuery, unsigned *pixelCount); #ifdef __cplusplus } #endif