浏览代码

LibSoftGPU: Round rasterization position to nearest integer

This fixes the issue where e.g. `299.97` would be cast to an integer
value of `299`, whereas the pixel's center would lie at `299.5` and
would then erroneously be excluded.
Jelle Raaijmakers 3 年之前
父节点
当前提交
f28047de73
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      Userland/Libraries/LibSoftGPU/Device.cpp

+ 6 - 2
Userland/Libraries/LibSoftGPU/Device.cpp

@@ -18,6 +18,7 @@
 #include <LibSoftGPU/Device.h>
 #include <LibSoftGPU/Device.h>
 #include <LibSoftGPU/PixelQuad.h>
 #include <LibSoftGPU/PixelQuad.h>
 #include <LibSoftGPU/SIMD.h>
 #include <LibSoftGPU/SIMD.h>
+#include <math.h>
 
 
 namespace SoftGPU {
 namespace SoftGPU {
 
 
@@ -1335,9 +1336,12 @@ void Device::set_raster_position(FloatVector4 const& position, FloatMatrix4x4 co
 
 
 Gfx::IntRect Device::get_rasterization_rect_of_size(Gfx::IntSize size)
 Gfx::IntRect Device::get_rasterization_rect_of_size(Gfx::IntSize size)
 {
 {
+    // Round the X and Y floating point coordinates to the nearest integer; OpenGL 1.5 spec:
+    // "Any fragments whose centers lie inside of this rectangle (or on its bottom or left
+    // boundaries) are produced in correspondence with this particular group of elements."
     return {
     return {
-        static_cast<int>(m_raster_position.window_coordinates.x()),
-        static_cast<int>(m_raster_position.window_coordinates.y()),
+        static_cast<int>(roundf(m_raster_position.window_coordinates.x())),
+        static_cast<int>(roundf(m_raster_position.window_coordinates.y())),
         size.width(),
         size.width(),
         size.height(),
         size.height(),
     };
     };