Fix background colors;

This commit is contained in:
bjorn 2022-08-05 21:05:02 -07:00
parent cb59f64a7b
commit fcbeccdfb1
5 changed files with 46 additions and 1 deletions

View File

@ -14,7 +14,7 @@ function lovr.load()
return
end
lovr.graphics.getWindowPass():setClear(0x20232c)
lovr.graphics.setBackground(0x20232c)
--[=[
logo = lovr.graphics.newShader([[

View File

@ -805,6 +805,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_lovrGraphicsGetWindowPass(lua_State* L) {
Pass* pass = lovrGraphicsGetWindowPass();
luax_pushtype(L, Pass, pass);
@ -1481,6 +1498,8 @@ static const luaL_Reg lovrGraphics[] = {
{ "getFeatures", l_lovrGraphicsGetFeatures },
{ "getLimits", l_lovrGraphicsGetLimits },
{ "isFormatSupported", l_lovrGraphicsIsFormatSupported },
{ "getBackground", l_lovrGraphicsGetBackground },
{ "setBackground", l_lovrGraphicsSetBackground },
{ "getWindowPass", l_lovrGraphicsGetWindowPass },
{ "getDefaultFont", l_lovrGraphicsGetDefaultFont },
{ "getBuffer", l_lovrGraphicsGetBuffer },

View File

@ -362,6 +362,7 @@ static struct {
gpu_device_info device;
gpu_features features;
gpu_limits limits;
float background[4];
Texture* window;
Pass* windowPass;
Font* defaultFont;
@ -754,6 +755,20 @@ void lovrGraphicsGetShaderCache(void* data, size_t* size) {
gpu_pipeline_get_cache(data, size);
}
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;
@ -3409,6 +3424,10 @@ void lovrPassReset(Pass* pass) {
} else {
pass->target.color[i].texture = lovrGraphicsGetWindowTexture()->gpu;
}
// The window pass always uses the global clear color. The intent is that exposing a global
// clear color that applies to the window/headset is more friendly than messing with passes.
lovrGraphicsGetBackground(pass->target.color[0].clear);
}
if (canvas->mipmap) {

View File

@ -103,6 +103,9 @@ void lovrGraphicsGetLimits(GraphicsLimits* limits);
bool lovrGraphicsIsFormatSupported(uint32_t format, uint32_t features);
void lovrGraphicsGetShaderCache(void* data, size_t* size);
void lovrGraphicsGetBackground(float background[4]);
void lovrGraphicsSetBackground(float background[4]);
void lovrGraphicsSubmit(Pass** passes, uint32_t count);
void lovrGraphicsPresent(void);
void lovrGraphicsWait(void);

View File

@ -1697,6 +1697,10 @@ static Pass* openxr_getPass(void) {
return NULL;
}
float color[4][4], depth, stencil;
lovrPassGetClear(state.pass, color, &depth, &stencil);
lovrGraphicsGetBackground(color[0]);
lovrPassSetClear(state.pass, color, depth, stencil);
lovrPassSetTarget(state.pass, &texture, NULL);
lovrPassReset(state.pass);