Vulkan2D
2D renderer written in C using Vulkan and SDL2
Structs.h File Reference

Forward declares struct typedefs. More...

#include <vulkan/vulkan.h>
#include <stdbool.h>
Include dependency graph for Structs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  VK2DVertexColour
 Vertex data for rendering shapes. More...
 
struct  VK2DVertex3D
 Vertex data for 3D models. More...
 
struct  VK2DUniformBufferObject
 The VP buffer. More...
 
struct  VK2DShaderPushBuffer
 Push buffer for user shaders. More...
 
struct  VK2DPushBuffer
 Buffer passed per-model via push constants. More...
 
struct  VK2D3DPushBuffer
 Push buffer used for 3D models. More...
 
struct  VK2DShadowsPushBuffer
 Push buffer used for hardware-accelerated shadows. More...
 
struct  VK2DConfiguration
 User configurable settings. More...
 
struct  VK2DStartupOptions
 Startup options that dictate some basic VK2D stuff. More...
 
struct  VK2DRendererConfig
 User configurable settings. More...
 
struct  VK2DCameraSpec
 Camera information. More...
 
struct  VK2DRendererLimits
 Renderer limitations for the host. More...
 
struct  VK2DDrawInstance
 Represents the data you need for each element in an instanced draw. More...
 
struct  VK2DDrawCommand
 Represents a user's draw command which will later be processed into an instance. More...
 
struct  VK2DInstancedPushBuffer
 A push buffer for an instanced draw. More...
 
struct  VK2DComputePushBuffer
 Push buffer for the sprite batch compute shader. More...
 
struct  VK2DShadowObjectInfo
 Info for the shadow environment to keep track of. More...
 
struct  VK2DAssetLoad
 Information needed to queue an asset loading off-thread. More...
 

Macros

#define VK2D_MAX_CAMERAS   10
 Maximum number of cameras that can exist, enabled or disabled, at once - this is here instead of constants to avoid circular dependencies.
 
#define VK2D_OPAQUE_POINTER(type)   typedef struct type##_t *type;
 
#define VK2D_USER_STRUCT(type)   typedef struct type type;
 

Typedefs

typedef float vec2[2]
 2D vector of floats
 
typedef float vec3[3]
 3D vector of floats
 
typedef float vec4[4]
 4D vector of floats
 
typedef float mat4[16]
 4x4 matrix of floats
 
typedef int32_t VK2DShadowObject
 Type used for referencing shadow objects.
 
typedef int32_t VK2DCameraIndex
 Type used for referencing cameras.
 

Enumerations

enum  VK2DVertexType {
  VK2D_VERTEX_TYPE_TEXTURE = 0 , VK2D_VERTEX_TYPE_SHAPE = 1 , VK2D_VERTEX_TYPE_MODEL = 2 , VK2D_VERTEX_TYPE_OTHER = 3 ,
  VK2D_VERTEX_TYPE_MAX = 4
}
 Describes what kind of vertices are in use. More...
 
enum  VK2DBlendMode {
  VK2D_BLEND_MODE_BLEND = 0 , VK2D_BLEND_MODE_NONE = 1 , VK2D_BLEND_MODE_ADD = 2 , VK2D_BLEND_MODE_SUBTRACT = 3 ,
  VK2D_BLEND_MODE_MAX = 4
}
 Blend modes that can be used to render if VK2D_GENERATE_BLEND_MODES is enabled. More...
 
enum  VK2DMSAA {
  VK2D_MSAA_1X = VK_SAMPLE_COUNT_1_BIT , VK2D_MSAA_2X = VK_SAMPLE_COUNT_2_BIT , VK2D_MSAA_4X = VK_SAMPLE_COUNT_4_BIT , VK2D_MSAA_8X = VK_SAMPLE_COUNT_8_BIT ,
  VK2D_MSAA_16X = VK_SAMPLE_COUNT_16_BIT , VK2D_MSAA_32X = VK_SAMPLE_COUNT_32_BIT
}
 Multisampling detail. More...
 
