gl_state_tracker: Implement depth dirty flags

This commit is contained in:
ReinUsesLisp 2019-12-29 22:56:21 -03:00
parent b910a83a47
commit 40a2c57df5
4 changed files with 31 additions and 6 deletions

View file

@ -1024,13 +1024,23 @@ void RasterizerOpenGL::SyncPrimitiveRestart() {
}
void RasterizerOpenGL::SyncDepthTestState() {
const auto& regs = system.GPU().Maxwell3D().regs;
auto& gpu = system.GPU().Maxwell3D();
auto& flags = gpu.dirty.flags;
glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE);
const auto& regs = gpu.regs;
if (flags[Dirty::DepthMask]) {
flags[Dirty::DepthMask] = false;
glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE);
}
oglEnable(GL_DEPTH_TEST, regs.depth_test_enable);
if (regs.depth_test_enable) {
glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func));
if (flags[Dirty::DepthTest]) {
flags[Dirty::DepthTest] = false;
if (regs.depth_test_enable) {
glEnable(GL_DEPTH_TEST);
glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func));
} else {
glDisable(GL_DEPTH_TEST);
}
}
}

View file

@ -129,6 +129,13 @@ void SetupDirtyShaders(Tables& tables) {
Shaders);
}
void SetupDirtyDepthTest(Tables& tables) {
auto& table = tables[0];
table[OFF(depth_test_enable)] = DepthTest;
table[OFF(depth_write_enabled)] = DepthMask;
table[OFF(depth_test_func)] = DepthTest;
}
void SetupDirtyBlend(Tables& tables) {
FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendColor);
@ -169,6 +176,7 @@ void StateTracker::Initialize() {
SetupDirtyVertexArrays(tables);
SetupDirtyVertexFormat(tables);
SetupDirtyShaders(tables);
SetupDirtyDepthTest(tables);
SetupDirtyBlend(tables);
SetupDirtyMisc(tables);

View file

@ -58,8 +58,9 @@ enum : u8 {
FrontFace,
CullTest,
PrimitiveRestart,
DepthMask,
DepthTest,
PrimitiveRestart,
StencilTest,
ColorMask,
PolygonOffset,
@ -129,6 +130,11 @@ public:
flags[OpenGL::Dirty::CullTest] = true;
}
void NotifyDepthTest() {
auto& flags = system.GPU().Maxwell3D().dirty.flags;
flags[OpenGL::Dirty::DepthTest] = true;
}
private:
Core::System& system;
};

View file

@ -584,6 +584,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
state_tracker.NotifyFramebuffer();
state_tracker.NotifyFrontFace();
state_tracker.NotifyCullTest();
state_tracker.NotifyDepthTest();
program_manager.UseVertexShader(vertex_program.handle);
program_manager.UseGeometryShader(0);