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.
This commit is contained in:
parent
e473fb721c
commit
c9b32afb1c
2 changed files with 50 additions and 1 deletions
|
@ -1119,7 +1119,14 @@ void RenderGeometry::copy(std::span<GLVertex2D> destination)
|
||||||
void RenderGeometry::appendWindowVertex(const WindowVertex &windowVertex, qreal deviceScale)
|
void RenderGeometry::appendWindowVertex(const WindowVertex &windowVertex, qreal deviceScale)
|
||||||
{
|
{
|
||||||
GLVertex2D glVertex;
|
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());
|
glVertex.texcoord = QVector2D(windowVertex.u(), windowVertex.v());
|
||||||
append(glVertex);
|
append(glVertex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2962,6 +2962,45 @@ public:
|
||||||
class KWINEFFECTS_EXPORT RenderGeometry : public QVector<GLVertex2D>
|
class KWINEFFECTS_EXPORT RenderGeometry : public QVector<GLVertex2D>
|
||||||
{
|
{
|
||||||
public:
|
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.
|
* Copy geometry data into another buffer.
|
||||||
*
|
*
|
||||||
|
@ -3012,6 +3051,9 @@ public:
|
||||||
* device coordinates.
|
* device coordinates.
|
||||||
*/
|
*/
|
||||||
void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale);
|
void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale);
|
||||||
|
|
||||||
|
private:
|
||||||
|
VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KWINEFFECTS_EXPORT WindowPrePaintData
|
class KWINEFFECTS_EXPORT WindowPrePaintData
|
||||||
|
|
Loading…
Reference in a new issue