mirror of https://github.com/bjornbytes/lovr.git
Organize lovr.graphics;
This commit is contained in:
parent
f18ee761cd
commit
a5fd7962f4
|
@ -10,6 +10,8 @@
|
|||
|
||||
static GraphicsState state;
|
||||
|
||||
// Base
|
||||
|
||||
void lovrGraphicsInit() {
|
||||
vec_init(&state.transforms);
|
||||
state.projection = mat4_init();
|
||||
|
@ -86,6 +88,8 @@ void lovrGraphicsPrepare() {
|
|||
lovrShaderBind(shader, vec_last(&state.transforms), state.projection, state.color, 0);
|
||||
}
|
||||
|
||||
// State
|
||||
|
||||
void lovrGraphicsGetBackgroundColor(float* r, float* g, float* b, float* a) {
|
||||
GLfloat clearColor[4];
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
|
||||
|
@ -245,6 +249,20 @@ void lovrGraphicsSetWireframe(int wireframe) {
|
|||
}
|
||||
}
|
||||
|
||||
int lovrGraphicsGetWidth() {
|
||||
int width;
|
||||
glfwGetFramebufferSize(window, &width, NULL);
|
||||
return width;
|
||||
}
|
||||
|
||||
int lovrGraphicsGetHeight() {
|
||||
int height;
|
||||
glfwGetFramebufferSize(window, NULL, &height);
|
||||
return height;
|
||||
}
|
||||
|
||||
// Transforms
|
||||
|
||||
int lovrGraphicsPush() {
|
||||
vec_mat4_t* transforms = &state.transforms;
|
||||
if (transforms->length >= 64) { return 1; }
|
||||
|
@ -307,17 +325,7 @@ void lovrGraphicsMatrixTransform(mat4 transform) {
|
|||
mat4_multiply(vec_last(&state.transforms), transform);
|
||||
}
|
||||
|
||||
int lovrGraphicsGetWidth() {
|
||||
int width;
|
||||
glfwGetFramebufferSize(window, &width, NULL);
|
||||
return width;
|
||||
}
|
||||
|
||||
int lovrGraphicsGetHeight() {
|
||||
int height;
|
||||
glfwGetFramebufferSize(window, NULL, &height);
|
||||
return height;
|
||||
}
|
||||
// Primitives
|
||||
|
||||
void lovrGraphicsSetShapeData(float* data, int dataCount, unsigned int* indices, int indicesCount) {
|
||||
vec_clear(&state.shapeIndices);
|
||||
|
|
|
@ -58,12 +58,15 @@ typedef struct {
|
|||
|
||||
#endif
|
||||
|
||||
// Base
|
||||
void lovrGraphicsInit();
|
||||
void lovrGraphicsDestroy();
|
||||
void lovrGraphicsReset();
|
||||
void lovrGraphicsClear(int color, int depth);
|
||||
void lovrGraphicsPresent();
|
||||
void lovrGraphicsPrepare();
|
||||
|
||||
// State
|
||||
void lovrGraphicsGetBackgroundColor(float* r, float* g, float* b, float* a);
|
||||
void lovrGraphicsSetBackgroundColor(float r, float g, float b, float a);
|
||||
void lovrGraphicsGetColor(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a);
|
||||
|
@ -90,6 +93,10 @@ CompareMode lovrGraphicsGetDepthTest();
|
|||
void lovrGraphicsSetDepthTest(CompareMode depthTest);
|
||||
int lovrGraphicsIsWireframe();
|
||||
void lovrGraphicsSetWireframe(int wireframe);
|
||||
int lovrGraphicsGetWidth();
|
||||
int lovrGraphicsGetHeight();
|
||||
|
||||
// Transforms
|
||||
int lovrGraphicsPush();
|
||||
int lovrGraphicsPop();
|
||||
void lovrGraphicsOrigin();
|
||||
|
@ -98,8 +105,8 @@ void lovrGraphicsRotate(float w, float x, float y, float z);
|
|||
void lovrGraphicsScale(float x, float y, float z);
|
||||
void lovrGraphicsTransform(float tx, float ty, float tz, float sx, float sy, float sz, float angle, float ax, float ay, float az);
|
||||
void lovrGraphicsMatrixTransform(mat4 transform);
|
||||
int lovrGraphicsGetWidth();
|
||||
int lovrGraphicsGetHeight();
|
||||
|
||||
// Primitives
|
||||
void lovrGraphicsSetShapeData(float* data, int dataCount, unsigned int* indices, int indicesCount);
|
||||
void lovrGraphicsDrawLinedShape(GLenum mode);
|
||||
void lovrGraphicsDrawFilledShape();
|
||||
|
|
|
@ -88,6 +88,8 @@ const luaL_Reg lovrGraphics[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
// Base
|
||||
|
||||
int l_lovrGraphicsInit(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrGraphics);
|
||||
|
@ -160,6 +162,8 @@ int l_lovrGraphicsPresent(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// State
|
||||
|
||||
int l_lovrGraphicsGetBackgroundColor(lua_State* L) {
|
||||
float r, g, b, a;
|
||||
lovrGraphicsGetBackgroundColor(&r, &g, &b, &a);
|
||||
|
@ -343,6 +347,24 @@ int l_lovrGraphicsSetWireframe(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetWidth(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetHeight(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetDimensions(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetWidth());
|
||||
lua_pushnumber(L, lovrGraphicsGetHeight());
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Transforms
|
||||
|
||||
int l_lovrGraphicsPush(lua_State* L) {
|
||||
if (lovrGraphicsPush()) {
|
||||
return luaL_error(L, "Unbalanced matrix stack (more pushes than pops?)");
|
||||
|
@ -395,6 +417,8 @@ int l_lovrGraphicsScale(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Primitives
|
||||
|
||||
int l_lovrGraphicsPoints(lua_State* L) {
|
||||
vec_float_t points;
|
||||
vec_init(&points);
|
||||
|
@ -454,21 +478,7 @@ int l_lovrGraphicsCube(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetWidth(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetHeight(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsGetDimensions(lua_State* L) {
|
||||
lua_pushnumber(L, lovrGraphicsGetWidth());
|
||||
lua_pushnumber(L, lovrGraphicsGetHeight());
|
||||
return 2;
|
||||
}
|
||||
// Types
|
||||
|
||||
int l_lovrGraphicsNewBuffer(lua_State* L) {
|
||||
int size;
|
||||
|
|
|
@ -13,10 +13,14 @@ map_int_t FilterModes;
|
|||
map_int_t WrapModes;
|
||||
|
||||
extern const luaL_Reg lovrGraphics[];
|
||||
|
||||
// Base
|
||||
int l_lovrGraphicsInit(lua_State* L);
|
||||
int l_lovrGraphicsReset(lua_State* L);
|
||||
int l_lovrGraphicsClear(lua_State* L);
|
||||
int l_lovrGraphicsPresent(lua_State* L);
|
||||
|
||||
// State
|
||||
int l_lovrGraphicsGetBackgroundColor(lua_State* L);
|
||||
int l_lovrGraphicsSetBackgroundColor(lua_State* L);
|
||||
int l_lovrGraphicsGetColor(lua_State* L);
|
||||
|
@ -40,20 +44,26 @@ int l_lovrGraphicsGetDepthTest(lua_State* L);
|
|||
int l_lovrGraphicsSetDepthTest(lua_State* L);
|
||||
int l_lovrGraphicsIsWireframe(lua_State* L);
|
||||
int l_lovrGraphicsSetWireframe(lua_State* L);
|
||||
int l_lovrGraphicsGetWidth(lua_State* L);
|
||||
int l_lovrGraphicsGetHeight(lua_State* L);
|
||||
int l_lovrGraphicsGetDimensions(lua_State* L);
|
||||
|
||||
// Transforms
|
||||
int l_lovrGraphicsPush(lua_State* L);
|
||||
int l_lovrGraphicsPop(lua_State* L);
|
||||
int l_lovrGraphicsOrigin(lua_State* L);
|
||||
int l_lovrGraphicsTranslate(lua_State* L);
|
||||
int l_lovrGraphicsRotate(lua_State* L);
|
||||
int l_lovrGraphicsScale(lua_State* L);
|
||||
|
||||
// Primitives
|
||||
int l_lovrGraphicsPoints(lua_State* L);
|
||||
int l_lovrGraphicsLine(lua_State* L);
|
||||
int l_lovrGraphicsTriangle(lua_State* L);
|
||||
int l_lovrGraphicsPlane(lua_State* L);
|
||||
int l_lovrGraphicsCube(lua_State* L);
|
||||
int l_lovrGraphicsGetWidth(lua_State* L);
|
||||
int l_lovrGraphicsGetHeight(lua_State* L);
|
||||
int l_lovrGraphicsGetDimensions(lua_State* L);
|
||||
|
||||
// Types
|
||||
int l_lovrGraphicsNewBuffer(lua_State* L);
|
||||
int l_lovrGraphicsNewModel(lua_State* L);
|
||||
int l_lovrGraphicsNewShader(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue