gl: Only toggle state settings that are relevant to the current RSX state

This commit is contained in:
kd-11 2022-07-17 15:55:07 +03:00 committed by kd-11
parent e95084f138
commit 1c5b685398

View File

@ -138,29 +138,11 @@ void GLGSRender::update_draw_state()
m_profiler.start();
gl_state.enable(GL_SCISSOR_TEST);
gl_state.enable(rsx::method_registers.dither_enabled(), GL_DITHER);
for (int index = 0; index < m_rtts.get_color_surface_count(); ++index)
if (m_rtts.m_bound_depth_stencil.first)
{
bool color_mask_b = rsx::method_registers.color_mask_b(index);
bool color_mask_g = rsx::method_registers.color_mask_g(index);
bool color_mask_r = rsx::method_registers.color_mask_r(index);
bool color_mask_a = rsx::method_registers.color_mask_a(index);
switch (rsx::method_registers.surface_color())
{
case rsx::surface_color_format::b8:
rsx::get_b8_colormask(color_mask_r, color_mask_g, color_mask_b, color_mask_a);
break;
case rsx::surface_color_format::g8b8:
rsx::get_g8b8_r8g8_colormask(color_mask_r, color_mask_g, color_mask_b, color_mask_a);
break;
default:
break;
}
gl_state.color_maski(index, color_mask_r, color_mask_g, color_mask_b, color_mask_a);
}
// Z-buffer is active.
gl_state.depth_mask(rsx::method_registers.depth_write_enabled());
gl_state.stencil_mask(rsx::method_registers.stencil_mask());
@ -181,8 +163,6 @@ void GLGSRender::update_draw_state()
gl_state.depth_range(rsx::method_registers.clip_min(), rsx::method_registers.clip_max());
}
gl_state.enable(rsx::method_registers.dither_enabled(), GL_DITHER);
if (gl_state.enable(rsx::method_registers.stencil_test_enabled(), GL_STENCIL_TEST))
{
glStencilFunc(gl::comparison_op(rsx::method_registers.stencil_func()),
@ -203,6 +183,32 @@ void GLGSRender::update_draw_state()
gl::stencil_op(rsx::method_registers.back_stencil_op_zfail()), gl::stencil_op(rsx::method_registers.back_stencil_op_zpass()));
}
}
}
if (m_rtts.get_color_surface_count())
{
// Color buffer is active
for (int index = 0; index < m_rtts.get_color_surface_count(); ++index)
{
bool color_mask_b = rsx::method_registers.color_mask_b(index);
bool color_mask_g = rsx::method_registers.color_mask_g(index);
bool color_mask_r = rsx::method_registers.color_mask_r(index);
bool color_mask_a = rsx::method_registers.color_mask_a(index);
switch (rsx::method_registers.surface_color())
{
case rsx::surface_color_format::b8:
rsx::get_b8_colormask(color_mask_r, color_mask_g, color_mask_b, color_mask_a);
break;
case rsx::surface_color_format::g8b8:
rsx::get_g8b8_r8g8_colormask(color_mask_r, color_mask_g, color_mask_b, color_mask_a);
break;
default:
break;
}
gl_state.color_maski(index, color_mask_r, color_mask_g, color_mask_b, color_mask_a);
}
bool mrt_blend_enabled[] =
{
@ -235,10 +241,17 @@ void GLGSRender::update_draw_state()
{
gl_state.logic_op(gl::logic_op(rsx::method_registers.logic_operation()));
}
}
switch (rsx::method_registers.current_draw_clause.primitive)
{
case rsx::primitive_type::lines:
case rsx::primitive_type::line_loop:
case rsx::primitive_type::line_strip:
gl_state.line_width(rsx::method_registers.line_width() * rsx::get_resolution_scale());
gl_state.enable(rsx::method_registers.line_smooth_enabled(), GL_LINE_SMOOTH);
break;
default:
gl_state.enable(rsx::method_registers.poly_offset_point_enabled(), GL_POLYGON_OFFSET_POINT);
gl_state.enable(rsx::method_registers.poly_offset_line_enabled(), GL_POLYGON_OFFSET_LINE);
gl_state.enable(rsx::method_registers.poly_offset_fill_enabled(), GL_POLYGON_OFFSET_FILL);
@ -253,6 +266,8 @@ void GLGSRender::update_draw_state()
}
gl_state.front_face(gl::front_face(rsx::method_registers.front_face_mode()));
break;
}
// Sample control
// TODO: MinSampleShading
@ -378,7 +393,7 @@ void GLGSRender::bind_texture_env()
if (current_fragment_program.texture_state.redirected_textures & (1 << i))
{
auto root_texture = static_cast<gl::viewable_image*>(view->image());
auto stencil_view = root_texture->get_view(0xAAE4, rsx::default_remap_vector, gl::image_aspect::stencil);
auto stencil_view = root_texture->get_view(gl::GL_REMAP_IDENTITY, rsx::default_remap_vector, gl::image_aspect::stencil);
stencil_view->bind(cmd, GL_STENCIL_MIRRORS_START + i);
}
}