lovr/src/graphics/graphics.h

138 lines
4.3 KiB
C
Raw Normal View History

2016-11-19 09:28:01 +00:00
#include "graphics/buffer.h"
#include "graphics/model.h"
#include "graphics/shader.h"
#include "graphics/skybox.h"
2016-11-27 02:58:58 +00:00
#include "graphics/texture.h"
2017-01-21 03:55:54 +00:00
#include "math/math.h"
2016-09-21 07:55:53 +00:00
#ifndef LOVR_GRAPHICS_TYPES
#define LOVR_GRAPHICS_TYPES
2016-09-27 06:48:09 +00:00
2016-11-27 18:57:36 +00:00
#define MAX_TRANSFORMS 64
2017-01-11 17:22:18 +00:00
#define MAX_CANVASES 4
2016-09-29 04:47:36 +00:00
2016-09-30 02:39:25 +00:00
typedef enum {
2016-10-01 19:10:38 +00:00
DRAW_MODE_FILL,
DRAW_MODE_LINE
2016-09-30 02:39:25 +00:00
} DrawMode;
2016-10-03 19:02:49 +00:00
typedef enum {
POLYGON_WINDING_CLOCKWISE = GL_CW,
POLYGON_WINDING_COUNTERCLOCKWISE = GL_CCW
} PolygonWinding;
2016-11-23 04:59:11 +00:00
typedef enum {
2016-11-24 23:45:59 +00:00
COMPARE_NONE = 0,
2016-11-23 04:59:11 +00:00
COMPARE_EQUAL = GL_EQUAL,
COMPARE_NOT_EQUAL = GL_NOTEQUAL,
COMPARE_LESS = GL_LESS,
COMPARE_LEQUAL = GL_LEQUAL,
COMPARE_GEQUAL = GL_GEQUAL,
COMPARE_GREATER = GL_GREATER
} CompareMode;
2017-01-11 17:22:18 +00:00
typedef struct {
int x;
int y;
int width;
int height;
} ScissorRectangle;
typedef struct CanvasState {
int framebuffer;
2017-01-12 09:26:44 +00:00
float projection[16];
2017-01-11 17:22:18 +00:00
int viewport[4];
} CanvasState;
2016-09-27 06:48:09 +00:00
typedef struct {
Shader* activeShader;
2016-09-28 02:56:36 +00:00
Shader* defaultShader;
2016-10-24 22:02:23 +00:00
Shader* skyboxShader;
2017-01-13 09:59:00 +00:00
Shader* fullscreenShader;
2016-11-27 02:58:58 +00:00
Texture* defaultTexture;
2017-01-20 02:04:45 +00:00
float transforms[MAX_TRANSFORMS][16];
CanvasState* canvases[MAX_CANVASES];
2016-11-27 18:57:36 +00:00
int transform;
2017-01-11 17:22:18 +00:00
int canvas;
2016-09-29 03:11:58 +00:00
unsigned int color;
2016-10-03 18:41:31 +00:00
char colorMask;
2016-11-23 05:07:33 +00:00
int isScissorEnabled;
2016-09-29 04:47:36 +00:00
ScissorRectangle scissor;
2016-09-29 07:00:02 +00:00
GLuint shapeArray;
GLuint shapeBuffer;
2016-09-30 06:18:51 +00:00
GLuint shapeIndexBuffer;
2016-09-29 07:00:02 +00:00
vec_float_t shapeData;
2016-09-30 06:18:51 +00:00
vec_uint_t shapeIndices;
2016-10-01 20:48:31 +00:00
float lineWidth;
2016-11-13 01:38:49 +00:00
float pointSize;
2016-11-23 05:07:33 +00:00
int isCullingEnabled;
2016-10-03 19:02:49 +00:00
PolygonWinding polygonWinding;
2016-11-23 04:59:11 +00:00
CompareMode depthTest;
2016-11-23 05:07:33 +00:00
int isWireframe;
2016-09-27 06:48:09 +00:00
} GraphicsState;
2016-11-23 05:07:33 +00:00
2016-09-21 07:55:53 +00:00
#endif
2016-07-07 07:04:24 +00:00
2016-11-23 05:16:13 +00:00
// Base
2016-08-10 06:28:17 +00:00
void lovrGraphicsInit();
void lovrGraphicsDestroy();
2016-09-28 03:20:08 +00:00
void lovrGraphicsReset();
2016-09-17 03:11:11 +00:00
void lovrGraphicsClear(int color, int depth);
2016-08-10 06:28:17 +00:00
void lovrGraphicsPresent();
2016-09-24 03:58:56 +00:00
void lovrGraphicsPrepare();
2016-11-23 05:16:13 +00:00
// State
2016-09-28 04:37:46 +00:00
void lovrGraphicsGetBackgroundColor(float* r, float* g, float* b, float* a);
void lovrGraphicsSetBackgroundColor(float r, float g, float b, float a);
2016-09-29 03:11:58 +00:00
void lovrGraphicsGetColor(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a);
void lovrGraphicsSetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
2016-10-03 18:41:31 +00:00
void lovrGraphicsGetColorMask(char* r, char* g, char* b, char* a);
void lovrGraphicsSetColorMask(char r, char g, char b, char a);
2016-11-23 05:07:33 +00:00
int lovrGraphicsIsScissorEnabled();
void lovrGraphicsSetScissorEnabled(int isEnabled);
2016-09-29 04:47:36 +00:00
void lovrGraphicsGetScissor(int* x, int* y, int* width, int* height);
void lovrGraphicsSetScissor(int x, int y, int width, int height);
2016-09-14 00:02:23 +00:00
Shader* lovrGraphicsGetShader();
2016-08-10 06:28:17 +00:00
void lovrGraphicsSetShader(Shader* shader);
2016-11-27 10:06:47 +00:00
void lovrGraphicsBindTexture(Texture* texture);
2017-01-13 09:59:00 +00:00
mat4 lovrGraphicsGetProjection();
2016-09-27 06:48:09 +00:00
void lovrGraphicsSetProjection(float near, float far, float fov);
2017-01-12 04:26:08 +00:00
void lovrGraphicsSetProjectionRaw(mat4 projection);
2016-10-01 20:48:31 +00:00
float lovrGraphicsGetLineWidth();
void lovrGraphicsSetLineWidth(float width);
2016-11-13 01:38:49 +00:00
float lovrGraphicsGetPointSize();
void lovrGraphicsSetPointSize(float size);
2016-11-23 05:07:33 +00:00
int lovrGraphicsIsCullingEnabled();
void lovrGraphicsSetCullingEnabled(int isEnabled);
2016-10-03 19:02:49 +00:00
PolygonWinding lovrGraphicsGetPolygonWinding();
void lovrGraphicsSetPolygonWinding(PolygonWinding winding);
2016-11-23 04:59:11 +00:00
CompareMode lovrGraphicsGetDepthTest();
void lovrGraphicsSetDepthTest(CompareMode depthTest);
2016-11-23 05:07:33 +00:00
int lovrGraphicsIsWireframe();
void lovrGraphicsSetWireframe(int wireframe);
2016-11-23 05:16:13 +00:00
int lovrGraphicsGetWidth();
int lovrGraphicsGetHeight();
2017-01-12 04:26:08 +00:00
void lovrGraphicsPushCanvas();
2017-01-11 17:22:18 +00:00
void lovrGraphicsPopCanvas();
2017-01-12 04:26:08 +00:00
void lovrGraphicsSetViewport(int x, int y, int w, int h);
void lovrGraphicsBindFramebuffer(int framebuffer);
2016-11-23 05:16:13 +00:00
// Transforms
2016-09-21 07:55:53 +00:00
int lovrGraphicsPush();
int lovrGraphicsPop();
2016-09-21 22:26:05 +00:00
void lovrGraphicsOrigin();
void lovrGraphicsTranslate(float x, float y, float z);
2016-12-02 01:32:39 +00:00
void lovrGraphicsRotate(float angle, float ax, float ay, float az);
void lovrGraphicsScale(float x, float y, float z);
2016-11-02 03:48:04 +00:00
void lovrGraphicsMatrixTransform(mat4 transform);
2016-11-23 05:16:13 +00:00
// Primitives
2017-01-13 09:59:00 +00:00
void lovrGraphicsDrawPrimitive(GLenum mode, Texture* texture, int hasNormals, int hasTexCoords, int useIndices);
2016-11-08 07:16:33 +00:00
void lovrGraphicsPoints(float* points, int count);
2016-09-30 02:39:25 +00:00
void lovrGraphicsLine(float* points, int count);
2016-11-23 04:43:22 +00:00
void lovrGraphicsTriangle(DrawMode mode, float* points);
2017-01-13 09:59:00 +00:00
void lovrGraphicsPlane(DrawMode mode, Texture* texture, float x, float y, float z, float size, float nx, float ny, float nz);
void lovrGraphicsPlaneFullscreen(Texture* texture);
void lovrGraphicsCube(DrawMode mode, Texture* texture, mat4 transform);
2016-10-24 22:02:23 +00:00
void lovrGraphicsSkybox(Skybox* skybox, float angle, float ax, float ay, float az);