lovr/src/modules/graphics/graphics.h

244 lines
7.4 KiB
C
Raw Normal View History

2017-02-03 23:16:30 +00:00
#include "graphics/font.h"
2019-06-27 20:44:09 +00:00
#include "data/modelData.h"
2019-05-20 09:47:33 +00:00
#include "core/maf.h"
2017-10-31 08:14:09 +00:00
#include <stdbool.h>
2018-07-17 06:51:11 +00:00
#include <stdint.h>
2016-09-21 07:55:53 +00:00
2017-01-26 10:20:30 +00:00
#pragma once
2016-09-27 06:48:09 +00:00
2019-04-05 11:58:29 +00:00
struct Buffer;
struct Canvas;
struct Font;
struct Material;
struct Mesh;
struct Shader;
struct Texture;
2018-07-16 00:05:06 +00:00
typedef void (*StencilCallback)(void* userdata);
2018-07-17 06:51:11 +00:00
typedef enum {
ARC_MODE_PIE,
ARC_MODE_OPEN,
ARC_MODE_CLOSED
} ArcMode;
2018-07-16 00:05:06 +00:00
typedef enum {
BLEND_ALPHA,
BLEND_ADD,
BLEND_SUBTRACT,
BLEND_MULTIPLY,
BLEND_LIGHTEN,
BLEND_DARKEN,
BLEND_SCREEN,
BLEND_NONE
2018-07-16 00:05:06 +00:00
} BlendMode;
typedef enum {
BLEND_ALPHA_MULTIPLY,
BLEND_PREMULTIPLIED
} BlendAlphaMode;
typedef enum {
COMPARE_EQUAL,
COMPARE_NEQUAL,
COMPARE_LESS,
COMPARE_LEQUAL,
COMPARE_GREATER,
2019-02-01 23:10:12 +00:00
COMPARE_GEQUAL,
COMPARE_NONE
2018-07-16 00:05:06 +00:00
} CompareMode;
2018-07-17 06:51:11 +00:00
typedef enum {
STYLE_FILL,
STYLE_LINE
} DrawStyle;
2018-07-17 06:51:11 +00:00
2018-07-16 00:05:06 +00:00
typedef enum {
STENCIL_REPLACE,
STENCIL_INCREMENT,
STENCIL_DECREMENT,
STENCIL_INCREMENT_WRAP,
STENCIL_DECREMENT_WRAP,
STENCIL_INVERT
} StencilAction;
2018-07-17 06:51:11 +00:00
typedef enum {
WINDING_CLOCKWISE,
WINDING_COUNTERCLOCKWISE
} Winding;
typedef struct {
2019-12-10 21:44:51 +00:00
float lineWidth;
unsigned alphaSampling : 1;
unsigned blendMode : 3; // BlendMode
unsigned blendAlphaMode : 1; // BlendAlphaMode
unsigned colorMask : 4;
unsigned culling : 1;
unsigned depthTest : 3; // CompareMode
unsigned depthWrite : 1;
unsigned stencilValue: 8;
unsigned stencilMode : 3; // CompareMode
unsigned winding : 1; // Winding
unsigned wireframe : 1;
2018-07-16 00:05:06 +00:00
} Pipeline;
2021-02-25 16:00:12 +00:00
typedef struct {
uint32_t width;
uint32_t height;
bool fullscreen;
bool resizable;
bool debug;
int vsync;
int msaa;
const char* title;
struct {
void* data;
uint32_t width;
uint32_t height;
} icon;
} WindowFlags;
2016-11-23 05:16:13 +00:00
// Base
2020-07-28 22:12:15 +00:00
bool lovrGraphicsInit(bool debug);
2019-02-17 22:39:51 +00:00
void lovrGraphicsDestroy(void);
void lovrGraphicsPresent(void);
2021-02-25 16:00:12 +00:00
void lovrGraphicsCreateWindow(WindowFlags* flags);
2019-02-17 22:39:51 +00:00
int lovrGraphicsGetWidth(void);
int lovrGraphicsGetHeight(void);
float lovrGraphicsGetPixelDensity(void);
void lovrGraphicsSetBackbuffer(struct Canvas* canvas, bool stereo, bool clear);
void lovrGraphicsGetViewMatrix(uint32_t index, float* viewMatrix);
void lovrGraphicsSetViewMatrix(uint32_t index, float* viewMatrix);
void lovrGraphicsGetProjection(uint32_t index, float* projection);
void lovrGraphicsSetProjection(uint32_t index, float* projection);
2019-04-05 11:58:29 +00:00
struct Buffer* lovrGraphicsGetIdentityBuffer(void);
#define lovrGraphicsTick lovrGpuTick
#define lovrGraphicsTock lovrGpuTock
#define lovrGraphicsGetFeatures lovrGpuGetFeatures
2018-08-31 13:03:35 +00:00
#define lovrGraphicsGetLimits lovrGpuGetLimits
#define lovrGraphicsGetStats lovrGpuGetStats
2016-11-23 05:16:13 +00:00
// State
2019-02-17 22:39:51 +00:00
void lovrGraphicsReset(void);
bool lovrGraphicsGetAlphaSampling(void);
2018-12-12 06:54:13 +00:00
void lovrGraphicsSetAlphaSampling(bool sample);
2019-02-17 22:39:51 +00:00
Color lovrGraphicsGetBackgroundColor(void);
2017-08-02 08:25:56 +00:00
void lovrGraphicsSetBackgroundColor(Color color);
2017-03-12 11:03:36 +00:00
void lovrGraphicsGetBlendMode(BlendMode* mode, BlendAlphaMode* alphaMode);
void lovrGraphicsSetBlendMode(BlendMode mode, BlendAlphaMode alphaMode);
2019-04-05 11:58:29 +00:00
struct Canvas* lovrGraphicsGetCanvas(void);
void lovrGraphicsSetCanvas(struct Canvas* canvas);
2019-02-17 22:39:51 +00:00
Color lovrGraphicsGetColor(void);
2017-08-02 08:25:56 +00:00
void lovrGraphicsSetColor(Color color);
2019-12-10 21:44:51 +00:00
void lovrGraphicsGetColorMask(bool* r, bool* g, bool* b, bool* a);
void lovrGraphicsSetColorMask(bool r, bool g, bool b, bool a);
2019-02-17 22:39:51 +00:00
bool lovrGraphicsIsCullingEnabled(void);
2017-10-31 08:14:09 +00:00
void lovrGraphicsSetCullingEnabled(bool culling);
2019-02-17 22:39:51 +00:00
TextureFilter lovrGraphicsGetDefaultFilter(void);
2017-08-02 07:54:33 +00:00
void lovrGraphicsSetDefaultFilter(TextureFilter filter);
2018-02-09 05:50:47 +00:00
void lovrGraphicsGetDepthTest(CompareMode* mode, bool* write);
void lovrGraphicsSetDepthTest(CompareMode depthTest, bool write);
2019-04-05 11:58:29 +00:00
struct Font* lovrGraphicsGetFont(void);
void lovrGraphicsSetFont(struct Font* font);
2019-02-17 22:39:51 +00:00
float lovrGraphicsGetLineWidth(void);
2019-12-10 21:44:51 +00:00
void lovrGraphicsSetLineWidth(float width);
2019-02-17 22:39:51 +00:00
float lovrGraphicsGetPointSize(void);
2017-08-02 07:54:33 +00:00
void lovrGraphicsSetPointSize(float size);
2019-04-05 11:58:29 +00:00
struct Shader* lovrGraphicsGetShader(void);
void lovrGraphicsSetShader(struct Shader* shader);
void lovrGraphicsGetStencilTest(CompareMode* mode, int* value);
void lovrGraphicsSetStencilTest(CompareMode mode, int value);
2019-02-17 22:39:51 +00:00
Winding lovrGraphicsGetWinding(void);
2017-08-02 07:54:33 +00:00
void lovrGraphicsSetWinding(Winding winding);
2019-02-17 22:39:51 +00:00
bool lovrGraphicsIsWireframe(void);
2017-10-31 08:14:09 +00:00
void lovrGraphicsSetWireframe(bool wireframe);
2016-11-23 05:16:13 +00:00
// Transforms
2019-02-17 22:39:51 +00:00
void lovrGraphicsPush(void);
void lovrGraphicsPop(void);
void lovrGraphicsOrigin(void);
2018-11-27 23:03:05 +00:00
void lovrGraphicsTranslate(vec3 translation);
void lovrGraphicsRotate(quat rotation);
void lovrGraphicsScale(vec3 scale);
2018-03-05 07:06:34 +00:00
void lovrGraphicsMatrixTransform(mat4 transform);
2016-11-23 05:16:13 +00:00
// Rendering
2019-02-17 22:39:51 +00:00
void lovrGraphicsFlush(void);
2019-04-05 11:58:29 +00:00
void lovrGraphicsFlushCanvas(struct Canvas* canvas);
void lovrGraphicsFlushShader(struct Shader* shader);
void lovrGraphicsFlushMaterial(struct Material* material);
void lovrGraphicsFlushMesh(struct Mesh* mesh);
2019-06-28 04:04:15 +00:00
void lovrGraphicsClear(Color* color, float* depth, int* stencil);
void lovrGraphicsDiscard(bool color, bool depth, bool stencil);
void lovrGraphicsPoints(uint32_t count, float** vertices);
void lovrGraphicsLine(uint32_t count, float** vertices);
2019-04-05 12:34:28 +00:00
void lovrGraphicsPlane(DrawStyle style, struct Material* material, mat4 transform, float u, float v, float w, float h);
2019-04-05 11:58:29 +00:00
void lovrGraphicsBox(DrawStyle style, struct Material* material, mat4 transform);
void lovrGraphicsArc(DrawStyle style, ArcMode mode, struct Material* material, mat4 transform, float r1, float r2, int segments);
void lovrGraphicsCircle(DrawStyle style, struct Material* material, mat4 transform, int segments);
void lovrGraphicsCylinder(struct Material* material, mat4 transform, float r1, float r2, bool capped, int segments);
void lovrGraphicsSphere(struct Material* material, mat4 transform, int segments);
void lovrGraphicsSkybox(struct Texture* texture);
void lovrGraphicsPrint(const char* str, size_t length, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
2019-04-05 11:58:29 +00:00
void lovrGraphicsFill(struct Texture* texture, float u, float v, float w, float h);
2019-06-27 20:35:43 +00:00
void lovrGraphicsDrawMesh(struct Mesh* mesh, mat4 transform, uint32_t instances, float* pose);
2018-08-31 13:03:35 +00:00
#define lovrGraphicsStencil lovrGpuStencil
2018-08-09 00:53:59 +00:00
#define lovrGraphicsCompute lovrGpuCompute
2018-07-17 10:35:01 +00:00
// GPU
typedef struct {
2019-06-10 06:59:57 +00:00
bool astc;
2019-01-16 16:52:21 +00:00
bool compute;
2019-06-10 06:59:57 +00:00
bool dxt;
2019-06-25 08:06:55 +00:00
bool instancedStereo;
bool multiview;
bool timers;
} GpuFeatures;
typedef struct {
float pointSizes[2];
int textureSize;
int textureMSAA;
float textureAnisotropy;
int blockSize;
int blockAlign;
2020-09-18 02:42:54 +00:00
int compute[3];
} GpuLimits;
typedef struct {
2019-09-07 22:07:07 +00:00
uint32_t shaderSwitches;
2020-01-31 11:35:42 +00:00
uint32_t renderPasses;
2019-09-07 22:07:07 +00:00
uint32_t drawCalls;
2020-01-31 11:35:42 +00:00
uint32_t bufferCount;
uint32_t textureCount;
uint64_t bufferMemory;
uint64_t textureMemory;
} GpuStats;
2018-12-25 04:26:47 +00:00
typedef struct {
2019-04-05 11:58:29 +00:00
struct Mesh* mesh;
struct Canvas* canvas;
struct Shader* shader;
2018-12-25 04:26:47 +00:00
Pipeline pipeline;
DrawMode topology;
uint32_t rangeStart;
uint32_t rangeCount;
uint32_t instances;
2018-12-25 04:26:47 +00:00
} DrawCommand;
2021-02-20 06:10:24 +00:00
void lovrGpuInit(void (*getProcAddress(const char*))(void), bool debug);
2019-02-17 22:39:51 +00:00
void lovrGpuDestroy(void);
2019-04-05 11:58:29 +00:00
void lovrGpuClear(struct Canvas* canvas, Color* color, float* depth, int* stencil);
void lovrGpuCompute(struct Shader* shader, int x, int y, int z);
void lovrGpuDiscard(struct Canvas* canvas, bool color, bool depth, bool stencil);
void lovrGpuDraw(DrawCommand* draw);
2018-08-31 13:03:35 +00:00
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata);
2019-02-17 22:39:51 +00:00
void lovrGpuPresent(void);
void lovrGpuDirtyTexture(void);
void lovrGpuTick(const char* label);
double lovrGpuTock(const char* label);
const GpuFeatures* lovrGpuGetFeatures(void);
2019-02-17 22:39:51 +00:00
const GpuLimits* lovrGpuGetLimits(void);
const GpuStats* lovrGpuGetStats(void);