From f28047de73957d2c381fcfda80ef6935542fc1e7 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Thu, 3 Feb 2022 16:45:08 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibSoftGPU/Device.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 59a8855b0c6..2f6835492bc 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -18,6 +18,7 @@ #include #include #include +#include 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) { + // 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 { - static_cast(m_raster_position.window_coordinates.x()), - static_cast(m_raster_position.window_coordinates.y()), + static_cast(roundf(m_raster_position.window_coordinates.x())), + static_cast(roundf(m_raster_position.window_coordinates.y())), size.width(), size.height(), };