return v;
}
+static float defaultThresholdFunc(float glyphScale)
+{
+ static float base = qgetenv("QT_DF_BASE").isEmpty() ? 0.5f : qgetenv("QT_DF_BASE").toFloat();
+ static float baseDev = qgetenv("QT_DF_BASEDEVIATION").isEmpty() ? 0.065f : qgetenv("QT_DF_BASEDEVIATION").toFloat();
+ static float devScaleMin = qgetenv("QT_DF_SCALEFORMAXDEV").isEmpty() ? 0.15f : qgetenv("QT_DF_SCALEFORMAXDEV").toFloat();
+ static float devScaleMax = qgetenv("QT_DF_SCALEFORNODEV").isEmpty() ? 0.3f : qgetenv("QT_DF_SCALEFORNODEV").toFloat();
+ return base - ((qBound(devScaleMin, glyphScale, devScaleMax) - devScaleMin) / (devScaleMax - devScaleMin) * -baseDev + baseDev);
+}
+
+static float defaultAntialiasingSpreadFunc(float glyphScale)
+{
+ static float range = qgetenv("QT_DF_RANGE").isEmpty() ? 0.06f : qgetenv("QT_DF_RANGE").toFloat();
+ return range / glyphScale;
+}
+
namespace
{
enum FillHDir
, m_maxTextureSize(0)
, ctx(c)
, m_blitProgram(0)
+ , m_threshold_func(defaultThresholdFunc)
+ , m_antialiasingSpread_func(defaultAntialiasingSpreadFunc)
{
Q_ASSERT(font.isValid());
m_font = font;
class QGLShaderProgram;
+typedef float (*ThresholdFunc)(float glyphScale);
+typedef float (*AntialiasingSpreadFunc)(float glyphScale);
+
class Q_DECLARATIVE_EXPORT QSGDistanceFieldGlyphCache : public QObject
{
Q_OBJECT
static bool distanceFieldEnabled();
+ ThresholdFunc thresholdFunc() const { return m_threshold_func; }
+ void setThresholdFunc(ThresholdFunc func) { m_threshold_func = func; }
+
+ AntialiasingSpreadFunc antialiasingSpreadFunc() const { return m_antialiasingSpread_func; }
+ void setAntialiasingSpreadFunc(AntialiasingSpreadFunc func) { m_antialiasingSpread_func = func; }
+
private Q_SLOTS:
void onContextDestroyed(const QGLContext *context);
GLfloat m_vertexCoordinateArray[8];
GLfloat m_textureCoordinateArray[8];
+ ThresholdFunc m_threshold_func;
+ AntialiasingSpreadFunc m_antialiasingSpread_func;
};
QT_END_NAMESPACE
virtual const char *vertexShader() const;
virtual const char *fragmentShader() const;
- virtual void updateAlphaRange();
+ void updateAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc);
- qreal m_fontScale;
- qreal m_matrixScale;
+ float m_fontScale;
+ float m_matrixScale;
int m_matrix_id;
int m_textureScale_id;
{
}
-void QSGDistanceFieldTextMaterialShader::updateAlphaRange()
+void QSGDistanceFieldTextMaterialShader::updateAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc)
{
- qreal combinedScale = m_fontScale * m_matrixScale;
- qreal alphaMin = qMax(0.0, 0.5 - 0.07 / combinedScale);
- qreal alphaMax = qMin(0.5 + 0.07 / combinedScale, 1.0);
+ float combinedScale = m_fontScale * m_matrixScale;
+ float base = thresholdFunc(combinedScale);
+ float range = spreadFunc(combinedScale);
+
+ float alphaMin = qMax(0.0f, base - range);
+ float alphaMax = qMin(base + range, 1.0f);
program()->setUniformValue(m_alphaMin_id, GLfloat(alphaMin));
program()->setUniformValue(m_alphaMax_id, GLfloat(alphaMax));
}
updateRange = true;
}
if (updateRange)
- updateAlphaRange();
+ updateAlphaRange(material->glyphCache()->thresholdFunc(), material->glyphCache()->antialiasingSpreadFunc());
Q_ASSERT(material->glyphCache());
virtual const char *vertexShader() const;
virtual const char *fragmentShader() const;
- void updateAlphaRange();
-
private:
int m_fontScale_id;
int m_vecDelta_id;
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
-void QSGSubPixelDistanceFieldTextMaterialShader::updateAlphaRange()
-{
- qreal combinedScale = m_fontScale * m_matrixScale;
- qreal alphaMin = qMax(0.0, 0.5 - 0.05 / combinedScale);
- qreal alphaMax = qMin(0.5 + 0.05 / combinedScale, 1.0);
- program()->setUniformValue(m_alphaMin_id, GLfloat(alphaMin));
- program()->setUniformValue(m_alphaMax_id, GLfloat(alphaMax));
-}
-
void QSGSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());