Vulkan2D
2D renderer written in C using Vulkan and SDL2
Loading...
Searching...
No Matches
Renderer.h
Go to the documentation of this file.
1
66#pragma once
67#include "VK2D/Structs.h"
68#include <SDL3/SDL.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
99
104
107
112
120
126
139void vk2dRendererGetVRAMUsage(float *inUse, float *total);
140
147
152void vk2dRendererStartFrame(const vec4 clearColour);
153
157
160VK2DLogicalDevice vk2dRendererGetDevice();
161
168void vk2dRendererSetTarget(VK2DTexture target);
169
173
177
181
187
196void vk2dRendererSetTextureCamera(bool useCameraOnTextures);
197
201
209
213
217
220
223
226
230
239void vk2dRendererDrawRectangle(float x, float y, float w, float h, float r, float ox, float oy);
240
250void vk2dRendererDrawRectangleOutline(float x, float y, float w, float h, float r, float ox, float oy, float lineWidth);
251
256void vk2dRendererDrawCircle(float x, float y, float r);
257
263void vk2dRendererDrawCircleOutline(float x, float y, float r, float lineWidth);
264
270void vk2dRendererDrawLine(float x1, float y1, float x2, float y2);
271
285void vk2dRendererDrawTexture(VK2DTexture tex, float x, float y, float xscale, float yscale, float rot, float originX,
286 float originY, float xInTex, float yInTex, float texWidth, float texHeight);
287
296void vk2dRendererAddBatch(VK2DDrawCommand *commands, uint32_t count);
297
313void
314vk2dRendererDrawShader(VK2DShader shader, void *data, VK2DTexture tex, float x, float y, float xscale, float yscale,
315 float rot, float originX, float originY, float xInTex, float yInTex, float texWidth,
316 float texHeight);
317
330void vk2dRendererDrawPolygon(VK2DPolygon polygon, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
331
348void vk2dRendererDrawGeometry(VK2DVertexColour *vertices, int count, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
349
354void vk2dRendererDrawShadows(VK2DShadowEnvironment shadowEnvironment, vec4 colour, vec2 lightSource);
355
375void
376vk2dRendererDrawModel(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale, float rot,
377 vec3 axis, float originX, float originY, float originZ);
378
396void vk2dRendererDrawWireframe(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale,
397 float rot, vec3 axis, float originX, float originY, float originZ, float lineWidth);
398
402void vk2dColourHex(vec4 dst, const char *hex);
403
407void vk2dColourInt(vec4 dst, uint32_t colour);
408
415void vk2dColourRGBA(vec4 dst, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
416
430
439float vk2dRandom(float min, float max);
440
455void vk2dAssetsLoad(VK2DAssetLoad *assets, uint32_t count);
456
464
469
473
477void vk2dAssetsFree(VK2DAssetLoad *assets, uint32_t count);
478
484void vk2dAssetsSetTextureFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *outVar);
485
492void vk2dAssetsSetTextureMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *outVar);
493
500void vk2dAssetsSetModelFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *texture, VK2DModel *outVar);
501
509void vk2dAssetsSetModelMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *texture, VK2DModel *outVar);
510
518void vk2dAssetsSetShaderFile(VK2DAssetLoad *array, int index, const char *vertexFilename, const char *fragmentFilename, uint32_t uniformBufferSize, VK2DShader *outVar);
519
529void vk2dAssetsSetShaderMemory(VK2DAssetLoad *array, int index, void *vertexBuffer, int vertexBufferSize, void *fragmentBuffer, int fragmentBufferSize, uint32_t uniformBufferSize, VK2DShader *outVar);
530
536void vk2dSleep(double seconds);
537
541
551
558const char *vk2dStatusMessage();
559
564
565/************************* Shorthand for simpler drawing at no performance cost *************************/
566
568#define vk2dDrawRectangle(x, y, w, h) vk2dRendererDrawRectangle(x, y, w, h, 0, 0, 0)
569
571#define vk2dDrawRectangleOutline(x, y, w, h, lw) vk2dRendererDrawRectangleOutline(x, y, w, h, 0, 0, 0, lw)
572
574#define vk2dDrawCircle(x, y, r) vk2dRendererDrawCircle(x, y, r)
575
577#define vk2dDrawCircleOutline(x, y, r, w) vk2dRendererDrawCircleOutline(x, y, r, w)
578
580#define vk2dDrawLine(x1, y1, x2, y2) vk2dRendererDrawLine(x1, y1, x2, y2)
581
583#define vk2dDrawShader(shader, data, texture, x, y) vk2dRendererDrawShader(shader, data, texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
584
586#define vk2dDrawTexture(texture, x, y) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
587
589#define vk2dDrawTextureExt(texture, x, y, xscale, yscale, rot, originX, originY) vk2dRendererDrawTexture(texture, x, y, xscale, yscale, rot, originX, originY, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
590
592#define vk2dDrawTexturePart(texture, x, y, xPos, yPos, w, h) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, xPos, yPos, w, h)
593
595#define vk2dDrawPolygonOutline(polygon, x, y, width) vk2dRendererDrawPolygon(polygon, x, y, false, width, 1, 1, 0, 0, 0)
596
598#define vk2dDrawPolygon(polygon, x, y) vk2dRendererDrawPolygon(polygon, x, y, true, 0, 1, 1, 0, 0, 0)
599
601#define vk2dDrawModel(model, x, y, z) vk2dRendererDrawModel(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0)
602
604#define vk2dDrawModelExt(model, x, y, z, xscale, yscale, zscale) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0)
605
607#define vk2dDrawWireframe(model, x, y, z) vk2dRendererDrawWireframe(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0, 1)
608
610#define vk2dDrawWireframeExt(model, x, y, z, xscale, yscale, zscale, lineWidth) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0, lineWidth)
611
612#ifdef __cplusplus
613}
614#endif
float vk2dAssetsLoadStatus()
Returns the loading status as a percentage from 0-1.
void vk2dRendererUnlockCameras()
Unlocking cameras means that all cameras will be drawn to again.
void vk2dRendererDrawPolygon(VK2DPolygon polygon, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY)
Renders a polygon.
void vk2dRendererDrawWireframe(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale, float rot, vec3 axis, float originX, float originY, float originZ, float lineWidth)
Renders a 3D model as a wireframe.
void vk2dRendererLockCameras(VK2DCameraIndex cam)
Locking cameras means that only the specified camera will be drawn to and all others ignored.
void vk2dColourHex(vec4 dst, const char *hex)
Converts a Hex colour into a vec4 normalized colour.
void vk2dAssetsSetTextureMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *outVar)
Sets up a VK2DAssetLoad array entry for a TextureMemory entry.
double vk2dRendererGetAverageFrameTime()
Gets the average amount of time frames are taking to process from the end of vk2dRendererEndFrame to ...
void vk2dRendererDrawLine(float x1, float y1, float x2, float y2)
Draws a line using the current rendering colour.
VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, VK2DStartupOptions *options)
Initializes VK2D's renderer.
void vk2dRendererAddBatch(VK2DDrawCommand *commands, uint32_t count)
Adds a user-provided draw batch to the current draw batch, flushing if necessary.
const char * vk2dStatusMessage()
Returns the current renderer status message, generally use this if vk2dGetStatus() returns something ...
void vk2dRendererSetColourMod(const vec4 mod)
Sets the current colour modifier (Colour all pixels are blended with)
void vk2dRendererDrawRectangle(float x, float y, float w, float h, float r, float ox, float oy)
Draws a rectangle using the current rendering colour.
void vk2dRendererEmpty()
Clears the content so that every pixel in the target is set to be complete transparent (useful for ne...
void vk2dAssetsLoad(VK2DAssetLoad *assets, uint32_t count)
Loads a number of assets in a background thread.
bool vk2dStatusFatal()
Returns true if the current status code should be considered fatal.
void vk2dAssetsSetModelFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *texture, VK2DModel *outVar)
Sets up a VK2DAssetLoad array entry for a ModelFile entry.
void vk2dAssetsSetShaderMemory(VK2DAssetLoad *array, int index, void *vertexBuffer, int vertexBufferSize, void *fragmentBuffer, int fragmentBufferSize, uint32_t uniformBufferSize, VK2DShader *outVar)
Sets up a VK2DAssetLoad array entry for a ShaderMemory entry.
VK2DCameraSpec vk2dRendererGetCamera()
Returns the camera spec of the default camera, this is equivalent to calling vk2dCameraGetSpec(VK2D_D...
void vk2dSleep(double seconds)
Combines busy loops and SDL_Delay for a more accurate sleep function.
void vk2dRendererDrawShader(VK2DShader shader, void *data, VK2DTexture tex, float x, float y, float xscale, float yscale, float rot, float originX, float originY, float xInTex, float yInTex, float texWidth, float texHeight)
Renders a texture.
const char * vk2dHostInformation()
Returns a string detailing information about the host machine.
void vk2dRendererResetSwapchain()
Forces the renderer to rebuild itself (VK2D does this automatically)
void vk2dRendererDrawCircleOutline(float x, float y, float r, float lineWidth)
Draws a circle using the current rendering colour.
void vk2dRendererSetBlendMode(VK2DBlendMode blendMode)
Sets the rendering blend mode (does nothing if VK2D_GENERATE_BLEND_MODES is disabled)
void vk2dAssetsSetShaderFile(VK2DAssetLoad *array, int index, const char *vertexFilename, const char *fragmentFilename, uint32_t uniformBufferSize, VK2DShader *outVar)
Sets up a VK2DAssetLoad array entry for a ShaderFile entry.
float vk2dRandom(float min, float max)
Returns a random number between min and max, thread safe.
void vk2dRendererDrawModel(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale, float rot, vec3 axis, float originX, float originY, float originZ)
Renders a 3D model.
VK2DLogicalDevice vk2dRendererGetDevice()
Returns the logical device being used by the renderer.
void vk2dAssetsWait()
Waits until all of the assets provided to vk2dAssetsLoad have been loaded.
bool vk2dAssetsLoadComplete()
Returns true if the assets thread is done loading assets.
VK2DResult vk2dRendererEndFrame()
Completes the end-of-frame drawing tasks.
void vk2dRendererDrawTexture(VK2DTexture tex, float x, float y, float xscale, float yscale, float rot, float originX, float originY, float xInTex, float yInTex, float texWidth, float texHeight)
Renders a texture.
void vk2dAssetsSetTextureFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *outVar)
Sets up a VK2DAssetLoad array entry for a TextureFile entry.
void vk2dRendererGetColourMod(vec4 dst)
Gets the current colour modifier.
VK2DRenderer vk2dRendererGetPointer()
Gets the internal renderer's pointer.
VK2DBlendMode vk2dRendererGetBlendMode()
Gets the current blend mode (will return whatever was set with vk2dRendererSetBlendMode regardless of...
void vk2dRendererClear()
Clears the current render target to the current renderer colour.
void vk2dRendererSetTextureCamera(bool useCameraOnTextures)
Allows you to enable or disable the use of the renderer's camera when drawing to textures.
void vk2dRendererSetConfig(VK2DRendererConfig config)
Resets the renderer with a new configuration.
void vk2dRendererSetTarget(VK2DTexture target)
Changes the render target to a texture or the screen.
void vk2dColourInt(vec4 dst, uint32_t colour)
Converts a Int colour into a vec4 normalized colour.
void vk2dRendererFlushSpriteBatch()
Forces the renderer to flush the current sprite batch The renderer automatically does this in a few c...
void vk2dRendererQuit()
Frees resources used by the renderer.
void vk2dRendererDrawGeometry(VK2DVertexColour *vertices, int count, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY)
Draws arbitrary geometry without needing to pre-allocate a polygon.
void vk2dRendererStartFrame(const vec4 clearColour)
Sets up the renderer to prepare for drawing.
void vk2dRendererWait()
Waits until current GPU tasks are done before moving on.
void vk2dAssetsSetModelMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *texture, VK2DModel *outVar)
Sets up a VK2DAssetLoad array entry for a ModelMemory entry.
void vk2dRendererSetCamera(VK2DCameraSpec camera)
Sets the current camera settings.
void vk2dRendererGetVRAMUsage(float *inUse, float *total)
Returns the amount of VRAM currently in use and free.
void vk2dRendererDrawRectangleOutline(float x, float y, float w, float h, float r, float ox, float oy, float lineWidth)
Draws a rectangle using the current rendering colour.
VK2DRendererLimits vk2dRendererGetLimits()
Returns the limits of the renderer on the current host.
void vk2dAssetsFree(VK2DAssetLoad *assets, uint32_t count)
Uses the same asset list you passed to vk2dAssetsLoad to free all the assets in one call.
VK2DStatus vk2dStatus()
Gets the renderer's current status code.
void vk2dRendererDrawShadows(VK2DShadowEnvironment shadowEnvironment, vec4 colour, vec2 lightSource)
Draws a shadow environment.
VK2DRendererConfig vk2dRendererGetConfig()
Gets the current user configuration of the renderer.
void vk2dColourRGBA(vec4 dst, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Converts a RGBA colour into a vec4 normalized colour.
void vk2dRendererDrawCircle(float x, float y, float r)
Draws a circle using the current rendering colour.
Forward declares struct typedefs.
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
float vec3[3]
3D vector of floats
Definition Structs.h:173
VK2DResult
Return codes through the renderer.
Definition Structs.h:115
VK2DStatus
Status codes for logging/error reporting.
Definition Structs.h:122
float vec4[4]
4D vector of floats
Definition Structs.h:176
Information needed to queue an asset loading off-thread.
Definition Structs.h:350
Camera information.
Definition Structs.h:272
Represents a user's draw command which will later be processed into an instance.
Definition Structs.h:321
User configurable settings.
Definition Structs.h:265
Renderer limitations for the host.
Definition Structs.h:298
Startup options that dictate some basic VK2D stuff.
Definition Structs.h:248
Vertex data for rendering shapes.
Definition Structs.h:188