5#include <vulkan/vulkan.h>
13#define VK2D_MAX_CAMERAS 10
16#define VK2D_OPAQUE_POINTER(type) typedef struct type##_t *type;
19#define VK2D_USER_STRUCT(type) typedef struct type type;
155VK2D_OPAQUE_POINTER(VK2DRenderer)
156VK2D_OPAQUE_POINTER(VK2DImage)
157VK2D_OPAQUE_POINTER(VK2DLogicalDevice)
158VK2D_OPAQUE_POINTER(VK2DPhysicalDevice)
159VK2D_OPAQUE_POINTER(VK2DBuffer)
160VK2D_OPAQUE_POINTER(VK2DPipeline)
161VK2D_OPAQUE_POINTER(VK2DTexture)
162VK2D_OPAQUE_POINTER(VK2DDescCon)
163VK2D_OPAQUE_POINTER(VK2DPolygon)
164VK2D_OPAQUE_POINTER(VK2DShader)
165VK2D_OPAQUE_POINTER(VK2DModel)
166VK2D_OPAQUE_POINTER(VK2DDescriptorBuffer)
167VK2D_OPAQUE_POINTER(VK2DShadowEnvironment)
VK2DAssetType
Types of assets.
Definition Structs.h:138
@ VK2D_ASSET_TYPE_MODEL_MEMORY
Load a model from a binary blob.
Definition Structs.h:142
@ VK2D_ASSET_TYPE_TEXTURE_MEMORY
Load a texture from a binary blob.
Definition Structs.h:140
@ VK2D_ASSET_TYPE_MODEL_FILE
Load a model from a filename.
Definition Structs.h:141
@ VK2D_ASSET_TYPE_SHADER_MEMORY
Load a shader from a binary blob.
Definition Structs.h:144
@ VK2D_ASSET_TYPE_TEXTURE_FILE
Load a texture from a filename.
Definition Structs.h:139
@ VK2D_ASSET_TYPE_SHADER_FILE
Load a shader from a filename.
Definition Structs.h:143
VK2DVertexType
Describes what kind of vertices are in use.
Definition Structs.h:22
@ VK2D_VERTEX_TYPE_SHAPE
Vertex meant for the shapes pipelines.
Definition Structs.h:24
@ VK2D_VERTEX_TYPE_OTHER
Unspecified vertex type.
Definition Structs.h:26
@ VK2D_VERTEX_TYPE_MAX
Maximum number of vertex types.
Definition Structs.h:27
@ VK2D_VERTEX_TYPE_TEXTURE
Vertex meant for the texture pipeline.
Definition Structs.h:23
@ VK2D_VERTEX_TYPE_MODEL
Vertex meant for models.
Definition Structs.h:25
VK2DFilterType
Specifies how textures will be filtered at higher and lower resolutions.
Definition Structs.h:76
@ VK2D_FILTER_TYPE_NEAREST
Nearest neighbor filter, good for pixel art.
Definition Structs.h:78
@ VK2D_FILTER_TYPE_LINEAR
Linear interpolation, good for most things.
Definition Structs.h:77
#define VK2D_MAX_CAMERAS
Maximum number of cameras that can exist, enabled or disabled, at once - this is here instead of cons...
Definition Structs.h:13
VK2DCameraState
The state a camera is in.
Definition Structs.h:88
@ VK2D_CAMERA_STATE_MAX
Total number of camera states.
Definition Structs.h:93
@ VK2D_CAMERA_STATE_DELETED
Camera is "deleted" and all data is invalid.
Definition Structs.h:91
@ VK2D_CAMERA_STATE_DISABLED
Camera is not being rendered or updated.
Definition Structs.h:90
@ VK2D_CAMERA_STATE_NORMAL
Camera is being rendered/updated as normal.
Definition Structs.h:89
@ VK2D_CAMERA_STATE_RESET
Camera is being reset by the renderer.
Definition Structs.h:92
float vec2[2]
2D vector of floats
Definition Structs.h:170
int32_t VK2DCameraIndex
Type used for referencing cameras.
Definition Structs.h:185
VK2DBlendMode
Blend modes that can be used to render if VK2D_GENERATE_BLEND_MODES is enabled.
Definition Structs.h:38
@ VK2D_BLEND_MODE_MAX
Total number of blend modes (used for looping)
Definition Structs.h:43
@ VK2D_BLEND_MODE_ADD
Additive blending.
Definition Structs.h:41
@ VK2D_BLEND_MODE_NONE
No blending, new colour is law.
Definition Structs.h:40
@ VK2D_BLEND_MODE_BLEND
Default blend mode, good for almost everything.
Definition Structs.h:39
@ VK2D_BLEND_MODE_SUBTRACT
Subtraction blending, new colour is subtracted from current colour.
Definition Structs.h:42
int32_t VK2DShadowObject
Type used for referencing shadow objects.
Definition Structs.h:182
VK2DMSAA
Multisampling detail.
Definition Structs.h:53
@ VK2D_MSAA_4X
4 samples per pixel
Definition Structs.h:56
@ VK2D_MSAA_1X
1 sample per pixel
Definition Structs.h:54
@ VK2D_MSAA_8X
8 samples per pixel
Definition Structs.h:57
@ VK2D_MSAA_2X
2 samples per pixel
Definition Structs.h:55
@ VK2D_MSAA_16X
16 samples per pixel
Definition Structs.h:58
@ VK2D_MSAA_32X
32 samples per pixel
Definition Structs.h:59
float vec3[3]
3D vector of floats
Definition Structs.h:173
VK2DResult
Return codes through the renderer.
Definition Structs.h:115
@ VK2D_SUCCESS
Everything worked.
Definition Structs.h:116
@ VK2D_RESET_SWAPCHAIN
The swapchain (renderer) was just reset (likely due to window resize or something similar)
Definition Structs.h:117
@ VK2D_ERROR
Error occurred.
Definition Structs.h:118
float mat4[16]
4x4 matrix of floats
Definition Structs.h:179
VK2DPipelineType
Types of graphics pipelines.
Definition Structs.h:105
@ VK2D_PIPELINE_TYPE_DEFAULT
Default 2D pipelines.
Definition Structs.h:106
@ VK2D_PIPELINE_TYPE_3D
3D pipelines
Definition Structs.h:107
@ VK2D_PIPELINE_TYPE_MAX
Max number of pipeline types.
Definition Structs.h:111
@ VK2D_PIPELINE_TYPE_USER_SHADER
Pipeline for user shaders.
Definition Structs.h:110
@ VK2D_PIPELINE_TYPE_SHADOWS
Pipeline for shadows.
Definition Structs.h:109
@ VK2D_PIPELINE_TYPE_INSTANCING
Pipelines for instancing.
Definition Structs.h:108
VK2DAssetState
State an asset may be in.
Definition Structs.h:148
@ VK2D_ASSET_TYPE_ASSET
Normal asset awaiting load.
Definition Structs.h:149
@ VK2D_ASSET_TYPE_NONE
This slot is empty.
Definition Structs.h:151
@ VK2D_ASSET_TYPE_PENDING
Asset is pending a queue family transfer.
Definition Structs.h:150
VK2DScreenMode
How to present images.
Definition Structs.h:69
@ VK2D_SCREEN_MODE_VSYNC
Slower but prevents screen tearing.
Definition Structs.h:71
@ VK2D_SCREEN_MODE_TRIPLE_BUFFER
Optimal for gaming but a bit slower than immediate (machines may not support this)
Definition Structs.h:72
@ VK2D_SCREEN_MODE_IMMEDIATE
Quickest mode, just plop to screen but may have screen tearing.
Definition Structs.h:70
VK2DStatus
Status codes for logging/error reporting.
Definition Structs.h:122
@ VK2D_STATUS_SDL_ERROR
General SDL-catch all, not fatal.
Definition Structs.h:132
@ VK2D_STATUS_BEYOND_LIMIT
User requested a setting that was beyond host limits, not fatal.
Definition Structs.h:133
@ VK2D_STATUS_RENDERER_NOT_INITIALIZED
Renderer has not been initialized.
Definition Structs.h:131
@ VK2D_STATUS_BAD_ASSET
User tried to pass a NULL asset to a VK2D method, not fatal.
Definition Structs.h:134
@ VK2D_STATUS_VULKAN_ERROR
Some sort of specific vulkan error.
Definition Structs.h:128
@ VK2D_STATUS_OUT_OF_VRAM
Out of gpu memory.
Definition Structs.h:130
@ VK2D_STATUS_TOO_MANY_CAMERAS
No camera slots left to use, not fatal.
Definition Structs.h:126
@ VK2D_STATUS_NONE
Nothing important to report.
Definition Structs.h:123
@ VK2D_STATUS_FILE_NOT_FOUND
File was not found for something like an image load, not fatal.
Definition Structs.h:124
@ VK2D_STATUS_OUT_OF_RAM
Out of host memory.
Definition Structs.h:129
@ VK2D_STATUS_BAD_FORMAT
Bad file format.
Definition Structs.h:125
@ VK2D_STATUS_DEVICE_LOST
General Vulkan catch-all for when something goes wrong.
Definition Structs.h:127
VK2DCameraType
Type of camera.
Definition Structs.h:97
@ VK2D_CAMERA_TYPE_ORTHOGRAPHIC
Orthographic camera for 3D rendering.
Definition Structs.h:99
@ VK2D_CAMERA_TYPE_MAX
Maximum number of camera types.
Definition Structs.h:101
@ VK2D_CAMERA_TYPE_DEFAULT
Default camera used for 2D games in VK2D.
Definition Structs.h:98
@ VK2D_CAMERA_TYPE_PERSPECTIVE
Perspective camera for 3D rendering.
Definition Structs.h:100
float vec4[4]
4D vector of floats
Definition Structs.h:176
VK2DShaderStage
A bitwise-able enum representing different shader stages.
Definition Structs.h:82
@ VK2D_SHADER_STAGE_VERTEX
Vertex shader.
Definition Structs.h:84
@ VK2D_SHADER_STAGE_FRAGMENT
Fragment (pixel) shader.
Definition Structs.h:83
Push buffer used for 3D models.
Definition Structs.h:222
uint32_t cameraIndex
Index of the camera.
Definition Structs.h:226
mat4 model
Model matrix.
Definition Structs.h:223
uint32_t textureIndex
Index of the texture.
Definition Structs.h:225
vec4 colourMod
Color modifier.
Definition Structs.h:224
Information needed to queue an asset loading off-thread.
Definition Structs.h:350
union VK2DAssetLoad::@1 Load
Information needed to create the asset.
void * fragmentData
Fragment shader's data.
Definition Structs.h:362
union VK2DAssetLoad::@2 Data
Asset-specific information.
const char * fragmentFilename
Fragment shader filename.
Definition Structs.h:356
union VK2DAssetLoad::@3 Output
How the user will receive the loaded asset.
void * data
Data to pull from or data for the vertex shader.
Definition Structs.h:360
struct VK2DAssetLoad::@2::@9 Model
Information needed if this is a model.
int uniformBufferSize
Uniform buffer size of this shader.
Definition Structs.h:368
int size
Data size or data size of the vertex shader.
Definition Structs.h:359
struct VK2DAssetLoad::@2::@8 Shader
Information needed if this is a texture.
VK2DTexture * tex
Texture to use for this model (pointer so the model's texture may be in the same list)
Definition Structs.h:371
VK2DModel * model
Pointer to where the output object will be placed.
Definition Structs.h:377
VK2DAssetType type
Type of asset this is.
Definition Structs.h:351
VK2DAssetState state
State this asset is in.
Definition Structs.h:352
VK2DTexture * texture
Pointer to where the output object will be placed.
Definition Structs.h:378
const char * filename
Filename to pull from or filename of the vertex shader.
Definition Structs.h:355
VK2DShader * shader
Pointer to where the output object will be placed.
Definition Structs.h:376
int fragmentSize
Fragment shader's size.
Definition Structs.h:361
Camera information.
Definition Structs.h:272
float hOnScreen
Height of the camera in the window.
Definition Structs.h:283
vec3 up
Which direction is up for the 3D camera.
Definition Structs.h:289
float xOnScreen
x position in the window
Definition Structs.h:280
float yOnScreen
y position in the window
Definition Structs.h:281
float y
Y position of the camera (top left coordinates) (only used in default camera type)
Definition Structs.h:275
float zoom
Zoom percentage (Relative to the virtual width and height, not actual)
Definition Structs.h:278
VK2DCameraType type
What type of camera this is.
Definition Structs.h:273
float rot
Rotation of the camera.
Definition Structs.h:279
float wOnScreen
Width of the camera in the window.
Definition Structs.h:282
float w
Virtual width of the screen.
Definition Structs.h:276
float h
Virtual height of the screen.
Definition Structs.h:277
vec3 centre
Where the 3D camera is looking.
Definition Structs.h:288
vec3 eyes
Where the 3D camera is.
Definition Structs.h:287
float x
X position of the camera (top left coordinates) (only used in default camera type)
Definition Structs.h:274
float fov
Field of view of the camera.
Definition Structs.h:290
Push buffer for the sprite batch compute shader.
Definition Structs.h:337
uint32_t drawCount
Number of draws being processed in this compute pass.
Definition Structs.h:338
User configurable settings.
Definition Structs.h:239
uint32_t engineVersion
Version of this engine.
Definition Structs.h:243
uint32_t apiVersion
Version of vulkan.
Definition Structs.h:244
const char * engineName
Name of this engine.
Definition Structs.h:241
const char * applicationName
Name of this program.
Definition Structs.h:240
uint32_t applicationVersion
Version of the program.
Definition Structs.h:242
Represents a user's draw command which will later be processed into an instance.
Definition Structs.h:321
vec4 colour
Colour mod of this draw.
Definition Structs.h:323
uint32_t textureIndex
Texture index for this draw (use vk2dTextureGetID)
Definition Structs.h:328
vec2 pos
X/Y in game world for this instance.
Definition Structs.h:324
vec4 texturePos
x in tex, y in tex, w in tex, and h in tex
Definition Structs.h:322
float rotation
Rotation of the draw centered around the origin.
Definition Structs.h:327
vec2 origin
X/Y Origin of this draw.
Definition Structs.h:325
vec2 scale
X/Y Scale of this draw.
Definition Structs.h:326
Represents the data you need for each element in an instanced draw.
Definition Structs.h:312
vec4 colour
Colour mod of this draw.
Definition Structs.h:314
vec4 texturePos
x in tex, y in tex, w in tex, and h in tex
Definition Structs.h:313
mat4 model
Model for this instance, generally shouldn't contain translations.
Definition Structs.h:317
uint32_t textureIndex
Which texture this instance is using.
Definition Structs.h:315
vec3 padding
Padding.
Definition Structs.h:316
A push buffer for an instanced draw.
Definition Structs.h:332
uint32_t cameraIndex
Index of the camera for this draw.
Definition Structs.h:333
Buffer passed per-model via push constants.
Definition Structs.h:215
int32_t cameraIndex
Index of the camera.
Definition Structs.h:218
vec4 colourMod
Current colour modifier.
Definition Structs.h:217
mat4 model
Model matrix.
Definition Structs.h:216
User configurable settings.
Definition Structs.h:265
VK2DMSAA msaa
Current MSAA.
Definition Structs.h:266
VK2DFilterType filterMode
How to filter textures – Not change-able after renderer creation.
Definition Structs.h:268
VK2DScreenMode screenMode
Current screen mode.
Definition Structs.h:267
Renderer limitations for the host.
Definition Structs.h:298
uint64_t maxGeometryVertices
Maximum vertices that can be used in one vk2dRendererDrawGeometryCall, if you use more vertices than ...
Definition Structs.h:306
bool supportsMultiThreadLoading
Whether or not the host supports loading assets in another thread, if attempt to load assets in anoth...
Definition Structs.h:307
uint64_t maxInstancedDraws
Maximum amount of instances you may draw at once, if you request to draw more instances than this it ...
Definition Structs.h:304
bool supportsTripleBuffering
Whether or not the host supports triple buffering, if you request triple buffering and this is false,...
Definition Structs.h:300
bool supportsWireframe
Doesn't really mean anything 💀
Definition Structs.h:302
VK2DMSAA maxMSAA
Maximum MSAA the host supports, if you request an msaa higher than this value, this value will be use...
Definition Structs.h:299
bool supportsImmediate
Whether or not the host supports immediate mode, if you request immediate mode and this is false,...
Definition Structs.h:301
float maxLineWidth
Maximum line width supported on the platform, if you specify a line width greater than this value,...
Definition Structs.h:303
bool supportsVRAMUsage
Whether or not the host supports accurate VRAM usage, if this is false VMA will provide a less accura...
Definition Structs.h:308
uint64_t maxShaderBufferSize
Maximum size of a shader's uniform buffer in bytes, if you attempt to create a shader with a uniform ...
Definition Structs.h:305
Push buffer for user shaders.
Definition Structs.h:205
vec4 colour
Colour mod of the renderer when called.
Definition Structs.h:210
int32_t cameraIndex
Index of the camera in use.
Definition Structs.h:206
mat4 model
Model matrix.
Definition Structs.h:211
vec4 texturePos
UV coordinates (unnormalized)
Definition Structs.h:209
vec2 _padding
For vec4 alignment.
Definition Structs.h:208
uint32_t textureIndex
Index of the texture that was passed to the shader.
Definition Structs.h:207
Info for the shadow environment to keep track of.
Definition Structs.h:342
int vertexCount
Number of vertices for this model.
Definition Structs.h:345
int startingVertex
Vertex in the master VBO to start from for this object.
Definition Structs.h:344
bool enabled
Whether or not this object is enabled.
Definition Structs.h:343
mat4 model
Model for this shadow object.
Definition Structs.h:346
Push buffer used for hardware-accelerated shadows.
Definition Structs.h:230
vec4 colour
Colour of this shadow render.
Definition Structs.h:234
vec2 _alignment
Simply for memory alignment.
Definition Structs.h:233
uint32_t cameraIndex
Index of the camera.
Definition Structs.h:235
vec2 lightSource
Light source position.
Definition Structs.h:232
mat4 model
Model matrix for this shadow object.
Definition Structs.h:231
Startup options that dictate some basic VK2D stuff.
Definition Structs.h:248
uint32_t maxTextures
Max number of textures active at once.
Definition Structs.h:253
bool stdoutLogging
Print VK2D information to stdout.
Definition Structs.h:250
bool enableDebug
Enables Vulkan compatibility layers.
Definition Structs.h:249
bool quitOnError
Crash the program when an error occurs.
Definition Structs.h:251
uint64_t vramPageSize
Definition Structs.h:259
const char * errorFile
The file to output errors to, or NULL to disable file output.
Definition Structs.h:252
Vertex data for 3D models.
Definition Structs.h:194
vec3 pos
Position of the vertex.
Definition Structs.h:195
vec2 uv
UV coordinates for this vertex.
Definition Structs.h:196
Vertex data for rendering shapes.
Definition Structs.h:188
vec4 colour
Colour of this vertex.
Definition Structs.h:190
vec3 pos
Position of this vertex.
Definition Structs.h:189