5#include <private/qsgmaterialshader_p.h>
7#include <QtGui/private/qguiapplication_p.h>
8#include <qpa/qplatformintegration.h>
9#include <private/qfontengine_p.h>
11#include <QtQuick/qquickwindow.h>
12#include <QtQuick/private/qsgtexture_p.h>
13#include <QtQuick/private/qsgdefaultrendercontext_p.h>
15#include <private/qrawfont_p.h>
16#include <QtCore/qmath.h>
22 float o =
c.w() * globalOpacity;
41 : m_glyphFormat(glyphFormat)
44 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/textmask.vert.qsb"));
46 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/textmask.frag.qsb"));
64 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->
type() == oldMaterial->
type());
78 if (
state.isMatrixDirty()) {
89 if (updated || !oldMat || oldRtex != newRtex) {
97 float dpr =
state.devicePixelRatio();
128 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/8bittextmask_a.frag.qsb"));
131 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/8bittextmask.frag.qsb"));
148 if (oldMat ==
nullptr || mat->
color() != oldMat->
color() ||
state.isOpacityDirty()) {
165 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/24bittextmask.frag.qsb"));
184 if (oldMat ==
nullptr || mat->
color() != oldMat->
color() ||
state.isOpacityDirty()) {
202 ps->
srcColor = GraphicsPipelineState::ConstantColor;
203 ps->
dstColor = GraphicsPipelineState::OneMinusSrcColor;
220 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/32bitcolortext.frag.qsb"));
237 if (oldMat ==
nullptr || mat->
color() != oldMat->
color() ||
state.isOpacityDirty()) {
254 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/styledtext.vert.qsb"));
257 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/styledtext_a.frag.qsb"));
260 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/styledtext.frag.qsb"));
300 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/outlinedtext.vert.qsb"));
303 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/outlinedtext_a.frag.qsb"));
306 QStringLiteral(
":/qt-project.org/scenegraph/shaders_ng/outlinedtext.frag.qsb"));
325 if (m_retainedFontEngine !=
nullptr)
332 if (m_color ==
color)
352 updateCache(glyphFormat);
367 ? fontEngine->glyphFormat
371 qreal devicePixelRatio;
382 if (!fontEngine->supportsTransformation(glyphCacheTransform))
386 m_glyphCache = fontEngine->glyphCache(cacheKey, glyphFormat, glyphCacheTransform,
color);
387 if (!m_glyphCache ||
int(m_glyphCache->
glyphFormat()) != glyphFormat) {
389 fontEngine->setGlyphCache(cacheKey, m_glyphCache.
data());
390 if (m_retainedFontEngine !=
nullptr)
395 m_retainedFontEngine = fontEngine;
412 const int glyphPositionsSize = glyphPositions.
size();
413 fixedPointPositions.
reserve(glyphPositionsSize);
414 for (
int i=0;
i < glyphPositionsSize; ++
i)
423 fixedPointPositions.
data(),
424 QPainter::RenderHints(),
426 cache->fillInPendingGlyphs();
430 qreal glyphCacheScaleX =
cache->transform().m11();
431 qreal glyphCacheScaleY =
cache->transform().m22();
432 qreal glyphCacheInverseScaleX = 1.0 / glyphCacheScaleX;
433 qreal glyphCacheInverseScaleY = 1.0 / glyphCacheScaleY;
434 qreal scaledMargin = margin * glyphCacheInverseScaleX;
443 for (
int i=0;
i<glyphIndexes.
size(); ++
i) {
448 if (supportsSubPixelPositions)
461 qreal x = (
qFloor(glyphPosition.
x() * glyphCacheScaleX) * glyphCacheInverseScaleX) +
462 (
c.baseLineX * glyphCacheInverseScaleX) - scaledMargin;
463 qreal y = (
qRound(glyphPosition.
y() * glyphCacheScaleY) * glyphCacheInverseScaleY) -
464 (
c.baseLineY * glyphCacheInverseScaleY) - scaledMargin;
466 qreal w =
c.w * glyphCacheInverseScaleX;
467 qreal h =
c.h * glyphCacheInverseScaleY;
471 float cx1 =
x - margins.
left();
472 float cx2 =
x +
w + margins.
right();
473 float cy1 =
y - margins.
top();
474 float cy2 =
y +
h + margins.
bottom();
476 float tx1 =
c.x - margins.
left();
477 float tx2 =
c.x +
c.w + margins.
right();
478 float ty1 =
c.y - margins.
top();
479 float ty2 =
c.y +
c.h + margins.
bottom();
482 *baseLine = glyphPosition;
484 vp[4 *
i + 0] =
QVector4D(cx1, cy1, tx1, ty1);
485 vp[4 *
i + 1] =
QVector4D(cx2, cy1, tx2, ty1);
486 vp[4 *
i + 2] =
QVector4D(cx1, cy2, tx1, ty2);
487 vp[4 *
i + 3] =
QVector4D(cx2, cy2, tx2, ty2);
490 ip[6 *
i + 0] =
o + 0;
491 ip[6 *
i + 1] =
o + 2;
492 ip[6 *
i + 2] =
o + 3;
493 ip[6 *
i + 3] =
o + 3;
494 ip[6 *
i + 4] =
o + 1;
495 ip[6 *
i + 5] =
o + 0;
528 switch (glyphFormat) {
542 return a.x() >
b.x() ? 1 : -1;
544 return a.y() >
b.y() ? 1 : -1;
546 return a.z() >
b.z() ? 1 : -1;
548 return a.w() >
b.w() ? 1 : -1;
556 if (m_glyphCache !=
other->m_glyphCache)
557 return m_glyphCache.
data() <
other->m_glyphCache.data() ? -1 : 1;
565 if (glyphCacheSize != m_size) {
572 m_size = glyphCacheSize;
601 if (m_styleShift !=
other->m_styleShift)
602 return m_styleShift.
y() -
other->m_styleShift.y();
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
T * data() const noexcept
Returns a pointer to the shared data object.
QFontEngine::GlyphFormat glyphFormat() const
virtual bool supportsHorizontalSubPixelPositions() const
virtual int glyphMargin(GlyphFormat format)
QFixed subPixelPositionForX(QFixed x) const
qsizetype size() const noexcept
const_pointer constData() const noexcept
const_reference at(qsizetype i) const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
const float * constData() const
Returns a constant pointer to the raw data of this matrix.
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
bool isNull() const noexcept
Returns true if both the x and y coordinates are set to 0.0 (ignoring the sign); otherwise returns fa...
static QRawFontPrivate * get(const QRawFont &font)
The QRawFont class provides access to a single physical instance of a font.
qreal ascent() const
Returns the ascent of this QRawFont in pixel units.
bool isValid() const
Returns true if the QRawFont is valid and false otherwise.
\inmodule QtCore\reentrant
bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to enable the material to provide a custom set of graphics...
QSG24BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSG32BitColorTextRhiShader(QFontEngine::GlyphFormat glyphFormat)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSG8BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
qreal currentDevicePixelRatio() const
QRhi * rhi() const override
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D.
int indexType() const
Returns the primitive type used for indices in this geometry object.
void allocate(int vertexCount, int indexCount=0)
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount ...
int sizeOfVertex() const
Returns the size in bytes of one vertex.
quint16 * indexDataAsUShort()
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
void setShaderFileName(Stage stage, const QString &filename)
Sets the filename for the shader for the specified stage.
void setFlag(Flags flags, bool on=true)
Sets the flags on this material shader if on is true; otherwise clears the specified flags.
@ UpdatesGraphicsPipelineState
The QSGMaterial class encapsulates rendering state for a shader program.
virtual QSGMaterialType * type() const =0
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGOutlinedTextRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
void setTextureSize(const QSize &size)
void setTexture(QRhiTexture *texture)
void setOwnsTexture(bool owns)
void registerFontengineForCleanup(QFontEngine *engine)
void unregisterFontengineForCleanup(QFontEngine *engine)
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto)
QRhiTexture * texture() const
bool eightBitFormatIsAlphaSwizzled() const
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
const QVector2D & styleShift() const
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font)
const QVector4D & styleColor() const
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGStyledTextRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat=QFontEngine::Format_None)
const QVector4D & color() const
virtual ~QSGTextMaskMaterial()
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
void setColor(const QColor &c)
QTextureGlyphCache * glyphCache() const
QSGRhiTextureGlyphCache * rhiGlyphCache() const
void populate(const QPointF &position, const QVector< quint32 > &glyphIndexes, const QVector< QPointF > &glyphPositions, QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine, const QMargins &margins=QMargins(0, 0, 0, 0))
QSGTexture * texture() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QFontEngine::GlyphFormat m_glyphFormat
QSGTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void setFiltering(Filtering filter)
Sets the sampling mode to filter.
virtual QRhiTexture * rhiTexture() const
The QVector2D class represents a vector or vertex in 2D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
The QVector4D class represents a vector or vertex in 4D space.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr float w() const noexcept
Returns the w coordinate of this point.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float z() const noexcept
Returns the z coordinate of this point.
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
T qobject_cast(QObject *object)
\variable QObject::staticMetaObject
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLfloat GLfloat GLfloat GLfloat h
static const QRectF boundingRect(const QPointF *points, int pointCount)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QT_BEGIN_NAMESPACE QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
static int qsg_colorDiff(const QVector4D &a, const QVector4D &b)
#define QStringLiteral(str)
static constexpr QFixedPoint fromPointF(const QPointF &p)
static constexpr QFixed fromReal(qreal r)
constexpr qreal toReal() const
Describes state changes that the material wants to apply to the currently active graphics pipeline st...
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.