GL_State: Feedback and fixes

master
Fernando Sahmkow 2019-07-17 17:00:06 +07:00 committed by FernandoS27
parent 5ad889f6fd
commit 4be61013a1
4 changed files with 27 additions and 14 deletions

@ -1129,24 +1129,30 @@ public:
union {
struct {
bool null_dirty;
// Vertex Attributes
bool vertex_attrib_format;
// Vertex Arrays
std::array<bool, 32> vertex_array;
bool vertex_array_buffers;
// Vertex Instances
std::array<bool, 32> vertex_instance;
bool vertex_instances;
// Render Targets
std::array<bool, 8> render_target;
bool depth_buffer;
bool render_settings;
// Shaders
bool shaders;
// State
// Rasterizer State
bool viewport;
bool clip_coefficient;
bool cull_mode;

@ -1059,7 +1059,7 @@ void RasterizerOpenGL::SyncStencilTestState() {
state.stencil.back.action_depth_fail = GL_KEEP;
state.stencil.back.action_depth_pass = GL_KEEP;
}
state.MarkDirtyStencilState(true);
state.MarkDirtyStencilState();
maxwell3d.dirty.stencil_test = false;
}
@ -1081,7 +1081,7 @@ void RasterizerOpenGL::SyncColorMask() {
dest.alpha_enabled = (source.A == 0) ? GL_FALSE : GL_TRUE;
}
state.MarkDirtyColorMask(true);
state.MarkDirtyColorMask();
maxwell3d.dirty.color_mask = false;
}
@ -1125,7 +1125,7 @@ void RasterizerOpenGL::SyncBlendState() {
state.blend[i].enabled = false;
}
maxwell3d.dirty.blend_state = false;
state.MarkDirtyBlendState(true);
state.MarkDirtyBlendState();
return;
}
@ -1143,7 +1143,7 @@ void RasterizerOpenGL::SyncBlendState() {
blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a);
}
state.MarkDirtyBlendState(true);
state.MarkDirtyBlendState();
maxwell3d.dirty.blend_state = false;
}
@ -1209,7 +1209,7 @@ void RasterizerOpenGL::SyncPolygonOffset() {
state.polygon_offset.factor = regs.polygon_offset_factor;
state.polygon_offset.clamp = regs.polygon_offset_clamp;
state.MarkDirtyPolygonOffset(true);
state.MarkDirtyPolygonOffset();
maxwell3d.dirty.polygon_offset = false;
}

@ -238,20 +238,20 @@ public:
/// Viewport does not affects glClearBuffer so emulate viewport using scissor test
void EmulateViewportWithScissor();
void MarkDirtyBlendState(const bool is_dirty) {
dirty.blend_state = is_dirty;
void MarkDirtyBlendState() {
dirty.blend_state = true;
}
void MarkDirtyStencilState(const bool is_dirty) {
dirty.stencil_state = is_dirty;
void MarkDirtyStencilState() {
dirty.stencil_state = true;
}
void MarkDirtyPolygonOffset(const bool is_dirty) {
dirty.polygon_offset = is_dirty;
void MarkDirtyPolygonOffset() {
dirty.polygon_offset = true;
}
void MarkDirtyColorMask(const bool is_dirty) {
dirty.color_mask = is_dirty;
void MarkDirtyColorMask() {
dirty.color_mask = true;
}
void AllDirty() {

@ -108,6 +108,7 @@ void RendererOpenGL::SwapBuffers(
// Maintain the rasterizer's state as a priority
OpenGLState prev_state = OpenGLState::GetCurState();
state.AllDirty();
state.Apply();
if (framebuffer) {
@ -140,6 +141,7 @@ void RendererOpenGL::SwapBuffers(
system.GetPerfStats().BeginSystemFrame();
// Restore the rasterizer state
prev_state.AllDirty();
prev_state.Apply();
}
@ -206,6 +208,7 @@ void RendererOpenGL::InitOpenGLObjects() {
// Link shaders and get variable locations
shader.CreateFromSource(vertex_shader, nullptr, fragment_shader);
state.draw.shader_program = shader.handle;
state.AllDirty();
state.Apply();
uniform_modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix");
uniform_color_texture = glGetUniformLocation(shader.handle, "color_texture");
@ -338,12 +341,14 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
// Workaround brigthness problems in SMO by enabling sRGB in the final output
// if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987
state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed();
state.AllDirty();
state.Apply();
glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), vertices.data());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Restore default state
state.framebuffer_srgb.enabled = false;
state.texture_units[0].texture = 0;
state.AllDirty();
state.Apply();
// Clear sRGB state for the next frame
OpenGLState::ClearsRGBUsed();
@ -388,6 +393,7 @@ void RendererOpenGL::CaptureScreenshot() {
GLuint old_read_fb = state.draw.read_framebuffer;
GLuint old_draw_fb = state.draw.draw_framebuffer;
state.draw.read_framebuffer = state.draw.draw_framebuffer = screenshot_framebuffer.handle;
state.AllDirty();
state.Apply();
Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout};
@ -407,6 +413,7 @@ void RendererOpenGL::CaptureScreenshot() {
screenshot_framebuffer.Release();
state.draw.read_framebuffer = old_read_fb;
state.draw.draw_framebuffer = old_draw_fb;
state.AllDirty();
state.Apply();
glDeleteRenderbuffers(1, &renderbuffer);