diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-01-11 01:37:12 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-11 23:47:42 +0100 |
commit | 17ec4333265d376e526c53c180492dfd67bab540 (patch) | |
tree | 8a26414797303197920c7f00820661fc36947d14 /Userland/Libraries/LibSoftGPU | |
parent | 69eb3b08386b8cc15321466a67462e04edfb2de8 (diff) | |
download | serenity-17ec4333265d376e526c53c180492dfd67bab540.zip |
LibSoftGPU: Only render complete primitives
Previously, we were expecting triangles and quads to consist of
complete sets of vertices. However, a more common behavior is to ignore
all vertices that do not make up a full primitive. For example, OpenGL
specifies for `GL_QUADS`:
"The total number of vertices between Begin and End is 4n + k, where
0 ≤ k ≤ 3; if k is not zero, the final k vertices are ignored."
This changes the behavior of `Device::draw_primitives()` to both return
early if no full set of vertices was provided, and to ignore any
additional vertices that are not part of a full set.
Diffstat (limited to 'Userland/Libraries/LibSoftGPU')
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index ef64a5526f..23d15ce1dd 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -568,7 +568,9 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& // Let's construct some triangles if (primitive_type == PrimitiveType::Triangles) { Triangle triangle; - for (size_t i = 0; i < vertices.size(); i += 3) { + if (vertices.size() < 3) + return; + for (size_t i = 0; i < vertices.size() - 2; i += 3) { triangle.vertices[0] = vertices.at(i); triangle.vertices[1] = vertices.at(i + 1); triangle.vertices[2] = vertices.at(i + 2); @@ -578,8 +580,9 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& } else if (primitive_type == PrimitiveType::Quads) { // We need to construct two triangles to form the quad Triangle triangle; - VERIFY(vertices.size() % 4 == 0); - for (size_t i = 0; i < vertices.size(); i += 4) { + if (vertices.size() < 4) + return; + for (size_t i = 0; i < vertices.size() - 3; i += 4) { // Triangle 1 triangle.vertices[0] = vertices.at(i); triangle.vertices[1] = vertices.at(i + 1); |