Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsgdefaultinternalimagenode.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <private/qsgdefaultrendercontext_p.h>
6#include <private/qsgmaterialshader_p.h>
7#include <private/qsgtexturematerial_p.h>
8#include <qopenglfunctions.h>
9#include <QtCore/qmath.h>
10#include <rhi/qrhi.h>
11
13
15{
16public:
17 SmoothTextureMaterialRhiShader(int viewCount);
18
19 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
20};
21
22
28
33
39
45
48{
49 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.vert.qsb"), viewCount);
50 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.frag.qsb"), viewCount);
51}
52
54{
55 bool changed = false;
56 QByteArray *buf = state.uniformData();
57 const int shaderMatrixCount = newMaterial->viewCount();
58
59 if (!oldMaterial) {
60 // The viewport is constant, so set the pixel size uniform only once (per batches with the same material).
61 const QRect r = state.viewportRect();
62 const QVector2D v(2.0f / r.width(), 2.0f / r.height());
63 // mat4 matrix, float opacity, vec2 pixelSize, and the vec2 must be 2*4 aligned
64 memcpy(buf->data() + 64 * shaderMatrixCount + 8, &v, 8);
65 changed = true;
66 }
67
68 changed |= QSGTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
69
70 return changed;
71}
72
73
80
82{
83 if (m_material.filtering() == filtering)
84 return;
85
86 m_material.setFiltering(filtering);
87 m_materialO.setFiltering(filtering);
88 m_smoothMaterial.setFiltering(filtering);
90}
91
93{
94 if (m_material.mipmapFiltering() == filtering)
95 return;
96
97 m_material.setMipmapFiltering(filtering);
98 m_materialO.setMipmapFiltering(filtering);
99 m_smoothMaterial.setMipmapFiltering(filtering);
101}
102
104{
105 if (m_material.verticalWrapMode() == wrapMode)
106 return;
107
108 m_material.setVerticalWrapMode(wrapMode);
109 m_materialO.setVerticalWrapMode(wrapMode);
110 m_smoothMaterial.setVerticalWrapMode(wrapMode);
112}
113
115{
116 if (m_material.horizontalWrapMode() == wrapMode)
117 return;
118
119 m_material.setHorizontalWrapMode(wrapMode);
120 m_materialO.setHorizontalWrapMode(wrapMode);
121 m_smoothMaterial.setHorizontalWrapMode(wrapMode);
123}
124
126{
127 if (m_antialiasing) {
128 setMaterial(&m_smoothMaterial);
129 setOpaqueMaterial(nullptr);
130 } else {
131 setMaterial(&m_materialO);
132 setOpaqueMaterial(&m_material);
133 }
134}
135
137{
138 m_material.setTexture(texture);
139 m_materialO.setTexture(texture);
140 m_smoothMaterial.setTexture(texture);
141}
142
144{
145 return m_material.texture();
146}
147
149{
150 const bool alpha = m_material.flags() & QSGMaterial::Blending;
151 if (materialTexture() && alpha != materialTexture()->hasAlphaChannel()) {
152 m_material.setFlag(QSGMaterial::Blending, !alpha);
153 return true;
154 }
155 return false;
156}
157
158inline static bool isPowerOfTwo(int x)
159{
160 // Assumption: x >= 1
161 return x == (x & -x);
162}
163
165{
166 bool npotSupported = m_rc->rhi() && m_rc->rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat);
167 return npotSupported || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
168}
169
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qrect.h:30
bool isFeatureSupported(QRhi::Feature feature) const
Definition qrhi.cpp:10110
@ NPOTTextureRepeat
Definition qrhi.h:1841
void setMipmapFiltering(QSGTexture::Filtering filtering) override
void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) override
void setMaterialTexture(QSGTexture *texture) override
void setFiltering(QSGTexture::Filtering filtering) override
QSGDefaultInternalImageNode(QSGDefaultRenderContext *rc)
QSGTexture * materialTexture() const override
void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) override
bool supportsWrap(const QSize &size) const override
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
void setOpaqueMaterial(QSGMaterial *material)
Sets the opaque material of this geometry to material.
Definition qsgnode.cpp:958
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.
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
QSGMaterial::Flags flags() const
Returns the material's flags.
Definition qsgmaterial.h:44
int viewCount() const
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
@ RequiresFullMatrixExceptTranslate
Definition qsgmaterial.h:20
@ DirtyMaterial
Definition qsgnode.h:75
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
QSGTexture::WrapMode verticalWrapMode() const
Returns this material's vertical wrap mode.
void setFiltering(QSGTexture::Filtering filteringType)
Sets the filtering to filtering.
void setVerticalWrapMode(QSGTexture::WrapMode mode)
Sets the vertical wrap mode to mode.
void setHorizontalWrapMode(QSGTexture::WrapMode mode)
Sets the horizontal wrap mode to mode.
QSGTexture::Filtering filtering() const
Returns this material's filtering mode.
void setMipmapFiltering(QSGTexture::Filtering filteringType)
Sets the mipmap mode to filtering.
void setTexture(QSGTexture *texture)
Sets the texture of this material to texture.
QSGTexture::WrapMode horizontalWrapMode() const
Returns this material's horizontal wrap mode.
QSGTexture::Filtering mipmapFiltering() const
Returns this material's mipmap filtering mode.
QSGTexture * texture() const
Returns this texture material's texture.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
QSGMaterialType * type() const override
void setTexture(QSGTexture *texture)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
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...
\inmodule QtQuick
Definition qsgtexture.h:20
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
Definition qsgtexture.h:34
WrapMode
Specifies how the sampler should treat texture coordinates.
Definition qsgtexture.h:28
\inmodule QtCore
Definition qsize.h:25
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
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...
else opt state
[0]
Combined button and popup list for selecting options.
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLuint texture
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
static bool isPowerOfTwo(int x)
static bool isPowerOfTwo(int x)
#define QStringLiteral(str)
#define Q_UNUSED(x)
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.