enum  VK2DScreenMode { VK2D_SCREEN_MODE_IMMEDIATE = VK_PRESENT_MODE_IMMEDIATE_KHR , VK2D_SCREEN_MODE_VSYNC = VK_PRESENT_MODE_FIFO_KHR , VK2D_SCREEN_MODE_TRIPLE_BUFFER = VK_PRESENT_MODE_MAILBOX_KHR }
 How to present images. More...
 
enum  VK2DFilterType { VK2D_FILTER_TYPE_LINEAR = VK_FILTER_LINEAR , VK2D_FILTER_TYPE_NEAREST = VK_FILTER_NEAREST }
 Specifies how textures will be filtered at higher and lower resolutions. More...
 
enum  VK2DShaderStage { VK2D_SHADER_STAGE_FRAGMENT = VK_SHADER_STAGE_FRAGMENT_BIT , VK2D_SHADER_STAGE_VERTEX = VK_SHADER_STAGE_VERTEX_BIT }
 A bitwise-able enum representing different shader stages. More...
 
enum  VK2DCameraState {
  VK2D_CAMERA_STATE_NORMAL = 0 , VK2D_CAMERA_STATE_DISABLED = 1 , VK2D_CAMERA_STATE_DELETED = 2 , VK2D_CAMERA_STATE_RESET = 3 ,
  VK2D_CAMERA_STATE_MAX = 4
}
 The state a camera is in. More...
 
enum  VK2DCameraType { VK2D_CAMERA_TYPE_DEFAULT = 0 , VK2D_CAMERA_TYPE_ORTHOGRAPHIC = 1 , VK2D_CAMERA_TYPE_PERSPECTIVE = 2 , VK2D_CAMERA_TYPE_MAX = 3 }
 Type of camera. More...
 
enum  VK2DPipelineType {
  VK2D_PIPELINE_TYPE_DEFAULT = 0 , VK2D_PIPELINE_TYPE_3D = 1 , VK2D_PIPELINE_TYPE_INSTANCING = 2 , VK2D_PIPELINE_TYPE_SHADOWS = 3 ,
  VK2D_PIPELINE_TYPE_USER_SHADER = 4 , VK2D_PIPELINE_TYPE_MAX = 5
}
 Types of graphics pipelines. More...
 
enum  VK2DResult { VK2D_SUCCESS = 0 , VK2D_RESET_SWAPCHAIN = 1 , VK2D_ERROR = -1 }
 Return codes through the renderer. More...
 
enum  VK2DStatus {
  VK2D_STATUS_NONE = 0 , VK2D_STATUS_FILE_NOT_FOUND = 1<<0 , VK2D_STATUS_BAD_FORMAT = 1<<1 , VK2D_STATUS_TOO_MANY_CAMERAS = 1<<2 ,
  VK2D_STATUS_DEVICE_LOST = 1<<3 , VK2D_STATUS_VULKAN_ERROR = 1<<4 , VK2D_STATUS_OUT_OF_RAM = 1<<5 , VK2D_STATUS_OUT_OF_VRAM = 1<<6 ,
  VK2D_STATUS_RENDERER_NOT_INITIALIZED = 1<<7 , VK2D_STATUS_SDL_ERROR = 1<<8 , VK2D_STATUS_BEYOND_LIMIT = 1<<9 , VK2D_STATUS_BAD_ASSET = 1<<10
}
 Status codes for logging/error reporting. More...
 
enum  VK2DAssetType {
  VK2D_ASSET_TYPE_TEXTURE_FILE = 1 , VK2D_ASSET_TYPE_TEXTURE_MEMORY = 2 , VK2D_ASSET_TYPE_MODEL_FILE = 3 , VK2D_ASSET_TYPE_MODEL_MEMORY = 4 ,
  VK2D_ASSET_TYPE_SHADER_FILE = 5 , VK2D_ASSET_TYPE_SHADER_MEMORY = 6
}
 Types of assets. More...
 
