From c9b32afb1c5d7b6c7451100d7727fc94e621d147 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 12 Jan 2023 14:04:31 +0100 Subject: [PATCH] Add a property to RenderGeometry that determines what vertex snapping mode to use Currently, only two modes are provided, rounding or not rounding, which allows explicitly disabling snapping. However, should we have a reason to add more modes it is now fairly simple to change. --- src/libkwineffects/kwineffects.cpp | 9 ++++++- src/libkwineffects/kwineffects.h | 42 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index 3cf56c855a..d7cad1dae6 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -1119,7 +1119,14 @@ void RenderGeometry::copy(std::span destination) void RenderGeometry::appendWindowVertex(const WindowVertex &windowVertex, qreal deviceScale) { GLVertex2D glVertex; - glVertex.position = roundVector(QVector2D(windowVertex.x(), windowVertex.y()) * deviceScale); + switch (m_vertexSnappingMode) { + case VertexSnappingMode::None: + glVertex.position = QVector2D(windowVertex.x(), windowVertex.y() * deviceScale); + break; + case VertexSnappingMode::Round: + glVertex.position = roundVector(QVector2D(windowVertex.x(), windowVertex.y()) * deviceScale); + break; + } glVertex.texcoord = QVector2D(windowVertex.u(), windowVertex.v()); append(glVertex); } diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index 746ce3a9af..d7bc2a3557 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -2962,6 +2962,45 @@ public: class KWINEFFECTS_EXPORT RenderGeometry : public QVector { public: + /** + * In what way should vertices snap to integer device coordinates? + * + * Vertices are converted to device coordinates before being sent to the + * rendering system. Depending on scaling factors, this may lead to device + * coordinates with fractional parts. For some cases, this may not be ideal + * as fractional coordinates need to be interpolated and can lead to + * "blurry" rendering. To avoid that, we can snap the vertices to integer + * device coordinates when they are added. + */ + enum class VertexSnappingMode { + None, //< No rounding, device coordinates containing fractional parts + // are passed directly to the rendering system. + Round, //< Perform a simple rounding, device coordinates will not have + // any fractional parts. + }; + + /** + * The vertex snapping mode to use for this geometry. + * + * By default, this is VertexSnappingMode::Round. + */ + inline VertexSnappingMode vertexSnappingMode() const + { + return m_vertexSnappingMode; + } + /** + * Set the vertex snapping mode to use for this geometry. + * + * Note that this doesn't change vertices retroactively, so you should set + * this before adding any vertices, or clear and rebuild the geometry after + * setting it. + * + * @param mode The new rounding mode. + */ + void setVertexSnappingMode(VertexSnappingMode mode) + { + m_vertexSnappingMode = mode; + } /** * Copy geometry data into another buffer. * @@ -3012,6 +3051,9 @@ public: * device coordinates. */ void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale); + +private: + VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round; }; class KWINEFFECTS_EXPORT WindowPrePaintData