QSGTexture¶
The
QSGTexture
class is a baseclass for textures used in the scene graph. More…
Inherited by: QSGDynamicTexture
Synopsis¶
Functions¶
def
anisotropyLevel
()def
comparisonKey
()def
convertToNormalizedSourceRect
(rect)def
filtering
()def
horizontalWrapMode
()def
mipmapFiltering
()def
setAnisotropyLevel
(level)def
setFiltering
(filter)def
setHorizontalWrapMode
(hwrap)def
setMipmapFiltering
(filter)def
setVerticalWrapMode
(vwrap)def
updateBindOptions
([force=false])def
verticalWrapMode
()
Virtual functions¶
def
bind
()def
hasAlphaChannel
()def
hasMipmaps
()def
isAtlasTexture
()def
normalizedTextureSubRect
()def
removedFromAtlas
()def
textureId
()def
textureSize
()
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
createTextureFromImage()
.The texture is a wrapper around an OpenGL texture, which texture id is given by
textureId()
and which size in pixels is given bytextureSize()
.hasAlphaChannel()
reports if the texture contains opacity values andhasMipmaps()
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 withsetMipmapFiltering()
,setFiltering()
,setHorizontalWrapMode()
andsetVerticalWrapMode()
. 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 thenormalizedTextureSubRect()
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 Scene Graph - Rendering FBOs in a thread
- class PySide2.QtQuick.QSGTexture¶
Constructs the
QSGTexture
base class.
- PySide2.QtQuick.QSGTexture.WrapMode¶
Specifies how the texture should treat texture coordinates.
Constant
Description
QSGTexture.Repeat
Only the fractional part of the texture coordinate is used, causing values above 1 and below 0 to repeat.
QSGTexture.ClampToEdge
Values above 1 are clamped to 1 and values below 0 are clamped to 0.
QSGTexture.MirroredRepeat
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.
- PySide2.QtQuick.QSGTexture.Filtering¶
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
Constant
Description
QSGTexture.None
No filtering should occur. This value is only used together with
setMipmapFiltering()
.QSGTexture.Nearest
Sampling returns the nearest texel.
QSGTexture.Linear
Sampling returns a linear interpolation of the neighboring texels.
- PySide2.QtQuick.QSGTexture.AnisotropyLevel¶
Specifies the anisotropic filtering level to be used when the texture is not screen aligned.
Constant
Description
QSGTexture.AnisotropyNone
No anisotropic filtering.
QSGTexture.Anisotropy2x
2x anisotropic filtering.
QSGTexture.Anisotropy4x
4x anisotropic filtering.
QSGTexture.Anisotropy8x
8x anisotropic filtering.
QSGTexture.Anisotropy16x
16x anisotropic filtering.
New in version 5.9.
- PySide2.QtQuick.QSGTexture.anisotropyLevel()¶
- Return type:
Returns the anisotropy level in use for filtering this texture.
See also
- PySide2.QtQuick.QSGTexture.bind()¶
Call this function to bind this texture to the current texture target.
Binding a texture may also include uploading the texture data from a previously set
QImage
.Warning
This function should only be called when running with the direct OpenGL rendering path.
Warning
This function can only be called from the rendering thread.
- PySide2.QtQuick.QSGTexture.comparisonKey()¶
- Return type:
int
Returns a key suitable for comparing textures. Typically used in
compare()
implementations.Just comparing
QSGTexture
pointers is not always sufficient because twoQSGTexture
instances that refer to the same native texture object underneath should also be considered equal. Hence this function.Note
Unlike
textureId()
, implementations of this function are not expected to and should not create any graphics resources (so texture objects) in case there is none yet.A
QSGTexture
that does not have a native texture object underneath is typically not equal to any otherQSGTexture
. There are exceptions to this, in particular when atlasing is used (where multiple textures share the same atlas texture under the hood), that is then up to the subclass implementations to deal with as appropriate.Warning
This function can only be called from the rendering thread.
- PySide2.QtQuick.QSGTexture.convertToNormalizedSourceRect(rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Returns
rect
converted to normalized coordinates.See also
- PySide2.QtQuick.QSGTexture.filtering()¶
- Return type:
Returns the sampling mode to be used for this texture.
See also
- PySide2.QtQuick.QSGTexture.hasAlphaChannel()¶
- Return type:
bool
Returns true if the texture data contains an alpha channel.
- PySide2.QtQuick.QSGTexture.hasMipmaps()¶
- Return type:
bool
Returns true if the texture data contains mipmap levels.
- PySide2.QtQuick.QSGTexture.horizontalWrapMode()¶
- Return type:
Returns the horizontal wrap mode to be used for this texture.
See also
- PySide2.QtQuick.QSGTexture.isAtlasTexture()¶
- Return type:
bool
Returns weither this texture is part of an atlas or not.
The default implementation returns false.
- PySide2.QtQuick.QSGTexture.mipmapFiltering()¶
- Return type:
Returns whether mipmapping should be used when sampling from this texture.
See also
- PySide2.QtQuick.QSGTexture.normalizedTextureSubRect()¶
- Return type:
Returns the rectangle inside
textureSize()
that this texture represents in normalized coordinates.The default implementation returns a rect at position (0, 0) with width and height of 1.
- PySide2.QtQuick.QSGTexture.removedFromAtlas()¶
- Return type:
This function returns a copy of the current texture which is removed from its atlas.
The current texture remains unchanged, so texture coordinates do not need to be updated.
Removing a texture from an atlas is primarily useful when passing it to a shader that operates on the texture coordinates 0-1 instead of the texture subrect inside the atlas.
If the texture is not part of a texture atlas, this function returns 0.
Implementations of this function are recommended to return the same instance for multiple calls to limit memory usage.
Warning
This function can only be called from the rendering thread.
- PySide2.QtQuick.QSGTexture.setAnisotropyLevel(level)¶
- Parameters:
level –
AnisotropyLevel
Sets the level of anisotropic filtering to be used for the upcoming
bind()
call tolevel
. The default value isAnisotropyNone
, which means no anisotropic filtering is enabled.See also
- PySide2.QtQuick.QSGTexture.setFiltering(filter)¶
- Parameters:
filter –
Filtering
Sets the sampling mode to be used for the upcoming
bind()
call tofilter
.See also
- PySide2.QtQuick.QSGTexture.setHorizontalWrapMode(hwrap)¶
- Parameters:
hwrap –
WrapMode
Sets the horizontal wrap mode to be used for the upcoming
bind()
call tohwrap
See also
- PySide2.QtQuick.QSGTexture.setMipmapFiltering(filter)¶
- Parameters:
filter –
Filtering
Sets the mipmap sampling mode to be used for the upcoming
bind()
call tofilter
.Setting the mipmap filtering has no effect it the texture does not have mipmaps.
See also
- PySide2.QtQuick.QSGTexture.setVerticalWrapMode(vwrap)¶
- Parameters:
vwrap –
WrapMode
Sets the vertical wrap mode to be used for the upcoming
bind()
call tovwrap
See also
- PySide2.QtQuick.QSGTexture.textureId()¶
- Return type:
int
Returns the OpenGL texture id for this texture.
The default value is 0, indicating that it is an invalid texture id.
The function should at all times return the correct texture id.
Warning
This function can only be called from the rendering thread.
- PySide2.QtQuick.QSGTexture.textureSize()¶
- Return type:
Returns the size of the texture.
- PySide2.QtQuick.QSGTexture.updateBindOptions([force=false])¶
- Parameters:
force – bool
Update the texture state to match the filtering, mipmap and wrap options currently set.
If
force
is true, all properties will be updated regardless of weither they have changed or not.
- PySide2.QtQuick.QSGTexture.verticalWrapMode()¶
- Return type:
Returns the vertical wrap mode to be used for this texture.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.