Simplify lovr.graphics.getWidth/Height;

This commit is contained in:
bjorn 2018-07-14 18:35:30 -07:00
parent b64489b020
commit fe75c666a9
3 changed files with 17 additions and 20 deletions

View File

@ -345,18 +345,24 @@ int l_lovrGraphicsCreateWindow(lua_State* L) {
}
int l_lovrGraphicsGetWidth(lua_State* L) {
lua_pushnumber(L, lovrGraphicsGetWidth());
int width;
lovrGraphicsGetDimensions(&width, NULL);
lua_pushnumber(L, width);
return 1;
}
int l_lovrGraphicsGetHeight(lua_State* L) {
lua_pushnumber(L, lovrGraphicsGetHeight());
int height;
lovrGraphicsGetDimensions(NULL, &height);
lua_pushnumber(L, height);
return 1;
}
int l_lovrGraphicsGetDimensions(lua_State* L) {
lua_pushnumber(L, lovrGraphicsGetWidth());
lua_pushnumber(L, lovrGraphicsGetHeight());
int width, height;
lovrGraphicsGetDimensions(&width, &height);
lua_pushnumber(L, width);
lua_pushnumber(L, height);
return 2;
}

View File

@ -46,12 +46,12 @@ void lovrGraphicsDestroy() {
}
void lovrGraphicsReset() {
int w = lovrGraphicsGetWidth();
int h = lovrGraphicsGetHeight();
int width, height;
lovrGraphicsGetDimensions(&width, &height);
state.transform = 0;
state.layer = 0;
memcpy(state.layers[state.layer].viewport, (int[]) { 0, 0, w, h }, 4 * sizeof(uint32_t));
mat4_perspective(state.layers[state.layer].projection, .01f, 100.f, 67 * M_PI / 180., (float) w / h);
memcpy(state.layers[state.layer].viewport, (int[]) { 0, 0, width, height }, 4 * sizeof(uint32_t));
mat4_perspective(state.layers[state.layer].projection, .01f, 100.f, 67 * M_PI / 180., (float) width / height);
mat4_identity(state.layers[state.layer].view);
lovrGraphicsSetBackgroundColor((Color) { 0, 0, 0, 1. });
lovrGraphicsSetBlendMode(BLEND_ALPHA, BLEND_ALPHA_MULTIPLY);
@ -140,16 +140,8 @@ void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const cha
state.initialized = true;
}
int lovrGraphicsGetWidth() {
int width, height;
glfwGetFramebufferSize(state.window, &width, &height);
return width;
}
int lovrGraphicsGetHeight() {
int width, height;
glfwGetFramebufferSize(state.window, &width, &height);
return height;
void lovrGraphicsGetDimensions(int* width, int* height) {
glfwGetFramebufferSize(state.window, width, height);
}
GpuStats lovrGraphicsGetStats() {

View File

@ -70,8 +70,7 @@ void lovrGraphicsReset();
void lovrGraphicsClear(Color* color, float* depth, int* stencil);
void lovrGraphicsPresent();
void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const char* title, const char* icon);
int lovrGraphicsGetWidth();
int lovrGraphicsGetHeight();
void lovrGraphicsGetDimensions(int* width, int* height);
GpuStats lovrGraphicsGetStats();
// State