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
128
134
147void vk2dRendererGetVRAMUsage(float *inUse, float *total);
148
155
160void vk2dRendererStartFrame(const vec4 clearColour);
161
165
168VK2DLogicalDevice vk2dRendererGetDevice();
169
176void vk2dRendererSetTarget(VK2DTexture target);
177
181
185
189
195
204void vk2dRendererSetTextureCamera(bool useCameraOnTextures);
205
209
217
221
225
228
231
234
238
247void vk2dRendererDrawRectangle(float x, float y, float w, float h, float r, float ox, float oy);
248
258void vk2dRendererDrawRectangleOutline(float x, float y, float w, float h, float r, float ox, float oy, float lineWidth);
259
264void vk2dRendererDrawCircle(float x, float y, float r);
265
271void vk2dRendererDrawCircleOutline(float x, float y, float r, float lineWidth);
272
278void vk2dRendererDrawLine(float x1, float y1, float x2, float y2);
279
293void vk2dRendererDrawTexture(VK2DTexture tex, float x, float y, float xscale, float yscale, float rot, float originX,
294 float originY, float xInTex, float yInTex, float texWidth, float texHeight);
295
304void vk2dRendererAddBatch(VK2DDrawCommand *commands, uint32_t count);
305
321void
322vk2dRendererDrawShader(VK2DShader shader, void *data, VK2DTexture tex, float x, float y, float xscale, float yscale,
323 float rot, float originX, float originY, float xInTex, float yInTex, float texWidth,
324 float texHeight);
325
338void vk2dRendererDrawPolygon(VK2DPolygon polygon, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
339
356void vk2dRendererDrawGeometry(VK2DVertexColour *vertices, int count, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
357
362void vk2dRendererDrawShadows(VK2DShadowEnvironment shadowEnvironment, vec4 colour, vec2 lightSource);
363
383void
384vk2dRendererDrawModel(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale, float rot,
385 vec3 axis, float originX, float originY, float originZ);
386
404void vk2dRendererDrawWireframe(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale,
405 float rot, vec3 axis, float originX, float originY, float originZ, float lineWidth);
406
410void vk2dColourHex(vec4 dst, const char *hex);
411
415void vk2dColourInt(vec4 dst, uint32_t colour);
416
423void vk2dColourRGBA(vec4 dst, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
424
438
447float vk2dRandom(float min, float max);
448
463void vk2dAssetsLoad(VK2DAssetLoad *assets, uint32_t count);
464
472
477
481
485void vk2dAssetsFree(VK2DAssetLoad *assets, uint32_t count);
486
492void vk2dAssetsSetTextureFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *outVar);
493
500void vk2dAssetsSetTextureMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *outVar);
501
508void vk2dAssetsSetModelFile(VK2DAssetLoad *array, int index, const char *filename, VK2DTexture *texture, VK2DModel *outVar);
509
517void vk2dAssetsSetModelMemory(VK2DAssetLoad *array, int index, void *buffer, int size, VK2DTexture *texture, VK2DModel *outVar);
518
526void vk2dAssetsSetShaderFile(VK2DAssetLoad *array, int index, const char *vertexFilename, const char *fragmentFilename, uint32_t uniformBufferSize, VK2DShader *outVar);
527
537void vk2dAssetsSetShaderMemory(VK2DAssetLoad *array, int index, void *vertexBuffer, int vertexBufferSize, void *fragmentBuffer, int fragmentBufferSize, uint32_t uniformBufferSize, VK2DShader *outVar);
538
544void vk2dSleep(double seconds);
545
549
559
566const char *vk2dStatusMessage();
567
572
573/************************* Shorthand for simpler drawing at no performance cost *************************/
574
576#define vk2dDrawRectangle(x, y, w, h) vk2dRendererDrawRectangle(x, y, w, h, 0, 0, 0)
577
579#define vk2dDrawRectangleOutline(x, y, w, h, lw) vk2dRendererDrawRectangleOutline(x, y, w, h, 0, 0, 0, lw)
580
582#define vk2dDrawCircle(x, y, r) vk2dRendererDrawCircle(x, y, r)
583
585#define vk2dDrawCircleOutline(x, y, r, w) vk2dRendererDrawCircleOutline(x, y, r, w)
586
588#define vk2dDrawLine(x1, y1, x2, y2) vk2dRendererDrawLine(x1, y1, x2, y2)
589
591#define vk2dDrawShader(shader, data, texture, x, y) vk2dRendererDrawShader(shader, data, texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
592
594#define vk2dDrawTexture(texture, x, y) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
595
597#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))
598
600#define vk2dDrawTexturePart(texture, x, y, xPos, yPos, w, h) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, xPos, yPos, w, h)
601
603#define vk2dDrawPolygonOutline(polygon, x, y, width) vk2dRendererDrawPolygon(polygon, x, y, false, width, 1, 1, 0, 0, 0)
604
606#define vk2dDrawPolygon(polygon, x, y) vk2dRendererDrawPolygon(polygon, x, y, true, 0, 1, 1, 0, 0, 0)
607
609#define vk2dDrawModel(model, x, y, z) vk2dRendererDrawModel(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0)
610
612#define vk2dDrawModelExt(model, x, y, z, xscale, yscale, zscale) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0)
613
615#define vk2dDrawWireframe(model, x, y, z) vk2dRendererDrawWireframe(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0, 1)
616
618#define vk2dDrawWireframeExt(model, x, y, z, xscale, yscale, zscale, lineWidth) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0, lineWidth)
619
620#ifdef __cplusplus
621}
622#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.
bool vk2dRendererHasStdoutLogging()
Checks if the renderer is set to log to stdout.
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:190
int32_t VK2DCameraIndex
Type used for referencing cameras.
Definition Structs.h:205
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:193
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:196
Information needed to queue an asset loading off-thread.
Definition Structs.h:370
Camera information.
Definition Structs.h:292
Represents a user's draw command which will later be processed into an instance.
Definition Structs.h:341
User configurable settings.
Definition Structs.h:285
Renderer limitations for the host.
Definition Structs.h:318
Startup options that dictate some basic VK2D stuff.
Definition Structs.h:268
Vertex data for rendering shapes.
Definition Structs.h:208