Trainings Graphics API
Should simply loading the cmake project not work:
Currently implemented are:
A Shader represents code to be executed on the GPU.
A handle to a Shader is created with a call to
Interface::createShader(const ShaderInfo &shaderInfo);
The ShaderInfo struct requires the following parameters:
ShaderType type; // Type of Shader. Valid Types are ShaderType::vertex and ShaderType::fragment
uint8_t const *src; // Pointer to the shader code. Dependant on the underlying API, for Vulkan this would be SPIR-V
size_t srcSize; // Size of the shader code in bytes
The handle to a Shader is valid until a call to
Interface::free(Shader shader); or until the descruction of the interface
A Buffer represents a chunk of memory on the GPU.
A handle to a Buffer is created with a call to
Interface::createBuffer(const BufferInfo &bufferInfo);
The BufferInfo struct requires the following parameters:
BufferUsage usage; // Usage flags of the Buffer. Valid Usage flags are BufferUsage::uniform, BufferUsage::vertex and BufferUsage::index. Others are work in progress
uint8_t const data; // Data of the Buffer to be uploaded. Alignment requirements are the users responsibility
size_t dataSize; // Size of the buffer data in bytes
To update the contents of a Buffer call ```Interface::updateBuffer(Buffer buffer, uint8_t const data, size_t dataSize, uint32_t offset)
with the Buffer you want to update, the data you want to write, the size of the data in bytes and an offset from the beginning of the Buffer The handle to a Buffer is valid until a call toInterface::free(Buffer buffer);``` or until the descruction of the interface
A Texture represents an image that is stored on and used by the GPU.
A handle to a Texture is created with a call to
Interface::createTexture(const TextureInfo &textureInfo);
The TextureInfo struct requires the following parameters:
uint32_t width; // Width of the Texture in pixels
uint32_t height; // Height of the Texture in pixels
Format format; // Format of the pixels. Example: For 8 bit per Pixel with red, green and blue channel use Format::r8g8b8_unorm. For a list of all formats refer to tga::Format
uint8_t const *data; // Data of the Texture. Pass a nullptr to create a texture with undefined content
size_t dataSize; // Size of the texture data in bytes
SamplerMode samplerMode; // How the Texture is sampled. Valid SamplerModes are SamplerMode::nearest (default) and SamplerMode::linear
RepeatMode repeatMode; // How textures reads with uv-coordinates outside of [0:1] are handled. For a list of all repeate modes refer to tga::RepeatMode
The handle to a Texture is valid until a call to
Interface::free(Texture texture); or until the descruction of the interface
A Window is used to present the result of a fragment shader to the screen.
A handle to a Window is created with a call to
Interface::createWindow(const WindowInfo &windowInfo);
The WindowInfo struct requires the following parameters:
uint32_t width; // Width of the Window in pixels
uint32_t height; // Height of the Window in pixels
PresentMode presentMode; // How syncronization to the monitor is handled. Valid PresentModes are PresentMode::immediate (show frame as fast as possible, default) and PresentMode::vsync (sync to the monitor refresh rate)
uint32_t framebufferCount; // How many backbuffers the window has to manage. Due to minimum and maximum contraints this value may not be the actual resulting number of backbuffers and needs to be polled later
The handle to a Window can be used to query and update its state:
The handle to a Window is valid until a call to
Interface::free(Window window); or until the descruction of the interface
An InputSet is a collection of Bindings and a Binding is a resource used in a Shader.
A handle to an InputSet is created with a call to
Interface::createInputSet(const InputSetInfo &inputSetInfo);
The InputSetInfo struct requires the following parameters:
RenderPass targetRenderPass; // The RenderPass this InputSet should be used with
uint32_t setIndex; // The Index of this InputSet as defined in RenderPass.inputLayout
std::vector bindings; // The collection of Bindings in this InputSet
A Binding assigns a resource to a shader as declared in RenderPass::InputLayout::SetLayout
The Binding struct consists of:
The handle to an InputSet is valid until a call to
Interface::free(InputSet inputSet); or until the descruction of the interface
A RenderPass describes a configuration of the graphics-pipeline.
A handle to a RenderPass is created with a call to
Interface::createRenderPass(const RenderPassInfo &renderPassInfo);
The RenderPassInfo struct requires the following parameters:
std::vector shaderStages; // The Shaders to be executed in this RenderPass. Must be ordererd in accordance with the shader stages of the graphics pipeline (i.e vertex before fragment, no duplicate stages, etc.)
std::variant renderTarget; // Where the result of the fragment shader stage will be saved. Keep in mind that a Window can have several framebuffers and only one is written at a time
ClearOperation clearOperations; // Determines if the renderTarget and/or depth-buffer should be cleared
VertexLayout vertexLayout; // Describes the format of the vertices in the vertex-buffer
RasterizerConfig rasterizerConfig; // Describes the configuration the Rasterizer, i.e blending, depth-buffer, culling and polygon draw mode
InputLayout inputLayout; // Describes how the Bindings are organized
The VertexLayout describes how a vertex in a vertex-buffer is laid out in memory.
The VertexLayout struct consists of:
A VertexAttribute consists of:
The RasterizerConfig determines depth test, blending, culling and polygon-draw-mode
the RasterizerConfig struct consists of:
The InputLayout describes how Bindings are organized.
The InputLayout is a collection of SetLayouts.
A SetLayout is a collection of BindingLayouts.
The BindingLayout struct consists of:
The handle to a RenderPass is valid until a call to
Interface::free(RenderPass renderPass); or until the descruction of the interface
A CommandBuffer is a list of instructions to be executed by the GPU.
A CommandBuffer is started with a call to
Interface::beginCommandBuffer(const CommandBufferInfo &commandBufferInfo)
Note that the CommandBufferInfo struct is currently empty
The handle to a CommandBuffer can then be created with a call to
Inbetween beginCommandBuffer and endCommandBuffer you can call the following commands to be recorded in the CommandBuffer:
To execute a CommandBuffer call
The handle to a CommandBuffer is valid until a call to
Interface::free(CommandBuffer commandBuffer); or until the descruction of the interface