enum  VK2DAssetState { VK2D_ASSET_TYPE_ASSET = 0 , VK2D_ASSET_TYPE_PENDING = 1 , VK2D_ASSET_TYPE_NONE = 2 }
 State an asset may be in. More...
 

Detailed Description

Forward declares struct typedefs.

Author
Paolo Mazzon

Enumeration Type Documentation

◆ VK2DAssetState

State an asset may be in.

Enumerator
VK2D_ASSET_TYPE_ASSET 

Normal asset awaiting load.

VK2D_ASSET_TYPE_PENDING 

Asset is pending a queue family transfer.

VK2D_ASSET_TYPE_NONE 

This slot is empty.

◆ VK2DAssetType

Types of assets.

Enumerator
VK2D_ASSET_TYPE_TEXTURE_FILE 

Load a texture from a filename.

VK2D_ASSET_TYPE_TEXTURE_MEMORY 

Load a texture from a binary blob.

VK2D_ASSET_TYPE_MODEL_FILE 

Load a model from a filename.

VK2D_ASSET_TYPE_MODEL_MEMORY 

Load a model from a binary blob.

VK2D_ASSET_TYPE_SHADER_FILE 

Load a shader from a filename.

VK2D_ASSET_TYPE_SHADER_MEMORY 

Load a shader from a binary blob.

◆ VK2DBlendMode

Blend modes that can be used to render if VK2D_GENERATE_BLEND_MODES is enabled.

The blend modes are kind of limited because very few people need more than these, but if you require a different blend mode there is only 3 steps to adding it:

  • Add a new blend mode to the end of this enumerator and increment bm_Max
  • Add the new blend mode to the VK2D_BLEND_MODES array in BlendModes.h
  • Make sure the indices in the array match the enumerator
Enumerator
VK2D_BLEND_MODE_BLEND 

Default blend mode, good for almost everything.

VK2D_BLEND_MODE_NONE 

No blending, new colour is law.

VK2D_BLEND_MODE_ADD 

Additive blending.

VK2D_BLEND_MODE_SUBTRACT 

Subtraction blending, new colour is subtracted from current colour.

VK2D_BLEND_MODE_MAX 

Total number of blend modes (used for looping)

◆ VK2DCameraState

The state a camera is in.

Enumerator
VK2D_CAMERA_STATE_NORMAL 

Camera is being rendered/updated as normal.

VK2D_CAMERA_STATE_DISABLED 

Camera is not being rendered or updated.

VK2D_CAMERA_STATE_DELETED 

Camera is "deleted" and all data is invalid.

VK2D_CAMERA_STATE_RESET 

Camera is being reset by the renderer.

VK2D_CAMERA_STATE_MAX 

Total number of camera states.

◆ VK2DCameraType

Type of camera.

Enumerator
VK2D_CAMERA_TYPE_DEFAULT 

Default camera used for 2D games in VK2D.

VK2D_CAMERA_TYPE_ORTHOGRAPHIC 

Orthographic camera for 3D rendering.

VK2D_CAMERA_TYPE_PERSPECTIVE 

Perspective camera for 3D rendering.

VK2D_CAMERA_TYPE_MAX 

Maximum number of camera types.

◆ VK2DFilterType

Specifies how textures will be filtered at higher and lower resolutions.

Enumerator
VK2D_FILTER_TYPE_LINEAR 

Linear interpolation, good for most things.

VK2D_FILTER_TYPE_NEAREST 

Nearest neighbor filter, good for pixel art.

◆ VK2DMSAA

enum VK2DMSAA

Multisampling detail.

While Vulkan does technically support 64 samples per pixel, there exists no device in the hardware database that supports it. Higher values look smoother but have a bigger impact on performance. Should you request an msaa larger than the device supports the maximum supported msaa is used.

Enumerator
VK2D_MSAA_1X 

