From fe75c666a9dc042265b415965aad65847bc25331 Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 14 Jul 2018 18:35:30 -0700 Subject: [PATCH] Simplify lovr.graphics.getWidth/Height; --- src/api/graphics.c | 14 ++++++++++---- src/graphics/graphics.c | 20 ++++++-------------- src/graphics/graphics.h | 3 +-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/api/graphics.c b/src/api/graphics.c index c054511f..5f5c2974 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -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; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index c9787f4a..ecc80331 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -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() { diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index dba75715..66e5bd72 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -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