GPU: Use scissor test for drawing area

This commit is contained in:
Connor McLaughlin 2019-09-14 21:54:58 +10:00
parent 3d6b8e485e
commit e40393fec4
2 changed files with 21 additions and 10 deletions

View File

@ -31,12 +31,6 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices)
hw_vert.x = vp.x();
hw_vert.y = vp.y();
// excluding lower-right coordinates
if ((i & UINT32_C(1)) != 0)
hw_vert.x--;
if ((i & UINT32_C(2)) != 0)
hw_vert.y--;
if (textured)
hw_vert.texcoord = Truncate16(m_GP0_command[buffer_pos++]);
else
@ -113,9 +107,9 @@ void GPU_HW::CalcViewport(int* x, int* y, int* width, int* height)
void GPU_HW::CalcScissorRect(int* left, int* top, int* right, int* bottom)
{
*left = m_drawing_area.top_left_x;
*right = m_drawing_area.bottom_right_x;
*right = m_drawing_area.bottom_right_x + 1;
*top = m_drawing_area.top_left_y;
*bottom = m_drawing_area.bottom_right_y;
*bottom = m_drawing_area.bottom_right_y + 1;
}
static void DefineMacro(std::stringstream& ss, const char* name, bool enabled)

View File

@ -175,7 +175,19 @@ void GPU_HW_OpenGL::SetViewport()
glViewport(x, y, width, height);
}
void GPU_HW_OpenGL::SetScissor() {}
void GPU_HW_OpenGL::SetScissor()
{
int left, top, right, bottom;
CalcScissorRect(&left, &top, &right, &bottom);
const int width = right - left;
const int height = bottom - top;
const int x = left;
const int y = VRAM_HEIGHT - bottom;
Log_DebugPrintf("SetScissor: (%d-%d, %d-%d)", x, x + width, y, y + height);
glScissor(x, y, width, height);
}
inline u32 ConvertRGBA5551ToRGBA8888(u16 color)
{
@ -252,7 +264,6 @@ void GPU_HW_OpenGL::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color)
const auto [r, g, b, a] = RGBA8ToFloat(color);
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
}
void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data)
@ -293,6 +304,7 @@ void GPU_HW_OpenGL::UpdateTexturePageTexture()
m_framebuffer_texture->Bind();
glDisable(GL_BLEND);
glDisable(GL_SCISSOR_TEST);
glViewport(0, 0, TEXTURE_PAGE_WIDTH, TEXTURE_PAGE_HEIGHT);
glBindVertexArray(m_attributeless_vao_id);
@ -321,8 +333,13 @@ void GPU_HW_OpenGL::FlushRender()
if (m_batch_vertices.empty())
return;
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
glDepthMask(GL_FALSE);
SetProgram(m_batch_command.texture_enable, m_batch_command.texture_blending_raw);
SetViewport();
SetScissor();
if (m_batch_command.texture_enable)
m_texture_page_texture->Bind();