From 3c6437fb20845eb5f64f8f647e8ef3b343b45ec6 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 22 Nov 2017 20:26:01 -0800 Subject: [PATCH] lovr.graphics.isGammaCorrect; conf.lua t.gammacorrect; --- src/api/graphics.c | 17 +++++++++++++++-- src/data/boot.lua | 1 + src/graphics/graphics.c | 13 +++++++++++++ src/graphics/graphics.h | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/api/graphics.c b/src/api/graphics.c index 6697edca..b67e8a85 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -172,10 +172,16 @@ int l_lovrGraphicsInit(lua_State* L) { lovrGraphicsInit(); - // Create window luax_pushconf(L); - lua_getfield(L, -1, "window"); + // Set gamma correct + lua_getfield(L, -1, "gammacorrect"); + bool gammaCorrect = lua_toboolean(L, -1); + lovrGraphicsSetGammaCorrect(gammaCorrect); + lua_pop(L, 1); + + // Create window if needed + lua_getfield(L, -1, "window"); if (!lua_isnil(L, -1)) { lua_getfield(L, -1, "width"); int width = luaL_checkinteger(L, -1); @@ -360,6 +366,12 @@ int l_lovrGraphicsSetFont(lua_State* L) { return 0; } +int l_lovrGraphicsIsGammaCorrect(lua_State* L) { + bool gammaCorrect = lovrGraphicsIsGammaCorrect(); + lua_pushboolean(L, gammaCorrect); + return 1; +} + int l_lovrGraphicsGetSystemLimits(lua_State* L) { GraphicsLimits limits = lovrGraphicsGetLimits(); lua_newtable(L); @@ -855,6 +867,7 @@ const luaL_Reg lovrGraphics[] = { { "setDepthTest", l_lovrGraphicsSetDepthTest }, { "getFont", l_lovrGraphicsGetFont }, { "setFont", l_lovrGraphicsSetFont }, + { "isGammaCorrect", l_lovrGraphicsIsGammaCorrect }, { "getSystemLimits", l_lovrGraphicsGetSystemLimits }, { "getLineWidth", l_lovrGraphicsGetLineWidth }, { "setLineWidth", l_lovrGraphicsSetLineWidth }, diff --git a/src/data/boot.lua b/src/data/boot.lua index 8a3c17ce..111c5960 100644 --- a/src/data/boot.lua +++ b/src/data/boot.lua @@ -8,6 +8,7 @@ local conf = { physics = true, timer = true }, + gammacorrect = false, headset = { mirror = true, offset = 1.7 diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 33353486..7bc3b6ae 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -196,6 +196,11 @@ void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const cha glEnable(GL_LINE_SMOOTH); glEnable(GL_PROGRAM_POINT_SIZE); #endif + if (state.gammaCorrect) { + glEnable(GL_FRAMEBUFFER_SRGB); + } else { + glDisable(GL_FRAMEBUFFER_SRGB); + } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -358,6 +363,14 @@ void lovrGraphicsSetFont(Font* font) { } } +bool lovrGraphicsIsGammaCorrect() { + return state.gammaCorrect; +} + +void lovrGraphicsSetGammaCorrect(bool gammaCorrect) { + state.gammaCorrect = gammaCorrect; +} + GraphicsLimits lovrGraphicsGetLimits() { if (!state.limits.initialized) { #ifdef EMSCRIPTEN diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 9ad14d56..15b0f892 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -92,6 +92,7 @@ typedef struct { TextureFilter defaultFilter; CompareMode depthTest; Font* font; + bool gammaCorrect; GraphicsLimits limits; float lineWidth; Material* material; @@ -139,6 +140,8 @@ CompareMode lovrGraphicsGetDepthTest(); void lovrGraphicsSetDepthTest(CompareMode depthTest); Font* lovrGraphicsGetFont(); void lovrGraphicsSetFont(Font* font); +bool lovrGraphicsIsGammaCorrect(); +void lovrGraphicsSetGammaCorrect(bool gammaCorrect); GraphicsLimits lovrGraphicsGetLimits(); float lovrGraphicsGetLineWidth(); void lovrGraphicsSetLineWidth(float width);