Vulkan2D
2D renderer written in C using Vulkan and SDL2
Loading...
Searching...
No Matches
Renderer.h
Go to the documentation of this file.
1
87#pragma once
88#include "VK2D/Structs.h"
89#include <SDL3/SDL.h>
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94
123 const VK2DStartupOptions *options);
124
130
133
138
149
157
163
183void vk2dRendererGetVRAMUsage(float *inUse, float *total);
184
189
192const VkPhysicalDeviceProperties *vk2dRendererGetDeviceProperties();
193
200
204
207VK2DLogicalDevice vk2dRendererGetDevice();
208
217void vk2dRendererSetTarget(VK2DTexture target);
218
223
229
233
239
250void vk2dRendererSetTextureCamera(bool useCameraOnTextures);
251
257
267
272
277
280
283
287
291
300void vk2dRendererDrawRectangle(float x, float y, float w, float h, float r,
301 float ox, float oy);
302
312void vk2dRendererDrawRectangleOutline(float x, float y, float w, float h,
313 float r, float ox, float oy,
314 float lineWidth);
315
320void vk2dRendererDrawCircle(float x, float y, float r);
321
327void vk2dRendererDrawCircleOutline(float x, float y, float r, float lineWidth);
328
334void vk2dRendererDrawLine(float x1, float y1, float x2, float y2);
335
352void vk2dRendererDrawTexture(VK2DTexture tex, float x, float y, float xscale,
353 float yscale, float rot, float originX,
354 float originY, float xInTex, float yInTex,
355 float texWidth, float texHeight);
356
367void vk2dRendererAddBatch(VK2DDrawCommand *commands, uint32_t count);
368
388void vk2dRendererDrawShader(VK2DShader shader, void *data, VK2DTexture tex,
389 float x, float y, float xscale, float yscale,
390 float rot, float originX, float originY,
391 float xInTex, float yInTex, float texWidth,
392 float texHeight);
393
409void vk2dRendererDrawPolygon(VK2DPolygon polygon, float x, float y, bool filled,
410 float lineWidth, float xscale, float yscale,
411 float rot, float originX, float originY);
412
432void vk2dRendererDrawGeometry(VK2DVertexColour *vertices, int count, float x,
433 float y, bool filled, float lineWidth,
434 float xscale, float yscale, float rot,
435 float originX, float originY);
436
441void vk2dRendererDrawShadows(VK2DShadowEnvironment shadowEnvironment,
442 vec4 colour, vec2 lightSource);
443
464void vk2dRendererDrawModel(VK2DModel model, float x, float y, float z,
465 float xscale, float yscale, float zscale, float rot,
466 vec3 axis, float originX, float originY,
467 float originZ);
468
488void vk2dRendererDrawWireframe(VK2DModel model, float x, float y, float z,
489 float xscale, float yscale, float zscale,
490 float rot, vec3 axis, float originX,
491 float originY, float originZ, float lineWidth);
492
496void vk2dColourHex(vec4 dst, const char *hex);
497
501void vk2dColourInt(vec4 dst, uint32_t colour);
502
509void vk2dColourRGBA(vec4 dst, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
510
525
534float vk2dRandom(float min, float max);
535
542void vk2dSleep(double seconds);
543
546double vk2dTime();
547
551
562
571const char *vk2dStatusMessage();
572
577
578/************************* Shorthand for simpler drawing at no performance cost
579 * *************************/
580
582#define vk2dDrawRectangle(x, y, w, h) \
583 vk2dRendererDrawRectangle(x, y, w, h, 0, 0, 0)
584
587#define vk2dDrawRectangleOutline(x, y, w, h, lw) \
588 vk2dRendererDrawRectangleOutline(x, y, w, h, 0, 0, 0, lw)
589
591#define vk2dDrawCircle(x, y, r) vk2dRendererDrawCircle(x, y, r)
592
595#define vk2dDrawCircleOutline(x, y, r, w) \
596 vk2dRendererDrawCircleOutline(x, y, r, w)
597
599#define vk2dDrawLine(x1, y1, x2, y2) vk2dRendererDrawLine(x1, y1, x2, y2)
600
602#define vk2dDrawShader(shader, data, texture, x, y) \
603 vk2dRendererDrawShader(shader, data, texture, x, y, 1, 1, 0, 0, 0, 0, 0, \
604 vk2dTextureWidth(texture), \
605 vk2dTextureHeight(texture))
606
608#define vk2dDrawTexture(texture, x, y) \
609 vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, 0, 0, \
610 vk2dTextureWidth(texture), \
611 vk2dTextureHeight(texture))
612
614#define vk2dDrawTextureExt(texture, x, y, xscale, yscale, rot, originX, \
615 originY) \
616 vk2dRendererDrawTexture(texture, x, y, xscale, yscale, rot, originX, \
617 originY, 0, 0, vk2dTextureWidth(texture), \
618 vk2dTextureHeight(texture))
619
621#define vk2dDrawTexturePart(texture, x, y, xPos, yPos, w, h) \
622 vk2dRendererDrawTexture(texture, x, y, 1, 1, 0, 0, 0, xPos, yPos, w, h)
623
625#define vk2dDrawPolygonOutline(polygon, x, y, width) \
626 vk2dRendererDrawPolygon(polygon, x, y, false, width, 1, 1, 0, 0, 0)
627
629#define vk2dDrawPolygon(polygon, x, y) \
630 vk2dRendererDrawPolygon(polygon, x, y, true, 0, 1, 1, 0, 0, 0)
631
633#define vk2dDrawModel(model, x, y, z) \
634 vk2dRendererDrawModel(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0)
635
637#define vk2dDrawModelExt(model, x, y, z, xscale, yscale, zscale) \
638 vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0)
639
641#define vk2dDrawWireframe(model, x, y, z) \
642 vk2dRendererDrawWireframe(model, x, y, z, 1, 1, 1, 0, 1, 0, 0, 0, 1)
643
645#define vk2dDrawWireframeExt(model, x, y, z, xscale, yscale, zscale, \
646 lineWidth) \
647 vk2dRendererDrawModel(model, x, y, z, xscale, yscale, zscale, 0, 1, 0, 0, 0, \
648 lineWidth)
649
650#ifdef __cplusplus
651}
652#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.
double vk2dRendererGetGPUFrameTime()
GPU time of a recent frame, from timestamps around its command buffers.
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.
const VkPhysicalDeviceProperties * vk2dRendererGetDeviceProperties()
Properties of the physical device in use (name, vendor, driver and API versions, limits).
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:193
int32_t VK2DCameraIndex
Type used for referencing cameras.
Definition Structs.h:210
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:196
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:199
Camera information.
Definition Structs.h:297
Represents a user's draw command which will later be processed into an instance.
Definition Structs.h:346
User configurable settings.
Definition Structs.h:290
Renderer limitations for the host.
Definition Structs.h:323
Startup options that dictate some basic VK2D stuff.
Definition Structs.h:273
Vertex data for rendering shapes.
Definition Structs.h:213