Qt 6.x
The Qt SDK
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:
18
19 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
20};
21
22
24{
26 setFlag(Blending, true);
27}
28
30{
32}
33
35{
36 static QSGMaterialType type;
37 return &type;
38}
39
41{
42 Q_UNUSED(renderMode);
44}
45
47{
48 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.vert.qsb"));
49 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.frag.qsb"));
50}
51
53{
54 bool changed = false;
55 QByteArray *buf = state.uniformData();
56
57 if (!oldMaterial) {
58 // The viewport is constant, so set the pixel size uniform only once (per batches with the same material).
59 const QRect r = state.viewportRect();
60 const QVector2D v(2.0f / r.width(), 2.0f / r.height());
61 memcpy(buf->data() + 64 + 8, &v, 8);
62 changed = true;
63 }
64
65 changed |= QSGTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
66
67 return changed;
68}
69
70
72 : m_rc(rc)
73{
74 setMaterial(&m_materialO);
75 setOpaqueMaterial(&m_material);
76}
77
79{
80 if (m_material.filtering() == filtering)
81 return;
82
83 m_material.setFiltering(filtering);
84 m_materialO.setFiltering(filtering);
85 m_smoothMaterial.setFiltering(filtering);
87}
88
90{
91 if (m_material.mipmapFiltering() == filtering)
92 return;
93
94 m_material.setMipmapFiltering(filtering);
95 m_materialO.setMipmapFiltering(filtering);
96 m_smoothMaterial.setMipmapFiltering(filtering);
98}
99
101{
102 if (m_material.verticalWrapMode() == wrapMode)
103 return;
104
105 m_material.setVerticalWrapMode(wrapMode);
106 m_materialO.setVerticalWrapMode(wrapMode);
107 m_smoothMaterial.setVerticalWrapMode(wrapMode);
109}
110
112{
113 if (m_material.horizontalWrapMode() == wrapMode)
114 return;
115
116 m_material.setHorizontalWrapMode(wrapMode);
117 m_materialO.setHorizontalWrapMode(wrapMode);
118 m_smoothMaterial.setHorizontalWrapMode(wrapMode);
120}
121
123{
124 if (m_antialiasing) {
125 setMaterial(&m_smoothMaterial);
126 setOpaqueMaterial(nullptr);
127 } else {
128 setMaterial(&m_materialO);
129 setOpaqueMaterial(&m_material);
130 }
131}
132
134{
135 m_material.setTexture(texture);
136 m_materialO.setTexture(texture);
137 m_smoothMaterial.setTexture(texture);
138}
139
141{
142 return m_material.texture();
143}
144
146{
147 const bool alpha = m_material.flags() & QSGMaterial::Blending;
148 if (materialTexture() && alpha != materialTexture()->hasAlphaChannel()) {
149 m_material.setFlag(QSGMaterial::Blending, !alpha);
150 return true;
151 }
152 return false;
153}
154
155inline static bool isPowerOfTwo(int x)
156{
157 // Assumption: x >= 1
158 return x == (x & -x);
159}
160
162{
163 bool npotSupported = m_rc->rhi() && m_rc->rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat);
164 return npotSupported || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
165}
166
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qrect.h:30
bool isFeatureSupported(QRhi::Feature feature) const
Definition qrhi.cpp:9681
@ NPOTTextureRepeat
Definition qrhi.h:1803
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:925
void setOpaqueMaterial(QSGMaterial *material)
Sets the opaque material of this geometry to material.
Definition qsgnode.cpp:956
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:40
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:622
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.