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
98VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, const VK2DStartupOptions *options);
99
104
107
112
120
128
134
147void vk2dRendererGetVRAMUsage(float *inUse, float *total);
148
155
159
162VK2DLogicalDevice vk2dRendererGetDevice();
163
170void vk2dRendererSetTarget(VK2DTexture target);
171
175
179
183
189
198void vk2dRendererSetTextureCamera(bool useCameraOnTextures);
199
203
211
215
219
222
225
228
232
241void vk2dRendererDrawRectangle(float x, float y, float w, float h, float r, float ox, float oy);
242
252void vk2dRendererDrawRectangleOutline(float x, float y, float w, float h, float r, float ox, float oy, float lineWidth);
253
258void vk2dRendererDrawCircle(float x, float y, float r);
259
265void vk2dRendererDrawCircleOutline(float x, float y, float r, float lineWidth);
266
272void vk2dRendererDrawLine(float x1, float y1, float x2, float y2);
273
287void vk2dRendererDrawTexture(VK2DTexture tex, float x, float y, float xscale, float yscale, float rot, float originX,
288 float originY, float xInTex, float yInTex, float texWidth, float texHeight);
289
298void vk2dRendererAddBatch(VK2DDrawCommand *commands, uint32_t count);
299
315void
316vk2dRendererDrawShader(VK2DShader shader, void *data, VK2DTexture tex, float x, float y, float xscale, float yscale,
317 float rot, float originX, float originY, float xInTex, float yInTex, float texWidth,
318 float texHeight);
319
332void vk2dRendererDrawPolygon(VK2DPolygon polygon, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
333
350void vk2dRendererDrawGeometry(VK2DVertexColour *vertices, int count, float x, float y, bool filled, float lineWidth, float xscale, float yscale, float rot, float originX, float originY);
351
356void vk2dRendererDrawShadows(VK2DShadowEnvironment shadowEnvironment, vec4 colour, vec2 lightSource);
357
377void
378vk2dRendererDrawModel(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale, float rot,
379 vec3 axis, float originX, float originY, float originZ);
380
398void vk2dRendererDrawWireframe(VK2DModel model, float x, float y, float z, float xscale, float yscale, float zscale,
399 float rot, vec3 axis, float originX, float originY, float originZ, float lineWidth);
400
404void vk2dColourHex(vec4 dst, const char *hex);
405
409void vk2dColourInt(vec4 dst, uint32_t colour);
410
417void vk2dColourRGBA(vec4 dst, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
418
432
441float vk2dRandom(float min, float max);
442
448void vk2dSleep(double seconds);
449
452double vk2dTime();
453
457
467
474const char *vk2dStatusMessage();
475
480
481/************************* Shorthand for simpler drawing at no performance cost *************************/
482
484#define vk2dDrawRectangle(x, y, w, h) vk2dRendererDrawRectangle(x, y, w, h, 0, 0, 0)
485
487#define vk2dDrawRectangleOutline(x, y, w, h, lw) vk2dRendererDrawRectangleOutline(x, y, w, h, 0, 0, 0, lw)
488
490#define vk2dDrawCircle(x, y, r) vk2dRendererDrawCircle(x, y, r)
491
493#define vk2dDrawCircleOutline(x, y, r, w) vk2dRendererDrawCircleOutline(x, y, r, w)
494
496#define vk2dDrawLine(x1, y1, x2, y2) vk2dRendererDrawLine(x1, y1, x2, y2)
497
499#define vk2dDrawShader(shader, data, texture, x, y) vk2dRendererDrawShader(shader, data, texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
500
502#define vk2dDrawTexture(texture, x, y) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, 0, 0, vk2dTextureWidth(texture), vk2dTextureHeight(texture))
503
505#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))
506
508#define vk2dDrawTexturePart(texture, x, y, xPos, yPos, w, h) vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, xPos, yPos, w, h)
509
511#define vk2dDrawPolygonOutline(polygon, x, y, width) vk2dRendererDrawPolygon(polygon, x, y, false, width, 1, 1, 0, 0, 0)
512
514#define vk2dDrawPolygon(polygon, x, y) vk2dRendererDrawPolygon(polygon, x, y, true, 0, 1, 1, 0, 0, 0)
515
517#define vk2dDrawModel(model, x, y, z) vk2dRendererDrawModel(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0)
518
520#define vk2dDrawModelExt(model, x, y, z, xscale, yscale, zscale) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0)
521
523#define vk2dDrawWireframe(model, x, y, z) vk2dRendererDrawWireframe(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0, 1)
524
526#define vk2dDrawWireframeExt(model, x, y, z, xscale, yscale, zscale, lineWidth) vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0, lineWidth)
527
528#ifdef __cplusplus
529}
530#endif
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.
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.
double vk2dTime()
Returns the time in seconds since Vulkan2D was initialized.
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...
bool vk2dStatusFatal()
Returns true if the current status code should be considered fatal.
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)
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 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 vk2dRendererGetColourMod(vec4 dst)
Gets the current colour modifier.
void vk2dRendererPresent()
Presents the frame Call this at the end of every frame to draw to the screen.
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 vk2dRendererWait()
Waits until current GPU tasks are done before moving on.
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.
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.
VK2DResult vk2dRendererInit(SDL_Window *window, VK2DRendererConfig config, const VK2DStartupOptions *options)
Initializes VK2D's renderer.
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
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