PySide6.QtQuick.QSGTexture¶
- class QSGTexture¶
- The - QSGTextureclass is the base class for textures used in the scene graph. More…- Inherited by: - QSGDynamicTexture- Synopsis¶- Methods¶- def - __init__()
- def - filtering()
- def - setFiltering()
 - Virtual methods¶
- def - comparisonKey()
- def - hasMipmaps()
- def - isAtlasTexture()
- def - rhiTexture()
- def - textureSize()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - 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 provides a default implementation for RGBA textures.The default implementation is not instantiated directly, rather they are constructed via factory functions, such as - createTextureFromImage().- With the default implementation, each - QSGTextureis backed by a QRhiTexture, which in turn contains a native texture object, such as an OpenGL texture or a Vulkan image.- The size in pixels is given by - textureSize().- hasAlphaChannel()reports if the texture contains opacity values and- hasMipmaps()reports if the texture contains mipmap levels.- Materialsthat work with textures reimplement- updateSampledImage()to provide logic that decides which- QSGTexture‘s underlying native texture should be exposed at a given shader resource binding point.- QSGTexturedoes not separate image (texture) and sampler objects. The parameters for filtering and wrapping can be specified with- setMipmapFiltering(),- setFiltering(),- setHorizontalWrapMode()and- setVerticalWrapMode(). The scene graph and Qt’s graphics abstraction takes care of creating separate sampler objects, when applicable.- Texture Atlases¶- 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. Atlases are used to aid the rendering algorithm to do better sorting which increases performance. Atlases are also essential for batching (merging together geometry to reduce the number of draw calls), because two instances of the same material using two different QSGTextures are not batchable, whereas if both QSGTextures refer to the same atlas, batching can happen, assuming the materials are otherwise compatible.- 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-atlased 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. - class WrapMode¶
- Specifies how the sampler should treat texture coordinates. - Constant - Description - QSGTexture.WrapMode.Repeat - Only the fractional part of the texture coordinate is used, causing values above 1 and below 0 to repeat. - QSGTexture.WrapMode.ClampToEdge - Values above 1 are clamped to 1 and values below 0 are clamped to 0. - QSGTexture.WrapMode.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.
 - class Filtering¶
- Specifies how sampling of texels should filter when texture coordinates are not pixel aligned. - Constant - Description - QSGTexture.Filtering.None_ - No filtering should occur. This value is only used together with - setMipmapFiltering().- QSGTexture.Filtering.Nearest - Sampling returns the nearest texel. - QSGTexture.Filtering.Linear - Sampling returns a linear interpolation of the neighboring texels. 
 - class AnisotropyLevel¶
- Specifies the anisotropic filtering level to be used when the texture is not screen aligned. - Constant - Description - QSGTexture.AnisotropyLevel.AnisotropyNone - No anisotropic filtering. - QSGTexture.AnisotropyLevel.Anisotropy2x - 2x anisotropic filtering. - QSGTexture.AnisotropyLevel.Anisotropy4x - 4x anisotropic filtering. - QSGTexture.AnisotropyLevel.Anisotropy8x - 8x anisotropic filtering. - QSGTexture.AnisotropyLevel.Anisotropy16x - 16x anisotropic filtering. 
 - __init__()¶
 - Constructs the - QSGTexturebase class.- anisotropyLevel()¶
- Return type:
 
 - Returns the anisotropy level in use for filtering this texture. - See also - commitTextureOperations(rhi, resourceUpdates)¶
- Parameters:
- rhi – - QRhi
- resourceUpdates – - QRhiResourceUpdateBatch
 
 
 - Call this function to enqueue image upload operations to - resourceUpdates, in case there are any pending ones. When there is no new data (for example, because there was no setImage() since the last call to this function), the function does nothing.- Materials involving - rhitextures are expected to call this function from their- updateSampledImage()implementation, typically without any conditions, passing- state.rhi()and- state.resourceUpdateBatch()from the- RenderState.- Warning - This function can only be called from the rendering thread. - abstract comparisonKey()¶
- Return type:
- int 
 
 - Returns a key suitable for comparing textures. Typically used in - compare()implementations.- Just comparing - QSGTexturepointers is not always sufficient because two- QSGTextureinstances that refer to the same native texture object underneath should also be considered equal. Hence the need for this function.- Implementations of this function are not expected to, and should not create any graphics resources (native texture objects) in case there are none yet. - A - QSGTexturethat does not have a native texture object underneath is typically not equal to any other- QSGTexture, so the return value has to be crafted accordingly. 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. - Returns - rectconverted to normalized coordinates.- See also - Returns the sampling mode to be used for this texture. - See also - abstract hasAlphaChannel()¶
- Return type:
- bool 
 
 - Returns true if the texture data contains an alpha channel. - abstract hasMipmaps()¶
- Return type:
- bool 
 
 - Returns true if the texture data contains mipmap levels. - Returns the horizontal wrap mode to be used for this texture. - See also - isAtlasTexture()¶
- Return type:
- bool 
 
 - Returns whether this texture is part of an atlas or not. - The default implementation returns false. - Returns whether mipmapping should be used when sampling from this texture. - See also - 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. - removedFromAtlas([resourceUpdates=None])¶
- Parameters:
- resourceUpdates – - QRhiResourceUpdateBatch
- 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. - resourceUpdatesis an optional resource update batch, on which texture operations, if any, are enqueued. Materials can retrieve an instance from- RenderState. When null, the removedFromAtlas() implementation creates its own batch and submit it right away. However, when a valid instance is specified, this function will not submit the update batch.- Warning - This function can only be called from the rendering thread. - resolveInterface(name, revision)¶
- Parameters:
- name – str 
- revision – int 
 
- Return type:
- void
 
 - rhiTexture()¶
- Return type:
- QRhiTexture
 
 - Returns the QRhiTexture for this - QSGTextureor null if there is none (either because a valid texture has not been created internally yet, or because the concept is not applicable to the scenegraph backend in use).- This function is not expected to create a new QRhiTexture in case there is none. It should return null in that case. The expectation towards the renderer is that a null texture leads to using a transparent, dummy texture instead. - Warning - This function can only be called from the rendering thread. - setAnisotropyLevel(level)¶
- Parameters:
- level – - AnisotropyLevel
 
 - Sets the level of anisotropic filtering to - level. The default value is- AnisotropyNone, which means no anisotropic filtering is enabled.- Note - The request may be ignored depending on the graphics API in use. There is no guarantee anisotropic filtering is supported at run time. - See also - Sets the sampling mode to - filter.- See also - Sets the horizontal wrap mode to - hwrap- See also - Sets the mipmap sampling mode to - filter.- Setting the mipmap filtering has no effect it the texture does not have mipmaps. - See also - Sets the vertical wrap mode to - vwrap- See also - Returns the size of the texture in pixels. - Returns the vertical wrap mode to be used for this texture. - See also