LibGL: Fix triangle winding calculation

Since we operate in screen space where y points down we need to reverse
what is considered clock wise and what is considered counter clockwise.

The rasterizer always expects triangles with a consistent winding order
thus swap 2 vertices if necessary to reverse the winding before passing
the triangle on to the rasterization stage.
This commit is contained in:
Stephan Unverwerth 2021-08-16 19:25:16 +02:00 committed by Andreas Kling
parent 220ac5eb02
commit addbcd42d7
2 changed files with 6 additions and 2 deletions

View file

@ -60,7 +60,7 @@ private:
start_timer(20); start_timer(20);
GL::make_context_current(m_context); GL::make_context_current(m_context);
glFrontFace(GL_CW); glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View file

@ -246,7 +246,7 @@ void SoftwareGLContext::gl_end()
continue; continue;
if (m_cull_faces) { if (m_cull_faces) {
bool is_front = (m_front_face == GL_CCW ? area > 0 : area < 0); bool is_front = (m_front_face == GL_CCW ? area < 0 : area > 0);
if (is_front && (m_culled_sides == GL_FRONT || m_culled_sides == GL_FRONT_AND_BACK)) if (is_front && (m_culled_sides == GL_FRONT || m_culled_sides == GL_FRONT_AND_BACK))
continue; continue;
@ -255,6 +255,10 @@ void SoftwareGLContext::gl_end()
continue; continue;
} }
if (area > 0) {
swap(triangle.vertices[0], triangle.vertices[1]);
}
m_rasterizer.submit_triangle(triangle, m_texture_units); m_rasterizer.submit_triangle(triangle, m_texture_units);
} }