Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dquadtextureprovider.cpp File Reference

(c56711cd927f407d348109e5f596f6a4d8436586)

#include "qquick3dquadtextureprovider_p.h"
#include <QtQuick3DRuntimeRender/private/qssgshadermaterialadapter_p.h>
#include <ssg/qssgrenderextensions.h>
#include <ssg/qssgrenderhelpers.h>
#include <ssg/qssgrendercontextcore.h>
#include <ssg/qquick3dextensionhelpers.h>
Include dependency graph for qquick3dquadtextureprovider.cpp:

Go to the source code of this file.

Classes

class  QSSGQuadTextureProvider

Functions

static void insertVertexMainArgs (QByteArray &snippet)

Variables

static QT_BEGIN_NAMESPACE constexpr float g_vertexData []
 \qmltype QuadTextureProvider \nativetype QQuick3DQuadTextureProvider \inqmlmodule QtQuick3D.Helpers \inherits TextureProviderExtension
static constexpr uint16_t g_indexData [] = { 0, 1, 2, 0, 2, 3 }
static const QByteArray mainVertexSnippet
static const QByteArray mainVertexSnippetFlipped
static const QByteArray mainFragmentSnippet
static const QByteArray fallbackFragmentShaderStr

Function Documentation

◆ insertVertexMainArgs()

void insertVertexMainArgs ( QByteArray & snippet)
inlinestatic

Definition at line 263 of file qquick3dquadtextureprovider.cpp.

Variable Documentation

◆ fallbackFragmentShaderStr

const QByteArray fallbackFragmentShaderStr
static
Initial value:
= R"(
void MAIN()
{
FRAGCOLOR = vec4(1.0, 0.0, 1.0, 1.0);
}
)"

Definition at line 256 of file qquick3dquadtextureprovider.cpp.

◆ g_indexData

constexpr uint16_t g_indexData = { 0, 1, 2, 0, 2, 3 }
staticconstexpr

Definition at line 230 of file qquick3dquadtextureprovider.cpp.

◆ g_vertexData

QT_BEGIN_NAMESPACE constexpr float g_vertexData
staticconstexpr
Initial value:
= { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f }

\qmltype QuadTextureProvider \nativetype QQuick3DQuadTextureProvider \inqmlmodule QtQuick3D.Helpers \inherits TextureProviderExtension

Since
6.12

Used to render a quad texture using a custom fragment shader.

This type is used to render quad textures using custom shader code, enabling a convenient way to get programmable textures. By providing a fragment shader and wanted properties, a pass is created and a shader pipeline is built based on the provided data, passing the properties in as uniform values to the fragment shader.

Built-ins provided:

\table \header

  • Keyword
  • Type
  • Description \row
  • MAIN
  • void MAIN() is the entry point. This function must always be present in the fragment shader provided. \row
  • INPUT_UV
  • vec2
  • UV coordinates for current fragment. Top-right: [1, 1] and bottom-left: [0, 0]. \row
  • OUTPUT_SIZE
  • vec2
  • Size of the output texture. \row \endtable

Custom properties gets mapped to uniforms. Any time the values change, the updated value will become visible in the shader. This concept may already be familiar from \l ShaderEffect.

The name of the QML property and the GLSL variable must match. There is no separate declaration in the shader code for the individual uniforms. Rather, the QML property name can be used as-is.

The following table lists how the types are mapped:

\table \header

  • QML Type
  • Shader Type
  • Notes \row
  • real, int, bool
  • float, int, bool
  • \row
  • color
  • vec4
  • sRGB to linear conversion is performed implicitly \row
  • vector2d
  • vec2
  • \row
  • vector3d
  • vec3
  • \row
  • vector4d
  • vec4
  • \row
  • matrix4x4
  • mat4
  • \row
  • quaternion
  • vec4
  • scalar value is w \row
  • rect
  • vec4
  • \row
  • point, size
  • vec2
  • \row
  • TextureInput
  • sampler2D
  • \endtable