1 sample per pixel

VK2D_MSAA_2X 

2 samples per pixel

VK2D_MSAA_4X 

4 samples per pixel

VK2D_MSAA_8X 

8 samples per pixel

VK2D_MSAA_16X 

16 samples per pixel

VK2D_MSAA_32X 

32 samples per pixel

◆ VK2DPipelineType

Types of graphics pipelines.

Enumerator
VK2D_PIPELINE_TYPE_DEFAULT 

Default 2D pipelines.

VK2D_PIPELINE_TYPE_3D 

3D pipelines

VK2D_PIPELINE_TYPE_INSTANCING 

Pipelines for instancing.

VK2D_PIPELINE_TYPE_SHADOWS 

Pipeline for shadows.

VK2D_PIPELINE_TYPE_USER_SHADER 

Pipeline for user shaders.

VK2D_PIPELINE_TYPE_MAX 

Max number of pipeline types.

◆ VK2DResult

enum VK2DResult

Return codes through the renderer.

Enumerator
VK2D_SUCCESS 

Everything worked.

VK2D_RESET_SWAPCHAIN 

The swapchain (renderer) was just reset (likely due to window resize or something similar)

VK2D_ERROR 

Error occurred.

◆ VK2DScreenMode

How to present images.

This is system dependent and its possible for a system to not support sm_Immediate or sm_TripleBuffer. While it is technically possible to not support VSync, the Vulkan spec states it must be supported and the hardware database agrees with that so VK2D assumes VSync is always supported. Should you request a mode that is not available, the option will default to sm_Vsync.

Enumerator
VK2D_SCREEN_MODE_IMMEDIATE 

Quickest mode, just plop to screen but may have screen tearing.

VK2D_SCREEN_MODE_VSYNC 

Slower but prevents screen tearing.

VK2D_SCREEN_MODE_TRIPLE_BUFFER 

Optimal for gaming but a bit slower than immediate (machines may not support this)

◆ VK2DShaderStage

A bitwise-able enum representing different shader stages.

Enumerator
VK2D_SHADER_STAGE_FRAGMENT 

Fragment (pixel) shader.

VK2D_SHADER_STAGE_VERTEX 

Vertex shader.

◆ VK2DStatus

enum VK2DStatus

Status codes for logging/error reporting.

Enumerator
VK2D_STATUS_NONE 

Nothing important to report.

VK2D_STATUS_FILE_NOT_FOUND 

File was not found for something like an image load, not fatal.

VK2D_STATUS_BAD_FORMAT 

Bad file format.

VK2D_STATUS_TOO_MANY_CAMERAS 

No camera slots left to use, not fatal.

VK2D_STATUS_DEVICE_LOST 

General Vulkan catch-all for when something goes wrong.

VK2D_STATUS_VULKAN_ERROR 

Some sort of specific vulkan error.

VK2D_STATUS_OUT_OF_RAM 

Out of host memory.

VK2D_STATUS_OUT_OF_VRAM 

Out of gpu memory.

VK2D_STATUS_RENDERER_NOT_INITIALIZED 

Renderer has not been initialized.

VK2D_STATUS_SDL_ERROR 

General SDL-catch all, not fatal.

VK2D_STATUS_BEYOND_LIMIT 

User requested a setting that was beyond host limits, not fatal.

VK2D_STATUS_BAD_ASSET 

User tried to pass a NULL asset to a VK2D method, not fatal.

◆ VK2DVertexType

Describes what kind of vertices are in use.

Enumerator
VK2D_VERTEX_TYPE_TEXTURE 

Vertex meant for the texture pipeline.

VK2D_VERTEX_TYPE_SHAPE 

Vertex meant for the shapes pipelines.

VK2D_VERTEX_TYPE_MODEL 

Vertex meant for models.

VK2D_VERTEX_TYPE_OTHER 

Unspecified vertex type.

VK2D_VERTEX_TYPE_MAX 

Maximum number of vertex types.