lovr.graphics.get/setBackground;

This commit is contained in:
bjorn 2022-05-11 15:38:01 -07:00
parent 970a84a514
commit 070e4f304d
3 changed files with 38 additions and 1 deletions

View File

@ -346,7 +346,7 @@ static Canvas luax_checkcanvas(lua_State* L, int index) {
};
for (uint32_t i = 0; i < 4; i++) {
// lovrGraphicsGetBackground(canvas.clears[i]);
lovrGraphicsGetBackground(canvas.clears[i]); // srgb conversion here does not spark joy
}
if (lua_type(L, index) == LUA_TSTRING && !strcmp(lua_tostring(L, index), "window")) {
@ -587,6 +587,23 @@ static int l_lovrGraphicsIsFormatSupported(lua_State* L) {
return 1;
}
static int l_lovrGraphicsGetBackground(lua_State* L) {
float color[4];
lovrGraphicsGetBackground(color);
lua_pushnumber(L, color[0]);
lua_pushnumber(L, color[1]);
lua_pushnumber(L, color[2]);
lua_pushnumber(L, color[3]);
return 4;
}
static int l_lovrGraphicsSetBackground(lua_State* L) {
float color[4];
luax_readcolor(L, 1, color);
lovrGraphicsSetBackground(color);
return 0;
}
static int l_lovrGraphicsPass(lua_State* L) {
PassInfo info;
info.type = luax_checkenum(L, 1, PassType, NULL);
@ -970,6 +987,8 @@ static const luaL_Reg lovrGraphics[] = {
{ "getFeatures", l_lovrGraphicsGetFeatures },
{ "getLimits", l_lovrGraphicsGetLimits },
{ "isFormatSupported", l_lovrGraphicsIsFormatSupported },
{ "getBackground", l_lovrGraphicsGetBackground },
{ "setBackground", l_lovrGraphicsSetBackground },
{ "buffer", l_lovrGraphicsBuffer },
{ "newBuffer", l_lovrGraphicsNewBuffer },
{ "newTexture", l_lovrGraphicsNewTexture },

View File

@ -85,6 +85,7 @@ static struct {
gpu_device_info device;
gpu_features features;
gpu_limits limits;
float background[4];
Texture* window;
Attachment attachments[16];
Allocator allocator;
@ -217,6 +218,20 @@ bool lovrGraphicsIsFormatSupported(uint32_t format, uint32_t features) {
return true;
}
void lovrGraphicsGetBackground(float background[4]) {
background[0] = lovrMathLinearToGamma(state.background[0]);
background[1] = lovrMathLinearToGamma(state.background[1]);
background[2] = lovrMathLinearToGamma(state.background[2]);
background[3] = state.background[3];
}
void lovrGraphicsSetBackground(float background[4]) {
state.background[0] = lovrMathGammaToLinear(background[0]);
state.background[1] = lovrMathGammaToLinear(background[1]);
state.background[2] = lovrMathGammaToLinear(background[2]);
state.background[3] = background[3];
}
void lovrGraphicsSubmit(Pass** passes, uint32_t count) {
if (!state.active) {
return;

View File

@ -78,6 +78,9 @@ void lovrGraphicsGetFeatures(GraphicsFeatures* features);
void lovrGraphicsGetLimits(GraphicsLimits* limits);
bool lovrGraphicsIsFormatSupported(uint32_t format, uint32_t features);
void lovrGraphicsGetBackground(float background[4]);
void lovrGraphicsSetBackground(float background[4]);
void lovrGraphicsSubmit(Pass** passes, uint32_t count);
void lovrGraphicsWait(void);