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
qquick3dcubemaptexture.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"qquick3dcubemaptexture_p.h"
7
#
include
"qquick3dobject_p.h"
8
9
QT_BEGIN_NAMESPACE
10
11
/*!
12
\qmltype CubeMapTexture
13
\inherits Texture
14
\inqmlmodule QtQuick3D
15
\brief Defines a cube map texture for use in 3D scenes.
16
17
CubeMapTexture is a Texture that represents a cube map texture. A cube map
18
texture has 6 faces (X+, X-, Y+, Y-, Z+, Z-), where each face is an
19
individual 2D image. CubeMapTexture allows \l{CustomMaterial}{custom
20
materials} and \l{Effect}{post-processing effects} to work with cube map
21
textures in their shaders. A cube map can also be used to define the scene
22
environment's \l{SceneEnvironment::skyBoxCubeMap}{skybox}.
23
24
\qml
25
CustomMaterial {
26
property TextureInput customTexture: TextureInput {
27
texture: CubeMapTexture {
28
source: "cubemap.ktx"
29
}
30
}
31
fragmentShader: "shader.frag"
32
}
33
\endqml
34
35
Here shader.frag can be implemented assuming \c customTexture is sampler
36
uniform with the GLSL type a \c samplerCube. This means that the
37
\c{texture()} GLSL function takes a \c vec3 as the texture coordinate for
38
that sampler. If we used \l Texture, the type would have been \c sampler2D.
39
40
\badcode
41
void MAIN()
42
{
43
vec4 c = texture(customTexture, NORMAL);
44
BASE_COLOR = vec4(c.rgb, 1.0);
45
}
46
\endcode
47
48
Sourcing a Texture from a container with a cubemap only loads face 0 (X+)
49
and results in a 2D texture. Whereas sourcing a CubeMapTexture from the
50
same asset loads all 6 faces and results in a cubemap texture.
51
52
CubeMapTexture inherits all its properties from Texture. The important
53
difference is that \l {Texture::}{source} must refer to a image file
54
containing a cubemap, or to a list of image files. In practice a single
55
file means a \l{https://www.khronos.org/ktx/}{KTX} container containing 6
56
face images.
57
58
Sourcing a CubeMapTexture from 6 individual images can be done in two
59
different ways. Either as a semicolon-separated list of file names in
60
X+, X-, Y+, Y-, Z+, Z- order:
61
\qml
62
CubeMapTexture {
63
source: "maps/right.jpg;maps/left.jpg;maps/top.jpg;maps/bottom.jpg;maps/front.jpg;maps/back.jpg"
64
}
65
\endqml
66
or as a string containing a "%p" placeholder, where "%p" will be replaced by the strings
67
"posx", "negx", "posy", "negy", "posz", and "negz" to generate the six filenames:
68
\qml
69
CubeMapTexture {
70
source: "maps/sky_%p.png"
71
// equivalent to:
72
// source: "maps/sky_posx.png;maps/sky_negx.png;maps/sky_posy.png;maps/sky_negy.png;maps/sky_posz.png;maps/sky_negz.png"
73
}
74
\endqml
75
76
\note Sourcing image data via other means, such as \l {Texture::}{sourceItem}
77
or \l {Texture::}{textureData} is not supported for CubeMapTexture at the
78
moment.
79
80
\sa Texture, CustomMaterial, Effect
81
*/
82
83
QQuick3DCubeMapTexture::QQuick3DCubeMapTexture(QQuick3DObject *parent)
84
: QQuick3DTexture(*(
new
QQuick3DObjectPrivate(QQuick3DObjectPrivate::Type::ImageCube)), parent)
85
{
86
}
87
88
QQuick3DCubeMapTexture::~QQuick3DCubeMapTexture()
89
{
90
}
91
92
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
qtquick3d
src
quick3d
qquick3dcubemaptexture.cpp
Generated on
for Qt by
1.16.1