Skip to content

Commit 8c6f1af

Browse files
TheLastRarSternXD
authored andcommitted
GS/GL: Replace GLState::Clear with Init() and Invalidate()
1 parent bdbed59 commit 8c6f1af

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

pcsx2/GS/Renderers/OpenGL/GLState.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ namespace GLState
5252
return draw_buffers;
5353
}
5454

55-
void Clear()
55+
void Init()
5656
{
57+
// Set the state to match initial API values.
5758
vao = 0;
5859
fbo = 0;
5960
viewport = GSVector2i(1, 1);
@@ -90,4 +91,35 @@ namespace GLState
9091

9192
std::fill(std::begin(tex_unit), std::end(tex_unit), 0);
9293
}
94+
95+
void Invalidate()
96+
{
97+
Init();
98+
99+
// Set the state to invalid values (or fetch from the API).
100+
blend = glIsEnabled(GL_BLEND);
101+
eq_RGB = 0xFFFF;
102+
f_sRGB = 0xFFFF;
103+
f_dRGB = 0xFFFF;
104+
f_sA = 0xFFFF;
105+
f_dA = 0xFFFF;
106+
{
107+
// We only track a single value for all channels.
108+
// So instead reset back to default values.
109+
glBlendColor(0, 0, 0, 0);
110+
}
111+
wrgba = 0xFF;
112+
113+
depth = glIsEnabled(GL_DEPTH_TEST);
114+
depth_func = 0xFFFFFFFF;
115+
{
116+
GLboolean mask;
117+
glGetBooleanv(GL_DEPTH_WRITEMASK, &mask);
118+
depth_mask = mask;
119+
}
120+
121+
stencil = glIsEnabled(GL_STENCIL_TEST);
122+
stencil_func = 0xFFFFFFFF;
123+
stencil_pass = 0xFFFFFFFF;
124+
}
93125
} // namespace GLState

pcsx2/GS/Renderers/OpenGL/GLState.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ namespace GLState
5151
extern GLuint tex_unit[8]; // shader input texture
5252

5353
extern u32 UpdateDrawBuffers();
54-
extern void Clear();
54+
// Initilise GLState to initial api state.
55+
extern void Init();
56+
// Invalidate GLState, used when the api state was modified without updating this class.
57+
extern void Invalidate();
5558
} // namespace GLState

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool GSDeviceOGL::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
286286
}
287287

288288
// because of fbo bindings below...
289-
GLState::Clear();
289+
GLState::Init();
290290

291291
// ****************************************************************
292292
// Debug helper
@@ -3448,13 +3448,13 @@ bool GSDeviceOGL::DoLibrashader(GSTexture* sTex, GSTexture* dTex)
34483448
libra_error_t err = libra_gl_filter_chain_frame(&chain, m_librashader_frame_count, input, output, &vp, nullptr, &frame_opts);
34493449
if (err)
34503450
{
3451-
libra_error_free(&err);
3452-
GLState::Clear();
3451+
Console.ErrorFmt("librashader: OpenGL frame rendering failed: {}", GetLibrashaderError(err));
3452+
GLState::Invalidate();
34533453
return false;
34543454
}
34553455

34563456
// librashader binds its own program/FBO/samplers wipe our cache so the next call rebinds.
3457-
GLState::Clear();
3457+
GLState::Invalidate();
34583458
return true;
34593459
}
34603460

0 commit comments

Comments
 (0)