An example of outputting a simple red texture could be done the following way: \badcode Texture { textureProvider: QuadTextureProvider { width: 128 height: 128 fragmentShaderCode: void MAIN() { FRAGCOLOR = vec4(1.0, 0.0, 0.0, 1.0); } } }

Another example sampling from a \l Texture property and mixing with UV colors: \badcode Texture { textureProvider: QuadTextureProvider { fragmentShaderCode: void MAIN() { vec2 uv = INPUT_UV; vec4 c = texture(checkers, uv); FRAGCOLOR = mix(c, vec4(uv, 1, 1), 0.5); }

property Texture checkers : Texture { source: "../shared/maps/checkers2.png" } } }

The result is the following:

Note
Providing a vertex shader is not supported, only a fragment shader.
If \l Texture properties are provided it will not render until the dependent textures are available.
There is currently no support for adding / removing properties at runtime, just modifying the original ones.
See also
ShaderEffect

\qmlproperty url QuadTextureProvider::fragmentShader

Since
6.12

Specifies the file with the snippet of custom fragment shader code.

The value is a URL and must either be a local file or use the qrc scheme to access files embedded via the Qt resource system. Relative file paths (without a scheme) are also accepted, in which case the file is treated as relative to the component (the {.qml} file).

Warning
Shader snippets are assumed to be trusted content. Application developers are advised to carefully consider the potential implications before allowing the loading of user-provided content that is not part of the application.
Note
If set, fragmentShaderCode will take precedence over fragmentShader.
See also
fragmentShaderCode

\qmlproperty string QuadTextureProvider::fragmentShaderCode

Since
6.12

Specifies a snippet of custom fragment shader code.

Used as a way to inline shader code as a string instead of providing a file.

Note
If set, this property will take precedence over \l fragmentShader.
See also
fragmentShader

\qmlproperty int QuadTextureProvider::width

Since
6.12 \default 128

Specifies the width in pixels of the output texture.

See also
height

\qmlproperty int QuadTextureProvider::height

Since
6.12 \default 128

Specifies the height in pixels of the output texture.

See also
width

\qmlproperty enumeration QuadTextureProvider::format

Since
6.12 \default TexureData.RGBA16F

This property holds the format of the output texture.

\value TexureData.RGBA8 The color format is considered as 8-bit integer in R, G, B and alpha channels. \value TexureData.RGBA16F The color format is considered as 16-bit float in R,G,B and alpha channels. \value TexureData.RGBA32F The color format is considered as 32-bit float in R, G, B and alpha channels. \value TexureData.RGBE8 The color format is considered as 8-bit mantissa in the R, G, and B channels and 8-bit shared exponent. \value TexureData.R8 The color format is considered as 8-bit integer in R channel. \value TexureData.R16 The color format is considered as 16-bit integer in R channel. \value TexureData.R16F The color format is considered as 16-bit float in R channel. \value TexureData.R32F The color format is considered as 32-bit float R channel.

Note
With the exception of TexureData.RGBA8, not every format is supported at runtime as this depends on which backend is being used as well which hardware is being used.

Definition at line 227 of file qquick3dquadtextureprovider.cpp.

Referenced by QSSGQuadTextureProvider::prepareRender().

◆ mainFragmentSnippet

const QByteArray mainFragmentSnippet
static
Initial value:
= R"(
void main()
{
qt_customMain();
}
)"

Definition at line 249 of file qquick3dquadtextureprovider.cpp.

◆ mainVertexSnippet

const QByteArray mainVertexSnippet
static
Initial value:
= R"(
void main()
{
qt_inputUV = attr_uv;
gl_Position = vec4(attr_pos, 0.0, 1.0);
}
)"

Definition at line 232 of file qquick3dquadtextureprovider.cpp.

◆ mainVertexSnippetFlipped

const QByteArray mainVertexSnippetFlipped
static
Initial value:
= R"(
void main()
{
qt_inputUV = attr_uv;
qt_inputUV.y = 1.0 - qt_inputUV.y;
gl_Position = vec4(attr_pos, 0.0, 1.0);
}
)"

Definition at line 240 of file qquick3dquadtextureprovider.cpp.