QSGTexture Class

The QSGTexture class is a baseclass for textures used in the scene graph. 更多...

头: #include <QSGTexture>
qmake: QT += quick
继承: QObject
继承者: QSGDynamicTexture

公共类型

enum AnisotropyLevel { AnisotropyNone, Anisotropy2x, Anisotropy4x, Anisotropy8x, Anisotropy16x }
enum 过滤 { None, Nearest, Linear }
enum WrapMode { Repeat, ClampToEdge }

公共函数

QSGTexture ()
~QSGTexture ()
QSGTexture::AnisotropyLevel anisotropyLevel () const
virtual void bind () = 0
QRectF convertToNormalizedSourceRect (const QRectF & rect ) const
QSGTexture::Filtering filtering () const
virtual bool hasAlphaChannel () const = 0
virtual bool hasMipmaps () const = 0
QSGTexture::WrapMode horizontalWrapMode () const
virtual bool isAtlasTexture () const
QSGTexture::Filtering mipmapFiltering () const
virtual QRectF normalizedTextureSubRect () const
virtual QSGTexture * removedFromAtlas () const
void setAnisotropyLevel (AnisotropyLevel level )
void setFiltering (Filtering filter )
void setHorizontalWrapMode (WrapMode hwrap )
void setMipmapFiltering (Filtering filter )
void setVerticalWrapMode (WrapMode vwrap )
virtual int textureId () const = 0
virtual QSize textureSize () const = 0
void updateBindOptions (bool force = false)
QSGTexture::WrapMode verticalWrapMode () const

额外继承成员

详细描述

The QSGTexture class is a baseclass for textures used in the scene graph.

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 () 和 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 () 函数。

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.

注意: 所有带有 QSG 前缀的类只应用于场景图形渲染线程。见 场景图形和渲染 了解更多信息。

另请参阅 场景图形 - 渲染 FBO (帧缓冲对象) and Scene Graph - Rendering FBOs in a thread .

成员类型文档编制

enum QSGTexture:: AnisotropyLevel

Specifies the anisotropic filtering level to be used when the texture is not screen aligned.

常量 描述
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.

该枚举在 Qt 5.9 引入或被修改。

enum QSGTexture:: 过滤

Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.

常量 描述
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.

常量 描述
QSGTexture::Repeat 0 Only the factional part of the texture coordiante 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:: QSGTexture ()

构造 QSGTexture 基类。

QSGTexture:: ~QSGTexture ()

销毁 QSGTexture .

QSGTexture::AnisotropyLevel QSGTexture:: anisotropyLevel () const

Returns the anisotropy level in use for filtering this texture.

该函数在 Qt 5.9 引入。

另请参阅 setAnisotropyLevel ().

[pure virtual] void 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 .

警告: This function can only be called from the rendering thread.

QRectF QSGTexture:: convertToNormalizedSourceRect (const QRectF & rect ) const

返回 rect converted to normalized coordinates.

另请参阅 normalizedTextureSubRect ().

QSGTexture::Filtering QSGTexture:: filtering () const

Returns the sampling mode to be used for this texture.

另请参阅 setFiltering ().

[pure virtual] bool QSGTexture:: hasAlphaChannel () const

Returns true if the texture data contains an alpha channel.

[pure virtual] bool QSGTexture:: hasMipmaps () const

Returns true if the texture data contains mipmap levels.

QSGTexture::WrapMode QSGTexture:: horizontalWrapMode () const

Returns the horizontal wrap mode to be used for this texture.

另请参阅 setHorizontalWrapMode ().

[虚拟] bool QSGTexture:: isAtlasTexture () const

Returns weither this texture is part of an atlas or not.

默认实现返回 false。

QSGTexture::Filtering QSGTexture:: mipmapFiltering () const

Returns whether mipmapping should be used when sampling from this texture.

另请参阅 setMipmapFiltering ().

[虚拟] QRectF QSGTexture:: normalizedTextureSubRect () const

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.

[虚拟] QSGTexture *QSGTexture:: removedFromAtlas () const

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.

警告: This function can only be called from the rendering thread.

void QSGTexture:: setAnisotropyLevel ( AnisotropyLevel level )

Sets the level of anisotropic filtering to be used for the upcoming bind () call to level 。默认值为 QSGTexture::AnisotropyNone , which means no anisotropic filtering is enabled.

该函数在 Qt 5.9 引入。

另请参阅 anisotropyLevel ().

void QSGTexture:: setFiltering ( 过滤 filter )

Sets the sampling mode to be used for the upcoming bind () call to filter .

另请参阅 filtering ().

void QSGTexture:: setHorizontalWrapMode ( WrapMode hwrap )

Sets the horizontal wrap mode to be used for the upcoming bind () call to hwrap

另请参阅 horizontalWrapMode ().

void QSGTexture:: setMipmapFiltering ( 过滤 filter )

Sets the mipmap sampling mode to be used for the upcoming bind () call to filter .

Setting the mipmap filtering has no effect it the texture does not have mipmaps.

另请参阅 mipmapFiltering () 和 hasMipmaps ().

void QSGTexture:: setVerticalWrapMode ( WrapMode vwrap )

Sets the vertical wrap mode to be used for the upcoming bind () call to vwrap

另请参阅 verticalWrapMode ().

[pure virtual] int QSGTexture:: textureId () const

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.

警告: This function can only be called from the rendering thread.

[pure virtual] QSize QSGTexture:: textureSize () const

Returns the size of the texture.

void QSGTexture:: updateBindOptions ( bool force = false)

Update the texture state to match the filtering, mipmap and wrap options currently set.

force is true, all properties will be updated regardless of weither they have changed or not.

QSGTexture::WrapMode QSGTexture:: verticalWrapMode () const

Returns the vertical wrap mode to be used for this texture.

另请参阅 setVerticalWrapMode ().