diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2021-08-16 19:25:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-18 20:30:58 +0200 |
commit | addbcd42d7e5bb34d48bcbe9ee0830bb1fd76442 (patch) | |
tree | 6eac3b8ab74f11a254502e59e50a1f5a518469dd /Userland/Libraries/LibGL | |
parent | 220ac5eb026c8e1fd01af0544c0e367c886eab80 (diff) | |
download | serenity-addbcd42d7e5bb34d48bcbe9ee0830bb1fd76442.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 70355668d2..45511b382a 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -246,7 +246,7 @@ void SoftwareGLContext::gl_end() continue; 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)) continue; @@ -255,6 +255,10 @@ void SoftwareGLContext::gl_end() continue; } + if (area > 0) { + swap(triangle.vertices[0], triangle.vertices[1]); + } + m_rasterizer.submit_triangle(triangle, m_texture_units); } |