From 62645cde28eff7761ea81da32ec36da9ee22378f Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 24 Dec 2018 19:19:08 -0800 Subject: [PATCH] Pipeline -> 4 bytes; lineWidth -> uint8_t; --- src/api/graphics.c | 2 +- src/graphics/graphics.c | 3 ++- src/graphics/graphics.h | 24 ++++++++++++------------ src/graphics/opengl.c | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/api/graphics.c b/src/api/graphics.c index 39f75b92..7c9ced50 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -526,7 +526,7 @@ static int l_lovrGraphicsGetLineWidth(lua_State* L) { } static int l_lovrGraphicsSetLineWidth(lua_State* L) { - float width = luaL_optnumber(L, 1, 1.f); + uint8_t width = (uint8_t) luaL_optinteger(L, 1, 1); lovrGraphicsSetLineWidth(width); return 0; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 401fae38..599b3740 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -297,7 +297,8 @@ float lovrGraphicsGetLineWidth() { return state.pipeline->lineWidth; } -void lovrGraphicsSetLineWidth(float width) { +void lovrGraphicsSetLineWidth(uint8_t width) { + lovrAssert(width > 0 && width <= 255, "Line width must be between 0 and 255"); state.pipeline->lineWidth = width; } diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 504d3bd4..93000432 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -100,17 +100,17 @@ typedef struct { } Camera; typedef struct { - bool alphaSampling; - BlendMode blendMode; - BlendAlphaMode blendAlphaMode; - bool culling; - CompareMode depthTest; - bool depthWrite; - float lineWidth; - CompareMode stencilMode; - int stencilValue; - Winding winding; - bool wireframe; + BlendMode blendMode : 3; + BlendAlphaMode blendAlphaMode : 1; + CompareMode depthTest : 3; + bool depthWrite : 1; + uint8_t lineWidth : 8; + uint8_t stencilValue: 8; + CompareMode stencilMode : 3; + bool alphaSampling : 1; + bool culling : 1; + Winding winding : 1; + bool wireframe : 1; } Pipeline; typedef struct { @@ -198,7 +198,7 @@ Font* lovrGraphicsGetFont(); void lovrGraphicsSetFont(Font* font); bool lovrGraphicsIsGammaCorrect(); float lovrGraphicsGetLineWidth(); -void lovrGraphicsSetLineWidth(float width); +void lovrGraphicsSetLineWidth(uint8_t width); float lovrGraphicsGetPointSize(); void lovrGraphicsSetPointSize(float size); Shader* lovrGraphicsGetShader(); diff --git a/src/graphics/opengl.c b/src/graphics/opengl.c index 20a0115b..0a9b805c 100644 --- a/src/graphics/opengl.c +++ b/src/graphics/opengl.c @@ -47,7 +47,7 @@ static struct { bool depthEnabled; CompareMode depthTest; bool depthWrite; - float lineWidth; + uint8_t lineWidth; bool stencilEnabled; CompareMode stencilMode; int stencilValue;