gl_state: Remove scissor test tracking

This commit is contained in:
ReinUsesLisp 2019-12-26 01:28:17 -03:00
parent 0914c70b7f
commit 7c16b3551b
6 changed files with 12 additions and 69 deletions

View file

@ -467,12 +467,10 @@ void RasterizerOpenGL::Clear() {
SyncViewport(clear_state); SyncViewport(clear_state);
SyncRasterizeEnable(clear_state); SyncRasterizeEnable(clear_state);
if (regs.clear_flags.scissor) { if (regs.clear_flags.scissor) {
SyncScissorTest(clear_state); SyncScissorTest();
} }
if (regs.clear_flags.viewport) { UNIMPLEMENTED_IF(regs.clear_flags.viewport);
clear_state.EmulateViewportWithScissor();
}
clear_state.Apply(); clear_state.Apply();
@ -508,7 +506,7 @@ void RasterizerOpenGL::Draw(bool is_indexed, bool is_instanced) {
SyncLogicOpState(); SyncLogicOpState();
SyncCullMode(); SyncCullMode();
SyncPrimitiveRestart(); SyncPrimitiveRestart();
SyncScissorTest(state); SyncScissorTest();
SyncTransformFeedback(); SyncTransformFeedback();
SyncPointState(); SyncPointState();
SyncPolygonOffset(); SyncPolygonOffset();
@ -1140,25 +1138,13 @@ void RasterizerOpenGL::SyncLogicOpState() {
} }
} }
void RasterizerOpenGL::SyncScissorTest(OpenGLState& current_state) { void RasterizerOpenGL::SyncScissorTest() {
const auto& regs = system.GPU().Maxwell3D().regs; const auto& regs = system.GPU().Maxwell3D().regs;
const bool geometry_shaders_enabled = for (std::size_t index = 0; index < Maxwell::NumViewports; ++index) {
regs.IsShaderConfigEnabled(static_cast<size_t>(Maxwell::ShaderProgram::Geometry)); const auto& src = regs.scissor_test[index];
const std::size_t viewport_count = oglEnablei(GL_SCISSOR_TEST, src.enable, static_cast<GLuint>(index));
geometry_shaders_enabled ? Tegra::Engines::Maxwell3D::Regs::NumViewports : 1; glScissorIndexed(static_cast<GLuint>(index), src.min_x, src.min_y, src.max_x - src.min_x,
for (std::size_t i = 0; i < viewport_count; i++) { src.max_y - src.min_y);
const auto& src = regs.scissor_test[i];
auto& dst = current_state.viewports[i].scissor;
dst.enabled = (src.enable != 0);
if (dst.enabled == 0) {
return;
}
const u32 width = src.max_x - src.min_x;
const u32 height = src.max_y - src.min_y;
dst.x = src.min_x;
dst.y = src.min_y;
dst.width = width;
dst.height = height;
} }
} }

View file

@ -167,7 +167,7 @@ private:
void SyncMultiSampleState(); void SyncMultiSampleState();
/// Syncs the scissor test state to match the guest state /// Syncs the scissor test state to match the guest state
void SyncScissorTest(OpenGLState& current_state); void SyncScissorTest();
/// Syncs the transform feedback state to match the guest state /// Syncs the transform feedback state to match the guest state
void SyncTransformFeedback(); void SyncTransformFeedback();

View file

@ -171,19 +171,6 @@ void OpenGLState::ApplyViewport() {
current.depth_range_far = updated.depth_range_far; current.depth_range_far = updated.depth_range_far;
glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far); glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far);
} }
Enable(GL_SCISSOR_TEST, i, current.scissor.enabled, updated.scissor.enabled);
if (current.scissor.x != updated.scissor.x || current.scissor.y != updated.scissor.y ||
current.scissor.width != updated.scissor.width ||
current.scissor.height != updated.scissor.height) {
current.scissor.x = updated.scissor.x;
current.scissor.y = updated.scissor.y;
current.scissor.width = updated.scissor.width;
current.scissor.height = updated.scissor.height;
glScissorIndexed(i, updated.scissor.x, updated.scissor.y, updated.scissor.width,
updated.scissor.height);
}
} }
} }
@ -306,28 +293,6 @@ void OpenGLState::Apply() {
ApplyRenderBuffer(); ApplyRenderBuffer();
} }
void OpenGLState::EmulateViewportWithScissor() {
auto& current = viewports[0];
if (current.scissor.enabled) {
const GLint left = std::max(current.x, current.scissor.x);
const GLint right =
std::max(current.x + current.width, current.scissor.x + current.scissor.width);
const GLint bottom = std::max(current.y, current.scissor.y);
const GLint top =
std::max(current.y + current.height, current.scissor.y + current.scissor.height);
current.scissor.x = std::max(left, 0);
current.scissor.y = std::max(bottom, 0);
current.scissor.width = std::max(right - left, 0);
current.scissor.height = std::max(top - bottom, 0);
} else {
current.scissor.enabled = true;
current.scissor.x = current.x;
current.scissor.y = current.y;
current.scissor.width = current.width;
current.scissor.height = current.height;
}
}
OpenGLState& OpenGLState::UnbindTexture(GLuint handle) { OpenGLState& OpenGLState::UnbindTexture(GLuint handle) {
for (auto& texture : textures) { for (auto& texture : textures) {
if (texture == handle) { if (texture == handle) {

View file

@ -63,13 +63,6 @@ public:
GLint height = 0; GLint height = 0;
GLfloat depth_range_near = 0.0f; // GL_DEPTH_RANGE GLfloat depth_range_near = 0.0f; // GL_DEPTH_RANGE
GLfloat depth_range_far = 1.0f; // GL_DEPTH_RANGE GLfloat depth_range_far = 1.0f; // GL_DEPTH_RANGE
struct {
bool enabled = false; // GL_SCISSOR_TEST
GLint x = 0;
GLint y = 0;
GLsizei width = 0;
GLsizei height = 0;
} scissor;
}; };
std::array<Viewport, Tegra::Engines::Maxwell3D::Regs::NumViewports> viewports; std::array<Viewport, Tegra::Engines::Maxwell3D::Regs::NumViewports> viewports;
@ -117,9 +110,6 @@ public:
OpenGLState& ResetFramebuffer(GLuint handle); OpenGLState& ResetFramebuffer(GLuint handle);
OpenGLState& ResetRenderbuffer(GLuint handle); OpenGLState& ResetRenderbuffer(GLuint handle);
/// Viewport does not affects glClearBuffer so emulate viewport using scissor test
void EmulateViewportWithScissor();
private: private:
static OpenGLState cur_state; static OpenGLState cur_state;
}; };

View file

@ -536,6 +536,7 @@ void TextureCacheOpenGL::ImageBlit(View& src_view, View& dst_view,
} else { } else {
glDisable(GL_FRAMEBUFFER_SRGB); glDisable(GL_FRAMEBUFFER_SRGB);
} }
glDisablei(GL_SCISSOR_TEST, 0);
u32 buffers{}; u32 buffers{};

View file

@ -568,6 +568,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_POLYGON_OFFSET_FILL);
glDisablei(GL_SCISSOR_TEST, 0);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glFrontFace(GL_CW); glFrontFace(GL_CW);
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);