QSGTexture Class
The QSGTexture class is a baseclass for textures used in the scene graph. More...
| Header: | #include <QSGTexture> |
| qmake: | QT += quick |
| Inherits: | QObject |
| Inherited By: |
Public Types
| struct | NativeTexture |
| enum | AnisotropyLevel { AnisotropyNone, Anisotropy2x, Anisotropy4x, Anisotropy8x, Anisotropy16x } |
| enum | Filtering { None, Nearest, Linear } |
| enum | WrapMode { Repeat, ClampToEdge, MirroredRepeat } |
Detailed Description
Users can freely implement their own texture classes to support arbitrary input textures, such as YUV video frames or 8 bit alpha masks. The scene graph backend provides a default implementation of normal color textures. As the implementation of these may be hardware specific, they are constructed via the factory function QQuickWindow::createTextureFromImage().
The texture is a wrapper around an OpenGL texture, which texture id is given by textureId() and which size in pixels is given by textureSize(). hasAlphaChannel() reports if the texture contains opacity values and hasMipmaps() reports if the texture contains mipmap levels.
To use a texture, call the bind() function. The texture parameters specifying how the texture is bound, can be specified with setMipmapFiltering(), setFiltering(), setHorizontalWrapMode() and setVerticalWrapMode(). The texture will internally try to store these values to minimize the OpenGL state changes when the texture is bound.
Texture Atlasses
Some scene graph backends use texture atlasses, grouping multiple small textures into one large texture. If this is the case, the function isAtlasTexture() will return true. Atlasses are used to aid the rendering algorithm to do better sorting which increases performance. The location of the texture inside the atlas is given with the normalizedTextureSubRect() function.
If the texture is used in such a way that atlas is not preferable, the function removedFromAtlas() can be used to extract a non-atlassed copy.
Note: All classes with QSG prefix should be used solely on the scene graph's rendering thread. See Scene Graph and Rendering for more information.
See also Scene Graph - Rendering FBOs and Scene Graph - Rendering FBOs in a thread.
Member Type Documentation
enum QSGTexture::AnisotropyLevel
Specifies the anisotropic filtering level to be used when the texture is not screen aligned.
| Constant | Value | Description |
|---|---|---|
QSGTexture::AnisotropyNone | 0 | No anisotropic filtering. |
QSGTexture::Anisotropy2x | 1 | 2x anisotropic filtering. |
QSGTexture::Anisotropy4x | 2 | 4x anisotropic filtering. |
QSGTexture::Anisotropy8x | 3 | 8x anisotropic filtering. |
QSGTexture::Anisotropy16x | 4 | 16x anisotropic filtering. |
This enum was introduced or modified in Qt 5.9.
enum QSGTexture::Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
| Constant | Value | Description |
|---|---|---|
QSGTexture::None | 0 | No filtering should occur. This value is only used together with setMipmapFiltering(). |
QSGTexture::Nearest | 1 | Sampling returns the nearest texel. |
QSGTexture::Linear | 2 | Sampling returns a linear interpolation of the neighboring texels. |
enum QSGTexture::WrapMode
Specifies how the texture should treat texture coordinates.
| Constant | Value | Description |
|---|---|---|
QSGTexture::Repeat | 0 | Only the fractional part of the texture coordinate is used, causing values above 1 and below 0 to repeat. |
QSGTexture::ClampToEdge | 1 | Values above 1 are clamped to 1 and values below 0 are clamped to 0. |
QSGTexture::MirroredRepeat | 2 | When the texture coordinate is even, only the fractional part is used. When odd, the texture coordinate is set to 1 - fractional part. This value has been introduced in Qt 5.10. |