QOpenGLTexture Class

The QOpenGLTexture class encapsulates an OpenGL texture object. More...

Header: #include <QOpenGLTexture>

Public Types

enum BindingTarget { BindingTarget1D, BindingTarget1DArray, BindingTarget2D, BindingTarget2DArray, BindingTarget3D, …, BindingTargetBuffer }
enum ComparisonFunction { CompareLessEqual, CompareGreaterEqual, CompareLess, CompareGreater, CompareEqual, …, CompareNever }
enum ComparisonMode { CompareRefToTexture, CompareNone }
enum CoordinateDirection { DirectionS, DirectionT, DirectionR }
enum CubeMapFace { CubeMapPositiveX, CubeMapNegativeX, CubeMapPositiveY, CubeMapNegativeY, CubeMapPositiveZ, CubeMapNegativeZ }
enum DepthStencilMode { DepthMode, StencilMode }
enum Feature { ImmutableStorage, ImmutableMultisampleStorage, TextureRectangle, TextureArrays, Texture3D, …, TextureMipMapLevel }
flags Features
enum Filter { Nearest, Linear, NearestMipMapNearest, NearestMipMapLinear, LinearMipMapNearest, LinearMipMapLinear }
enum MipMapGeneration { GenerateMipMaps, DontGenerateMipMaps }
enum PixelFormat { NoSourceFormat, Red, RG, RGB, BGR, …, LuminanceAlpha }
enum PixelType { NoPixelType, Int8, UInt8, Int16, UInt16, …, Float32_D32_UInt32_S8_X24 }
enum SwizzleComponent { SwizzleRed, SwizzleGreen, SwizzleBlue, SwizzleAlpha }
enum SwizzleValue { RedValue, GreenValue, BlueValue, AlphaValue, ZeroValue, OneValue }
enum Target { Target1D, Target1DArray, Target2D, Target2DArray, Target3D, …, TargetBuffer }
enum TextureFormat { NoFormat, R8_UNorm, RG8_UNorm, RGB8_UNorm, RGBA8_UNorm, …, LuminanceAlphaFormat }
enum TextureUnitReset { ResetTextureUnit, DontResetTextureUnit }
enum WrapMode { Repeat, MirroredRepeat, ClampToEdge, ClampToBorder }

Public Functions

QOpenGLTexture(QOpenGLTexture::Target target)
QOpenGLTexture(const QImage &image, QOpenGLTexture::MipMapGeneration genMipMaps = GenerateMipMaps)
void allocateStorage()
void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)
void bind()
void bind(uint unit, QOpenGLTexture::TextureUnitReset reset = DontResetTextureUnit)
QColor borderColor() const
void borderColor(float *border) const
void borderColor(int *border) const
void borderColor(unsigned int *border) const
QOpenGLTexture::ComparisonFunction comparisonFunction() const
QOpenGLTexture::ComparisonMode comparisonMode() const
bool create()
QOpenGLTexture *createTextureView(QOpenGLTexture::Target target, QOpenGLTexture::TextureFormat viewFormat, int minimumMipmapLevel, int maximumMipmapLevel, int minimumLayer, int maximumLayer) const
int depth() const
QOpenGLTexture::DepthStencilMode depthStencilMode() const
void destroy()
int faces() const
QOpenGLTexture::TextureFormat format() const
void generateMipMaps()
void generateMipMaps(int baseLevel, bool resetBaseLevel = true)
int height() const
bool isAutoMipMapGenerationEnabled() const
bool isBound() const
bool isBound(uint unit)
bool isCreated() const
bool isFixedSamplePositions() const
bool isStorageAllocated() const
bool isTextureView() const
int layers() const
QPair<float, float> levelOfDetailRange() const
float levelofDetailBias() const
QOpenGLTexture::Filter magnificationFilter() const
float maximumAnisotropy() const
float maximumLevelOfDetail() const
int maximumMipLevels() const
QPair<QOpenGLTexture::Filter, QOpenGLTexture::Filter> minMagFilters() const
QOpenGLTexture::Filter minificationFilter() const
float minimumLevelOfDetail() const
int mipBaseLevel() const
QPair<int, int> mipLevelRange() const
int mipLevels() const
int mipMaxLevel() const
void release()
void release(uint unit, QOpenGLTexture::TextureUnitReset reset = DontResetTextureUnit)
int samples() const
void setAutoMipMapGenerationEnabled(bool enabled)
void setBorderColor(const QColor &color)
void setBorderColor(float r, float g, float b, float a)
void setBorderColor(int r, int g, int b, int a)
void setBorderColor(uint r, uint g, uint b, uint a)
void setComparisonFunction(QOpenGLTexture::ComparisonFunction function)
void setComparisonMode(QOpenGLTexture::ComparisonMode mode)
void setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setCompressedData(int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setCompressedData(int mipLevel, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setCompressedData(int mipLevel, int layer, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(const QImage &image, QOpenGLTexture::MipMapGeneration genMipMaps = GenerateMipMaps)
void setData(QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int mipLevel, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int mipLevel, int layer, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::CubeMapFace face, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::CubeMapFace face, int layerCount, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)
void setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode)
void setFixedSamplePositions(bool fixed)
void setFormat(QOpenGLTexture::TextureFormat format)
void setLayers(int layers)
void setLevelOfDetailRange(float min, float max)
void setLevelofDetailBias(float bias)
void setMagnificationFilter(QOpenGLTexture::Filter filter)
void setMaximumAnisotropy(float anisotropy)
void setMaximumLevelOfDetail(float value)
void setMinMagFilters(QOpenGLTexture::Filter minificationFilter, QOpenGLTexture::Filter magnificationFilter)
void setMinificationFilter(QOpenGLTexture::Filter filter)
void setMinimumLevelOfDetail(float value)
void setMipBaseLevel(int baseLevel)
void setMipLevelRange(int baseLevel, int maxLevel)
void setMipLevels(int levels)
void setMipMaxLevel(int maxLevel)
void setSamples(int samples)
void setSize(int width, int height = 1, int depth = 1)
void setSwizzleMask(QOpenGLTexture::SwizzleComponent component, QOpenGLTexture::SwizzleValue value)
void setSwizzleMask(QOpenGLTexture::SwizzleValue r, QOpenGLTexture::SwizzleValue g, QOpenGLTexture::SwizzleValue b, QOpenGLTexture::SwizzleValue a)
void setWrapMode(QOpenGLTexture::WrapMode mode)
void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode)
QOpenGLTexture::SwizzleValue swizzleMask(QOpenGLTexture::SwizzleComponent component) const
QOpenGLTexture::Target target() const
GLuint textureId() const
int width() const
QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const

Static Public Members

GLuint boundTextureId(QOpenGLTexture::BindingTarget target)
GLuint boundTextureId(uint unit, QOpenGLTexture::BindingTarget target)
bool hasFeature(QOpenGLTexture::Feature feature)

Detailed Description

QOpenGLTexture makes it easy to work with OpenGL textures and the myriad features and targets that they offer depending upon the capabilities of your OpenGL implementation.

The typical usage pattern for QOpenGLTexture is

  • Instantiate the object specifying the texture target type
  • Set properties that affect the storage requirements e.g. storage format, dimensions
  • Allocate the server-side storage
  • Optionally upload pixel data
  • Optionally set any additional properties e.g. filtering and border options
  • Render with texture or render to texture

In the common case of simply using a QImage as the source of texture pixel data most of the above steps are performed automatically.

// Prepare texture
QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).mirrored());
texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
texture->setMagnificationFilter(QOpenGLTexture::Linear);
...
// Render with texture
texture->bind();
glDrawArrays(...);

Note that the QImage is mirrored vertically to account for the fact that OpenGL and QImage use opposite directions for the y axis. Another option would be to transform your texture coordinates.

Member Type Documentation

enum QOpenGLTexture::BindingTarget

This enum defines the possible binding targets of texture units.

ConstantValueDescription
QOpenGLTexture::BindingTarget1D0x8068Equivalent to GL_TEXTURE_BINDING_1D
QOpenGLTexture::BindingTarget1DArray0x8C1CEquivalent to GL_TEXTURE_BINDING_1D_ARRAY
QOpenGLTexture::BindingTarget2D0x8069Equivalent to GL_TEXTURE_BINDING_2D
QOpenGLTexture::BindingTarget2DArray0x8C1DEquivalent to GL_TEXTURE_BINDING_2D_ARRAY
QOpenGLTexture::BindingTarget3D0x806AEquivalent to GL_TEXTURE_BINDING_3D
QOpenGLTexture::BindingTargetCubeMap0x8514Equivalent to GL_TEXTURE_BINDING_CUBE_MAP
QOpenGLTexture::BindingTargetCubeMapArray0x900AEquivalent to GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
QOpenGLTexture::BindingTarget2DMultisample0x9104Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE
QOpenGLTexture::BindingTarget2DMultisampleArray0x9105Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
QOpenGLTexture::BindingTargetRectangle0x84F6Equivalent to GL_TEXTURE_BINDING_RECTANGLE
QOpenGLTexture::BindingTargetBuffer0x8C2CEquivalent to GL_TEXTURE_BINDING_BUFFER

enum QOpenGLTexture::ComparisonFunction

This enum specifies which comparison operator is used when texture comparison is enabled on this texture.

ConstantValueDescription
QOpenGLTexture::CompareLessEqual0x0203Equivalent to GL_LEQUAL.
QOpenGLTexture::CompareGreaterEqual0x0206Equivalent to GL_GEQUAL.
QOpenGLTexture::CompareLess0x0201Equivalent to GL_LESS.
QOpenGLTexture::CompareGreater0x0204Equivalent to GL_GREATER.
QOpenGLTexture::CompareEqual0x0202Equivalent to GL_EQUAL.
QOpenGLTexture::CompareNotEqual0x0205Equivalent to GL_NOTEQUAL.
QOpenGLTexture::CompareAlways0x0207Equivalent to GL_ALWAYS.
QOpenGLTexture::CompareNever0x0200Equivalent to GL_NEVER.

enum QOpenGLTexture::ComparisonMode

This enum specifies which comparison mode is used when sampling this texture.

ConstantValueDescription
QOpenGLTexture::CompareRefToTexture0x884EEquivalent to GL_COMPARE_REF_TO_TEXTURE.
QOpenGLTexture::CompareNone0x0000Equivalent to GL_NONE.

enum QOpenGLTexture::CoordinateDirection

This enum defines the possible texture coordinate directions

ConstantValueDescription
QOpenGLTexture::DirectionS0x2802The horizontal direction. Equivalent to GL_TEXTURE_WRAP_S
QOpenGLTexture::DirectionT0x2803The vertical direction. Equivalent to GL_TEXTURE_WRAP_T
QOpenGLTexture::DirectionR0x8072The depth direction. Equivalent to GL_TEXTURE_WRAP_R

enum QOpenGLTexture::CubeMapFace

This enum defines the possible CubeMap faces.

ConstantValueDescription
QOpenGLTexture::CubeMapPositiveX0x8515Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_X
QOpenGLTexture::CubeMapNegativeX0x8516Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_X
QOpenGLTexture::CubeMapPositiveY0x8517Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Y
QOpenGLTexture::CubeMapNegativeY0x8518Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
QOpenGLTexture::CubeMapPositiveZ0x8519Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Z
QOpenGLTexture::CubeMapNegativeZ0x851AEquivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z

enum QOpenGLTexture::DepthStencilMode

This enum specifies which component of a depth/stencil texture is accessed when the texture is sampled.

ConstantValueDescription
QOpenGLTexture::DepthMode0x1902Equivalent to GL_DEPTH_COMPONENT.
QOpenGLTexture::StencilMode0x1901Equivalent to GL_STENCIL_INDEX.

enum QOpenGLTexture::Feature
flags QOpenGLTexture::Features

This enum defines the OpenGL texture-related features that can be tested for.

ConstantValueDescription
QOpenGLTexture::ImmutableStorage0x00000001Support for immutable texture storage
QOpenGLTexture::ImmutableMultisampleStorage0x00000002Support for immutable texture storage with multisample targets
QOpenGLTexture::TextureRectangle0x00000004Support for the GL_TEXTURE_RECTANGLE target
QOpenGLTexture::TextureArrays0x00000008Support for texture targets with array layers
QOpenGLTexture::Texture3D0x00000010Support for the 3 dimensional texture target
QOpenGLTexture::TextureMultisample0x00000020Support for texture targets that have multisample capabilities
QOpenGLTexture::TextureBuffer0x00000040Support for textures that use OpenGL buffer objects as their data source
QOpenGLTexture::TextureCubeMapArrays0x00000080Support for cubemap array texture target
QOpenGLTexture::Swizzle0x00000100Support for texture component swizzle masks
QOpenGLTexture::StencilTexturing0x00000200Support for stencil texturing (i.e. looking up depth or stencil components of a combined depth/stencil format texture in GLSL shaders).
QOpenGLTexture::AnisotropicFiltering0x00000400Support for anisotropic texture filtering
QOpenGLTexture::NPOTTextures0x00000800Basic support for non-power-of-two textures
QOpenGLTexture::NPOTTextureRepeat0x00001000Full support for non-power-of-two textures including texture repeat modes
QOpenGLTexture::Texture1D0x00002000Support for the 1 dimensional texture target
QOpenGLTexture::TextureComparisonOperators0x00004000Support for texture comparison operators
QOpenGLTexture::TextureMipMapLevel0x00008000Support for setting the base and maximum mipmap levels

The Features type is a typedef for QFlags<Feature>. It stores an OR combination of Feature values.

enum QOpenGLTexture::Filter

This enum defines the filtering parameters for a QOpenGLTexture object.

ConstantValueDescription
QOpenGLTexture::Nearest0x2600Equivalent to GL_NEAREST
QOpenGLTexture::Linear0x2601Equivalent to GL_LINEAR
QOpenGLTexture::NearestMipMapNearest0x2700Equivalent to GL_NEAREST_MIPMAP_NEAREST
QOpenGLTexture::NearestMipMapLinear0x2702Equivalent to GL_NEAREST_MIPMAP_LINEAR
QOpenGLTexture::LinearMipMapNearest0x2701Equivalent to GL_LINEAR_MIPMAP_NEAREST
QOpenGLTexture::LinearMipMapLinear0x2703Equivalent to GL_LINEAR_MIPMAP_LINEAR

enum QOpenGLTexture::MipMapGeneration

This enum defines the options to control mipmap generation.

ConstantValueDescription
QOpenGLTexture::GenerateMipMaps0Mipmaps should be generated
QOpenGLTexture::DontGenerateMipMaps1Mipmaps should not be generated

enum QOpenGLTexture::PixelFormat

This enum defines the possible client-side pixel formats for a pixel transfer operation.

ConstantValueDescription
QOpenGLTexture::NoSourceFormat0Equivalent to GL_NONE
QOpenGLTexture::Red0x1903Equivalent to GL_RED
QOpenGLTexture::RG0x8227Equivalent to GL_RG
QOpenGLTexture::RGB0x1907Equivalent to GL_RGB
QOpenGLTexture::BGR0x80E0Equivalent to GL_BGR
QOpenGLTexture::RGBA0x1908Equivalent to GL_RGBA
QOpenGLTexture::BGRA0x80E1Equivalent to GL_BGRA
QOpenGLTexture::Red_Integer0x8D94Equivalent to GL_RED_INTEGER
QOpenGLTexture::RG_Integer0x8228Equivalent to GL_RG_INTEGER
QOpenGLTexture::RGB_Integer0x8D98Equivalent to GL_RGB_INTEGER
QOpenGLTexture::BGR_Integer0x8D9AEquivalent to GL_BGR_INTEGER
QOpenGLTexture::RGBA_Integer0x8D99Equivalent to GL_RGBA_INTEGER
QOpenGLTexture::BGRA_Integer0x8D9BEquivalent to GL_BGRA_INTEGER
QOpenGLTexture::Stencil0x1901Equivalent to GL_STENCIL_INDEX. Introduced in Qt 5.4
QOpenGLTexture::Depth0x1902Equivalent to GL_DEPTH_COMPONENT
QOpenGLTexture::DepthStencil0x84F9Equivalent to GL_DEPTH_STENCIL
QOpenGLTexture::Alpha0x1906Equivalent to GL_ALPHA (OpenGL ES 2 only)
QOpenGLTexture::Luminance0x1909Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
QOpenGLTexture::LuminanceAlpha0x190AEquivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)

enum QOpenGLTexture::PixelType

This enum defines the possible pixel data types for a pixel transfer operation

ConstantValueDescription
QOpenGLTexture::NoPixelType0Equivalent to GL_NONE
QOpenGLTexture::Int80x1400Equivalent to GL_BYTE
QOpenGLTexture::UInt80x1401Equivalent to GL_UNSIGNED_BYTE
QOpenGLTexture::Int160x1402Equivalent to GL_SHORT
QOpenGLTexture::UInt160x1403Equivalent to GL_UNSIGNED_SHORT
QOpenGLTexture::Int320x1404Equivalent to GL_INT
QOpenGLTexture::UInt320x1405Equivalent to GL_UNSIGNED_INT
QOpenGLTexture::Float160x140BEquivalent to GL_HALF_FLOAT
QOpenGLTexture::Float16OES0x8D61Equivalent to GL_HALF_FLOAT_OES
QOpenGLTexture::Float320x1406Equivalent to GL_FLOAT
QOpenGLTexture::UInt32_RGB9_E50x8C3EEquivalent to GL_UNSIGNED_INT_5_9_9_9_REV
QOpenGLTexture::UInt32_RG11B10F0x8C3BEquivalent to GL_UNSIGNED_INT_10F_11F_11F_REV
QOpenGLTexture::UInt8_RG3B20x8032Equivalent to GL_UNSIGNED_BYTE_3_3_2
QOpenGLTexture::UInt8_RG3B2_Rev0x8362Equivalent to GL_UNSIGNED_BYTE_2_3_3_REV
QOpenGLTexture::UInt16_RGB5A10x8034Equivalent to GL_UNSIGNED_SHORT_5_5_5_1
QOpenGLTexture::UInt16_RGB5A1_Rev0x8366Equivalent to GL_UNSIGNED_SHORT_1_5_5_5_REV
QOpenGLTexture::UInt16_R5G6B50x8363Equivalent to GL_UNSIGNED_SHORT_5_6_5
QOpenGLTexture::UInt16_R5G6B5_Rev0x8364Equivalent to GL_UNSIGNED_SHORT_5_6_5_REV
QOpenGLTexture::UInt16_RGBA40x8033Equivalent to GL_UNSIGNED_SHORT_4_4_4_4
QOpenGLTexture::UInt16_RGBA4_Rev0x8365Equivalent to GL_UNSIGNED_SHORT_4_4_4_4_REV
QOpenGLTexture::UInt32_RGBA80x8035Equivalent to GL_UNSIGNED_INT_8_8_8_8
QOpenGLTexture::UInt32_RGBA8_Rev0x8367Equivalent to GL_UNSIGNED_INT_8_8_8_8_REV
QOpenGLTexture::UInt32_RGB10A20x8036Equivalent to GL_UNSIGNED_INT_10_10_10_2
QOpenGLTexture::UInt32_RGB10A2_Rev0x8368Equivalent to GL_UNSIGNED_INT_2_10_10_10_REV
QOpenGLTexture::UInt32_D24S80x84FAEquivalent to GL_UNSIGNED_INT_24_8. Introduced in Qt 5.4
QOpenGLTexture::Float32_D32_UInt32_S8_X240x8DADEquivalent to GL_FLOAT_32_UNSIGNED_INT_24_8_REV. Introduced in Qt 5.4

enum QOpenGLTexture::SwizzleComponent

This enum defines the texture color components that can be assigned a swizzle mask.

ConstantValueDescription
QOpenGLTexture::SwizzleRed0x8E42The red component. Equivalent to GL_TEXTURE_SWIZZLE_R
QOpenGLTexture::SwizzleGreen0x8E43The green component. Equivalent to GL_TEXTURE_SWIZZLE_G
QOpenGLTexture::SwizzleBlue0x8E44The blue component. Equivalent to GL_TEXTURE_SWIZZLE_B
QOpenGLTexture::SwizzleAlpha0x8E45The alpha component. Equivalent to GL_TEXTURE_SWIZZLE_A

enum QOpenGLTexture::SwizzleValue

This enum defines the possible mask values for texture swizzling.

ConstantValueDescription
QOpenGLTexture::RedValue0x1903Maps the component to the red channel. Equivalent to GL_RED
QOpenGLTexture::GreenValue0x1904Maps the component to the green channel. Equivalent to GL_GREEN
QOpenGLTexture::BlueValue0x1905Maps the component to the blue channel. Equivalent to GL_BLUE
QOpenGLTexture::AlphaValue0x1906Maps the component to the alpha channel. Equivalent to GL_ALPHA
QOpenGLTexture::ZeroValue0Maps the component to a fixed value of 0. Equivalent to GL_ZERO
QOpenGLTexture::OneValue1Maps the component to a fixed value of 1. Equivalent to GL_ONE

enum QOpenGLTexture::Target

This enum defines the texture target of a QOpenGLTexture object. For more information on creating array textures, see Array Texture.

ConstantValueDescription
QOpenGLTexture::Target1D0x0DE0A 1-dimensional texture. Equivalent to GL_TEXTURE_1D.
QOpenGLTexture::Target1DArray0x8C18An array of 1-dimensional textures. Equivalent to GL_TEXTURE_1D_ARRAY
QOpenGLTexture::Target2D0x0DE1A 2-dimensional texture. Equivalent to GL_TEXTURE_2D
QOpenGLTexture::Target2DArray0x8C1AAn array of 2-dimensional textures. Equivalent to GL_TEXTURE_2D_ARRAY
QOpenGLTexture::Target3D0x806FA 3-dimensional texture. Equivalent to GL_TEXTURE_3D
QOpenGLTexture::TargetCubeMap0x8513A cubemap texture. Equivalent to GL_TEXTURE_CUBE_MAP
QOpenGLTexture::TargetCubeMapArray0x9009An array of cubemap textures. Equivalent to GL_TEXTURE_CUBE_MAP_ARRAY
QOpenGLTexture::Target2DMultisample0x9100A 2-dimensional texture with multisample support. Equivalent to GL_TEXTURE_2D_MULTISAMPLE
QOpenGLTexture::Target2DMultisampleArray0x9102An array of 2-dimensional textures with multisample support. Equivalent to GL_TEXTURE_2D_MULTISAMPLE_ARRAY
QOpenGLTexture::TargetRectangle0x84F5A rectangular 2-dimensional texture. Equivalent to GL_TEXTURE_RECTANGLE
QOpenGLTexture::TargetBuffer0x8C2AA texture with data from an OpenGL buffer object. Equivalent to GL_TEXTURE_BUFFER

enum QOpenGLTexture::TextureFormat

This enum defines the possible texture formats. Depending upon your OpenGL implementation only a subset of these may be supported.

ConstantValueDescription
QOpenGLTexture::NoFormat0Equivalent to GL_NONE
QOpenGLTexture::R8_UNorm0x8229Equivalent to GL_R8
QOpenGLTexture::RG8_UNorm0x822BEquivalent to GL_RG8
QOpenGLTexture::RGB8_UNorm0x8051Equivalent to GL_RGB8
QOpenGLTexture::RGBA8_UNorm0x8058Equivalent to GL_RGBA8
QOpenGLTexture::R16_UNorm0x822AEquivalent to GL_R16
QOpenGLTexture::RG16_UNorm0x822CEquivalent to GL_RG16
QOpenGLTexture::RGB16_UNorm0x8054Equivalent to GL_RGB16
QOpenGLTexture::RGBA16_UNorm0x805BEquivalent to GL_RGBA16
QOpenGLTexture::R8_SNorm0x8F94Equivalent to GL_R8_SNORM
QOpenGLTexture::RG8_SNorm0x8F95Equivalent to GL_RG8_SNORM
QOpenGLTexture::RGB8_SNorm0x8F96Equivalent to GL_RGB8_SNORM
QOpenGLTexture::RGBA8_SNorm0x8F97Equivalent to GL_RGBA8_SNORM
QOpenGLTexture::R16_SNorm0x8F98Equivalent to GL_R16_SNORM
QOpenGLTexture::RG16_SNorm0x8F99Equivalent to GL_RG16_SNORM
QOpenGLTexture::RGB16_SNorm0x8F9AEquivalent to GL_RGB16_SNORM
QOpenGLTexture::RGBA16_SNorm0x8F9BEquivalent to GL_RGBA16_SNORM
QOpenGLTexture::R8U0x8232Equivalent to GL_R8UI
QOpenGLTexture::RG8U0x8238Equivalent to GL_RG8UI
QOpenGLTexture::RGB8U0x8D7DEquivalent to GL_RGB8UI
QOpenGLTexture::RGBA8U0x8D7CEquivalent to GL_RGBA8UI
QOpenGLTexture::R16U0x8234Equivalent to GL_R16UI
QOpenGLTexture::RG16U0x823AEquivalent to GL_RG16UI
QOpenGLTexture::RGB16U0x8D77Equivalent to GL_RGB16UI
QOpenGLTexture::RGBA16U0x8D76Equivalent to GL_RGBA16UI
QOpenGLTexture::R32U0x8236Equivalent to GL_R32UI
QOpenGLTexture::RG32U0x823CEquivalent to GL_RG32UI
QOpenGLTexture::RGB32U0x8D71Equivalent to GL_RGB32UI
QOpenGLTexture::RGBA32U0x8D70Equivalent to GL_RGBA32UI
QOpenGLTexture::R8I0x8231Equivalent to GL_R8I
QOpenGLTexture::RG8I0x8237Equivalent to GL_RG8I
QOpenGLTexture::RGB8I0x8D8FEquivalent to GL_RGB8I
QOpenGLTexture::RGBA8I0x8D8EEquivalent to GL_RGBA8I
QOpenGLTexture::R16I0x8233Equivalent to GL_R16I
QOpenGLTexture::RG16I0x8239Equivalent to GL_RG16I
QOpenGLTexture::RGB16I0x8D89Equivalent to GL_RGB16I
QOpenGLTexture::RGBA16I0x8D88Equivalent to GL_RGBA16I
QOpenGLTexture::R32I0x8235Equivalent to GL_R32I
QOpenGLTexture::RG32I0x823BEquivalent to GL_RG32I
QOpenGLTexture::RGB32I0x8D83Equivalent to GL_RGB32I
QOpenGLTexture::RGBA32I0x8D82Equivalent to GL_RGBA32I
QOpenGLTexture::R16F0x822DEquivalent to GL_R16F
QOpenGLTexture::RG16F0x822FEquivalent to GL_RG16F
QOpenGLTexture::RGB16F0x881BEquivalent to GL_RGB16F
QOpenGLTexture::RGBA16F0x881AEquivalent to GL_RGBA16F
QOpenGLTexture::R32F0x822EEquivalent to GL_R32F
QOpenGLTexture::RG32F0x8230Equivalent to GL_RG32F
QOpenGLTexture::RGB32F0x8815Equivalent to GL_RGB32F
QOpenGLTexture::RGBA32F0x8814Equivalent to GL_RGBA32F
QOpenGLTexture::RGB9E50x8C3DEquivalent to GL_RGB9_E5
QOpenGLTexture::RG11B10F0x8C3AEquivalent to GL_R11F_G11F_B10F
QOpenGLTexture::RG3B20x2A10Equivalent to GL_R3_G3_B2
QOpenGLTexture::R5G6B50x8D62Equivalent to GL_RGB565
QOpenGLTexture::RGB5A10x8057Equivalent to GL_RGB5_A1
QOpenGLTexture::RGBA40x8056Equivalent to GL_RGBA4
QOpenGLTexture::RGB10A20x906FEquivalent to GL_RGB10_A2UI
QOpenGLTexture::D160x81A5Equivalent to GL_DEPTH_COMPONENT16
QOpenGLTexture::D240x81A6Equivalent to GL_DEPTH_COMPONENT24
QOpenGLTexture::D24S80x88F0Equivalent to GL_DEPTH24_STENCIL8
QOpenGLTexture::D320x81A7Equivalent to GL_DEPTH_COMPONENT32
QOpenGLTexture::D32F0x8CACEquivalent to GL_DEPTH_COMPONENT32F
QOpenGLTexture::D32FS8X240x8CADEquivalent to GL_DEPTH32F_STENCIL8
QOpenGLTexture::S80x8D48Equivalent to GL_STENCIL_INDEX8. Introduced in Qt 5.4
QOpenGLTexture::RGB_DXT10x83F0Equivalent to GL_COMPRESSED_RGB_S3TC_DXT1_EXT
QOpenGLTexture::RGBA_DXT10x83F1Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
QOpenGLTexture::RGBA_DXT30x83F2Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
QOpenGLTexture::RGBA_DXT50x83F3Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
QOpenGLTexture::R_ATI1N_UNorm0x8DBBEquivalent to GL_COMPRESSED_RED_RGTC1
QOpenGLTexture::R_ATI1N_SNorm0x8DBCEquivalent to GL_COMPRESSED_SIGNED_RED_RGTC1
QOpenGLTexture::RG_ATI2N_UNorm0x8DBDEquivalent to GL_COMPRESSED_RG_RGTC2
QOpenGLTexture::RG_ATI2N_SNorm0x8DBEEquivalent to GL_COMPRESSED_SIGNED_RG_RGTC2
QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT0x8E8FEquivalent to GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
QOpenGLTexture::RGB_BP_SIGNED_FLOAT0x8E8EEquivalent to GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
QOpenGLTexture::RGB_BP_UNorm0x8E8CEquivalent to GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
QOpenGLTexture::R11_EAC_UNorm0x9270Equivalent to GL_COMPRESSED_R11_EAC
QOpenGLTexture::R11_EAC_SNorm0x9271Equivalent to GL_COMPRESSED_SIGNED_R11_EAC
QOpenGLTexture::RG11_EAC_UNorm0x9272Equivalent to GL_COMPRESSED_RG11_EAC
QOpenGLTexture::RG11_EAC_SNorm0x9273Equivalent to GL_COMPRESSED_SIGNED_RG11_EAC
QOpenGLTexture::RGB8_ETC20x9274Equivalent to GL_COMPRESSED_RGB8_ETC2
QOpenGLTexture::SRGB8_ETC20x9275Equivalent to GL_COMPRESSED_SRGB8_ETC2
QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC20x9276Equivalent to GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC20x9277Equivalent to GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
QOpenGLTexture::RGBA8_ETC2_EAC0x9278Equivalent to GL_COMPRESSED_RGBA8_ETC2_EAC
QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC0x9279Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
QOpenGLTexture::RGB8_ETC10x8D64Equivalent to GL_ETC1_RGB8_OES
QOpenGLTexture::RGBA_ASTC_4x40x93B0Equivalent to GL_COMPRESSED_RGBA_ASTC_4x4_KHR
QOpenGLTexture::RGBA_ASTC_5x40x93B1Equivalent to GL_COMPRESSED_RGBA_ASTC_5x4_KHR
QOpenGLTexture::RGBA_ASTC_5x50x93B2Equivalent to GL_COMPRESSED_RGBA_ASTC_5x5_KHR
QOpenGLTexture::RGBA_ASTC_6x50x93B3Equivalent to GL_COMPRESSED_RGBA_ASTC_6x5_KHR
QOpenGLTexture::RGBA_ASTC_6x60x93B4Equivalent to GL_COMPRESSED_RGBA_ASTC_6x6_KHR
QOpenGLTexture::RGBA_ASTC_8x50x93B5Equivalent to GL_COMPRESSED_RGBA_ASTC_8x5_KHR
QOpenGLTexture::RGBA_ASTC_8x60x93B6Equivalent to GL_COMPRESSED_RGBA_ASTC_8x6_KHR
QOpenGLTexture::RGBA_ASTC_8x80x93B7Equivalent to GL_COMPRESSED_RGBA_ASTC_8x8_KHR
QOpenGLTexture::RGBA_ASTC_10x50x93B8Equivalent to GL_COMPRESSED_RGBA_ASTC_10x5_KHR
QOpenGLTexture::RGBA_ASTC_10x60x93B9Equivalent to GL_COMPRESSED_RGBA_ASTC_10x6_KHR
QOpenGLTexture::RGBA_ASTC_10x80x93BAEquivalent to GL_COMPRESSED_RGBA_ASTC_10x8_KHR
QOpenGLTexture::RGBA_ASTC_10x100x93BBEquivalent to GL_COMPRESSED_RGBA_ASTC_10x10_KHR
QOpenGLTexture::RGBA_ASTC_12x100x93BCEquivalent to GL_COMPRESSED_RGBA_ASTC_12x10_KHR
QOpenGLTexture::RGBA_ASTC_12x120x93BDEquivalent to GL_COMPRESSED_RGBA_ASTC_12x12_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_4x40x93D0Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_5x40x93D1Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_5x50x93D2Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_6x50x93D3Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_6x60x93D4Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x50x93D5Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x60x93D6Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x80x93D7Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x50x93D8Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x60x93D9Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x80x93DAEquivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x100x93DBEquivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_12x100x93DCEquivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_12x120x93DDEquivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
QOpenGLTexture::SRGB80x8C41Equivalent to GL_SRGB8
QOpenGLTexture::SRGB8_Alpha80x8C43Equivalent to GL_SRGB8_ALPHA8
QOpenGLTexture::SRGB_DXT10x8C4CEquivalent to GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
QOpenGLTexture::SRGB_Alpha_DXT10x8C4DEquivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
QOpenGLTexture::SRGB_Alpha_DXT30x8C4EEquivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
QOpenGLTexture::SRGB_Alpha_DXT50x8C4FEquivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
QOpenGLTexture::SRGB_BP_UNorm0x8E8DEquivalent to GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
QOpenGLTexture::DepthFormat0x1902Equivalent to GL_DEPTH_COMPONENT (only OpenGL ES 3 or ES 2 with OES_depth_texture)
QOpenGLTexture::AlphaFormat0x1906Equivalent to GL_ALPHA (OpenGL ES 2 only)
QOpenGLTexture::RGBFormat0x1907Equivalent to GL_RGB (OpenGL ES 2 only)
QOpenGLTexture::RGBAFormat0x1908Equivalent to GL_RGBA (OpenGL ES 2 only)
QOpenGLTexture::LuminanceFormat0x1909Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
QOpenGLTexture::LuminanceAlphaFormat0x190AEquivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)

enum QOpenGLTexture::TextureUnitReset

This enum defines options ot control texture unit activation.

ConstantValueDescription
QOpenGLTexture::ResetTextureUnit0The previous active texture unit will be reset
QOpenGLTexture::DontResetTextureUnit1The previous active texture unit will not be rest

enum QOpenGLTexture::WrapMode

This enum defines the possible texture coordinate wrapping modes.

ConstantValueDescription
QOpenGLTexture::Repeat0x2901Texture coordinate is repeated. Equivalent to GL_REPEAT
QOpenGLTexture::MirroredRepeat0x8370Texture coordinate is reflected about 0 and 1. Equivalent to GL_MIRRORED_REPEAT
QOpenGLTexture::ClampToEdge0x812FClamps the texture coordinates to [0,1]. Equivalent to GL_CLAMP_TO_EDGE
QOpenGLTexture::ClampToBorder0x812DAs for ClampToEdge but also blends samples at 0 and 1 with a fixed border color. Equivalent to GL_CLAMP_TO_BORDER

Member Function Documentation

[explicit] QOpenGLTexture::QOpenGLTexture(QOpenGLTexture::Target target)

Creates a QOpenGLTexture object that can later be bound to target.

This does not create the underlying OpenGL texture object. Therefore, construction using this constructor does not require a valid current OpenGL context.

[explicit] QOpenGLTexture::QOpenGLTexture(const QImage &image, QOpenGLTexture::MipMapGeneration genMipMaps = GenerateMipMaps)

Creates a QOpenGLTexture object that can later be bound to the 2D texture target and contains the pixel data contained in image. If you wish to have a chain of mipmaps generated then set genMipMaps to true (this is the default).

This does create the underlying OpenGL texture object. Therefore, construction using this constructor does require a valid current OpenGL context.

Note: image is automatically converted to QImage::Format_RGBA8888 which may have performance implications for large images with a different format.

void QOpenGLTexture::allocateStorage()

Allocates server-side storage for this texture object taking into account, the format, dimensions, mipmap levels, array layers and cubemap faces.

Once storage has been allocated it is no longer possible to change these properties.

If supported QOpenGLTexture makes use of immutable texture storage.

Once storage has been allocated for the texture then pixel data can be uploaded via one of the setData() overloads.

Note: If immutable texture storage is not available, then a default pixel format and pixel type will be used to create the mutable storage. You can use the other allocateStorage() overload to specify exactly the pixel format and the pixel type to use when allocating mutable storage; this is particularly useful under certain OpenGL ES implementations (notably, OpenGL ES 2), where the pixel format and the pixel type used at allocation time must perfectly match the format and the type passed to any subsequent setData() call.

See also isStorageAllocated() and setData().

void QOpenGLTexture::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)

Allocates server-side storage for this texture object taking into account, the format, dimensions, mipmap levels, array layers and cubemap faces.

Once storage has been allocated it is no longer possible to change these properties.

If supported QOpenGLTexture makes use of immutable texture storage. However, if immutable texture storage is not available, then the specified pixelFormat and pixelType will be used to allocate mutable storage; note that in certain OpenGL implementations (notably, OpenGL ES 2) they must perfectly match the format and the type passed to any subsequent setData() call.

Once storage has been allocated for the texture then pixel data can be uploaded via one of the setData() overloads.

See also isStorageAllocated() and setData().

void QOpenGLTexture::bind()

Binds this texture to the currently active texture unit ready for rendering. Note that you do not need to bind QOpenGLTexture objects in order to modify them as the implementation makes use of the EXT_direct_state_access extension where available and simulates it where it is not.

See also release().

void QOpenGLTexture::bind(uint unit, QOpenGLTexture::TextureUnitReset reset = DontResetTextureUnit)

Binds this texture to texture unit unit ready for rendering. Note that you do not need to bind QOpenGLTexture objects in order to modify them as the implementation makes use of the EXT_direct_state_access extension where available and simulates it where it is not.

If parameter reset is true then this function will restore the active unit to the texture unit that was active upon entry.

See also release().

QColor QOpenGLTexture::borderColor() const

Returns the borderColor of this texture.

See also setBorderColor().

void QOpenGLTexture::borderColor(float *border) const

Writes the texture border color into the first four elements of the array pointed to by border.

See also setBorderColor().

void QOpenGLTexture::borderColor(int *border) const

Writes the texture border color into the first four elements of the array pointed to by border.

This is an overloaded function.

void QOpenGLTexture::borderColor(unsigned int *border) const

Writes the texture border color into the first four elements of the array pointed to by border.

This is an overloaded function.

[static] GLuint QOpenGLTexture::boundTextureId(QOpenGLTexture::BindingTarget target)

Returns the textureId of the texture that is bound to the target of the currently active texture unit.

[static] GLuint QOpenGLTexture::boundTextureId(uint unit, QOpenGLTexture::BindingTarget target)

Returns the textureId of the texture that is bound to the target of the texture unit unit.

QOpenGLTexture::ComparisonFunction QOpenGLTexture::comparisonFunction() const

Returns the texture comparison operator set on this texture. By default, a texture has a CompareLessEqual comparison function.

See also setComparisonFunction().

QOpenGLTexture::ComparisonMode QOpenGLTexture::comparisonMode() const

Returns the texture comparison mode set on this texture. By default, a texture has a CompareNone comparison mode (i.e. comparisons are disabled).

See also setComparisonMode().

bool QOpenGLTexture::create()

Creates the underlying OpenGL texture object. This requires a current valid OpenGL context. If the texture object already exists, this function does nothing.

Once the texture object is created you can obtain the object name from the textureId() function. This may be useful if you wish to make some raw OpenGL calls related to this texture.

Normally it should not be necessary to call this function directly as all functions that set properties of the texture object implicitly call create() on your behalf.

Returns true if the creation succeeded, otherwise returns false.

See also destroy(), isCreated(), and textureId().

QOpenGLTexture *QOpenGLTexture::createTextureView(QOpenGLTexture::Target target, QOpenGLTexture::TextureFormat viewFormat, int minimumMipmapLevel, int maximumMipmapLevel, int minimumLayer, int maximumLayer) const

Attempts to create a texture view onto this texture. A texture view is somewhat analogous to a view in SQL in that it presents a restricted or reinterpreted view of the original data. Texture views do not allocate any more server-side storage, instead relying on the storage buffer of the source texture.

Texture views are only available when using immutable storage. For more information on texture views see http://www.opengl.org/wiki/Texture_Storage#Texture_views.

The target argument specifies the target to use for the view. Only some targets can be used depending upon the target of the original target. For e.g. a view onto a Target1DArray texture can specify either Target1DArray or Target1D but for the latter the number of array layers specified with minimumLayer and maximumLayer must be exactly 1.

Simpliar constraints apply for the viewFormat. See the above link and the specification for more details.

The minimumMipmapLevel, maximumMipmapLevel, minimumLayer, and maximumLayer arguments serve to restrict the parts of the texture accessible by the texture view.

If creation of the texture view fails this function will return 0. If the function succeeds it will return a pointer to a new QOpenGLTexture object that will return true from its isTextureView() function.

See also isTextureView().

int QOpenGLTexture::depth() const

Returns the depth of a 3D texture.

See also width(), height(), and setSize().

QOpenGLTexture::DepthStencilMode QOpenGLTexture::depthStencilMode() const

Returns the depth stencil mode for textures using a combined depth/stencil format.

See also setDepthStencilMode().

void QOpenGLTexture::destroy()

Destroys the underlying OpenGL texture object. This requires a current valid OpenGL context.

See also create(), isCreated(), and textureId().

int QOpenGLTexture::faces() const

Returns the number of faces for this texture. For cubemap and cubemap array type targets this will be 6.

For non-cubemap type targets this will return 1.

QOpenGLTexture::TextureFormat QOpenGLTexture::format() const

Returns the format of this texture object.

See also setFormat().

void QOpenGLTexture::generateMipMaps()

Generates mipmaps for this texture object from mipmap level 0. If you are using a texture target and filtering option that requires mipmaps and you have disabled automatic mipmap generation then you need to call this function or the overload to create the mipmap chain.

Note: Mipmap generation is not supported for compressed textures with OpenGL ES.

See also setAutoMipMapGenerationEnabled(), setMipLevels(), and mipLevels().

void QOpenGLTexture::generateMipMaps(int baseLevel, bool resetBaseLevel = true)

Generates mipmaps for this texture object from mipmap level baseLevel. If you are using a texture target and filtering option that requires mipmaps and you have disabled automatic mipmap generation then you need to call this function or the overload to create the mipmap chain.

The generation of mipmaps to above baseLevel is achieved by setting the mipmap base level to baseLevel and then generating the mipmap chain. If resetBaseLevel is true, then the baseLevel of the texture will be reset to its previous value.

See also setAutoMipMapGenerationEnabled(), setMipLevels(), and mipLevels().

[static] bool QOpenGLTexture::hasFeature(QOpenGLTexture::Feature feature)

Returns true if your OpenGL implementation and version supports the texture feature feature.

int QOpenGLTexture::height() const

Returns the height of a 2D or 3D texture.

See also width(), depth(), and setSize().

bool QOpenGLTexture::isAutoMipMapGenerationEnabled() const

Returns whether auto mipmap generation is enabled for this texture object.

See also setAutoMipMapGenerationEnabled() and generateMipMaps().

bool QOpenGLTexture::isBound() const

Returns true if this texture is bound to the corresponding target of the currently active texture unit.

See also bind() and release().

bool QOpenGLTexture::isBound(uint unit)

Returns true if this texture is bound to the corresponding target of texture unit unit.

See also bind() and release().

bool QOpenGLTexture::isCreated() const

Returns true if the underlying OpenGL texture object has been created.

See also create(), destroy(), and textureId().

bool QOpenGLTexture::isFixedSamplePositions() const

Returns whether this texture uses a fixed pattern of multisample samples. If storage has not yet been allocated for this texture then this function returns the requested fixed sample position setting.

For texture targets that do not support multisampling this will return true.

See also setFixedSamplePositions() and isStorageAllocated().

bool QOpenGLTexture::isStorageAllocated() const

Returns true if server-side storage for this texture as been allocated.

The texture format, dimensions, mipmap levels and array layers cannot be altered once storage ihas been allocated.

See also allocateStorage(), setSize(), setMipLevels(), setLayers(), and setFormat().

bool QOpenGLTexture::isTextureView() const

Returns true if this texture object is actually a view onto another texture object.

See also createTextureView().

int QOpenGLTexture::layers() const

Returns the number of array layers for this texture. If storage has not yet been allocated for this texture then this function returns the requested number of array layers.

For texture targets that do not support array layers this will return 1.

See also setLayers() and isStorageAllocated().

QPair<float, float> QOpenGLTexture::levelOfDetailRange() const

Returns the minimum and maximum level of detail parameters.

See also setLevelOfDetailRange(), minimumLevelOfDetail(), and maximumLevelOfDetail().

float QOpenGLTexture::levelofDetailBias() const

Returns the level of detail bias parameter.

See also setLevelofDetailBias().

QOpenGLTexture::Filter QOpenGLTexture::magnificationFilter() const

Returns the magnification filter.

See also setMagnificationFilter().

float QOpenGLTexture::maximumAnisotropy() const

Returns the maximum level of anisotropy to be accounted for when performing texture lookups. This requires the GL_EXT_texture_filter_anisotropic extension.

See also setMaximumAnisotropy().

float QOpenGLTexture::maximumLevelOfDetail() const

Returns the maximum level of detail parameter.

See also setMaximumLevelOfDetail(), minimumLevelOfDetail(), and levelOfDetailRange().

int QOpenGLTexture::maximumMipLevels() const

Returns the maximum number of mipmap levels that this texture can have given the current dimensions.

See also setMipLevels(), mipLevels(), and setSize().

QPair<QOpenGLTexture::Filter, QOpenGLTexture::Filter> QOpenGLTexture::minMagFilters() const

Returns the current minification and magnification filters.

See also setMinMagFilters().

QOpenGLTexture::Filter QOpenGLTexture::minificationFilter() const

Returns the minification filter.

See also setMinificationFilter().

float QOpenGLTexture::minimumLevelOfDetail() const

Returns the minimum level of detail parameter.

See also setMinimumLevelOfDetail(), maximumLevelOfDetail(), and levelOfDetailRange().

int QOpenGLTexture::mipBaseLevel() const

Returns the mipmap base level used for all texture lookups with this texture. The default is 0.

See also setMipBaseLevel(), mipMaxLevel(), and mipLevelRange().

QPair<int, int> QOpenGLTexture::mipLevelRange() const

Returns the range of mipmap levels that can be used for texture lookups with this texture.

See also setMipLevelRange(), mipBaseLevel(), and mipMaxLevel().

int QOpenGLTexture::mipLevels() const

Returns the number of mipmap levels for this texture. If storage has not yet been allocated for this texture it returns the requested number of mipmap levels.

See also setMipLevels(), maximumMipLevels(), and isStorageAllocated().

int QOpenGLTexture::mipMaxLevel() const

Returns the mipmap maximum level used for all texture lookups with this texture.

See also setMipMaxLevel(), mipBaseLevel(), and mipLevelRange().

void QOpenGLTexture::release()

Unbinds this texture from the currently active texture unit.

See also bind().

void QOpenGLTexture::release(uint unit, QOpenGLTexture::TextureUnitReset reset = DontResetTextureUnit)

Unbinds this texture from texture unit unit.

If parameter reset is true then this function will restore the active unit to the texture unit that was active upon entry.

int QOpenGLTexture::samples() const

Returns the number of multisample sample points for this texture. If storage has not yet been allocated for this texture then this function returns the requested number of samples.

For texture targets that do not support multisampling this will return 0.

See also setSamples() and isStorageAllocated().

void QOpenGLTexture::setAutoMipMapGenerationEnabled(bool enabled)

If enabled is true, enables automatic mipmap generation for this texture object to occur whenever the level 0 mipmap data is set via setData().

The automatic mipmap generation is enabled by default.

Note: Mipmap generation is not supported for compressed textures with OpenGL ES 2.0.

See also isAutoMipMapGenerationEnabled() and generateMipMaps().

void QOpenGLTexture::setBorderColor(const QColor &color)

Sets the border color of the texture to color.

Note: This function has no effect on Mac and Qt built for OpenGL ES 2.

See also borderColor().

void QOpenGLTexture::setBorderColor(float r, float g, float b, float a)

Sets the color red to r, green to g, blue to b, and a to the alpha value.

This is an overloaded function.

void QOpenGLTexture::setBorderColor(int r, int g, int b, int a)

Sets the color red to r, green to g, blue to b, and the alpha value to a.

This is an overloaded function.

void QOpenGLTexture::setBorderColor(uint r, uint g, uint b, uint a)

Sets the color red to r, green to g, blue to b, and the alpha value to a.

This is an overloaded function.

void QOpenGLTexture::setComparisonFunction(QOpenGLTexture::ComparisonFunction function)

Sets the texture comparison function on this texture to function. The texture comparison function is used by shadow samplers when sampling a depth texture.

See also comparisonFunction().

void QOpenGLTexture::setComparisonMode(QOpenGLTexture::ComparisonMode mode)

Sets the texture comparison mode on this texture to mode. The texture comparison mode is used by shadow samplers when sampling a depth texture.

See also comparisonMode().

void QOpenGLTexture::setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

Uploads compressed pixel data to mipLevel, array layer, and cubeFace. The pixel transfer can optionally be controlled with options. The dataSize argument should specify the size of the data pointed to by data.

If not using a compressed format() then you should use setData() instead of this function.

void QOpenGLTexture::setCompressedData(int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, int dataSize, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

Parameter layerCount is the number of layers in a texture array that are being uploaded/populated by this call.

void QOpenGLTexture::setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

Uploads pixel data for this texture object mipLevel, array layer, and cubeFace. Storage must have been allocated before uploading pixel data. Some overloads of setData() will set appropriate dimensions, mipmap levels, and array layers and then allocate storage for you if they have enough information to do so. This will be noted in the function documentation.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

If using a compressed format() then you should use setCompressedData() instead of this function.

See also setCompressedData().

void QOpenGLTexture::setData(const QImage &image, QOpenGLTexture::MipMapGeneration genMipMaps = GenerateMipMaps)

This overload of setData() will allocate storage for you. The pixel data is contained in image. Mipmaps are generated by default. Set genMipMaps to DontGenerateMipMaps to turn off mipmap generation.

Note: image is automatically converted to QImage::Format_RGBA8888 which may have performance implications for large images with a different format.

This is an overloaded function.

void QOpenGLTexture::setData(QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setData(int mipLevel, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setData(int mipLevel, int layer, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

void QOpenGLTexture::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

Parameter layerCount is the number of layers in a texture array that are being uploaded/populated by this call.

void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

This overload is to be used to update a part of the texture. Parameters xOffset, yOffset, zOffset specify the texel offsets within the texture. Parameters width, height and depth specify the dimensions of the sub image.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

This overload is to be used to update a part of the texture. Parameters xOffset, yOffset, zOffset specify the texel offsets within the texture. Parameters width, height and depth specify the dimensions of the sub image. The mip map level the sub image we want to update is specified with mipLevel.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

This overload is to be used to update a part of the texture. Parameters xOffset, yOffset, zOffset specify the texel offsets within the texture. Parameters width, height and depth specify the dimensions of the sub image. The mip map level and layerof the sub image we want to update are specified with mipLevel and layer.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::CubeMapFace face, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

This overload is to be used to update a part of the texture. Parameters xOffset, yOffset, zOffset specify the texel offsets within the texture. Parameters width, height and depth specify the dimensions of the sub image.The mip map level, layer and cube map face of the sub image we want to update are specified with mipLevel, layer and face.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

void QOpenGLTexture::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, int mipLevel, int layer, QOpenGLTexture::CubeMapFace face, int layerCount, QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, const void *data, const QOpenGLPixelTransferOptions *const options = nullptr)

This is an overloaded function.

This overload is to be used to update a part of the texture. Parameters xOffset, yOffset, zOffset specify the texel offsets within the texture. Parameters width, height and depth specify the dimensions of the sub image.The mip map level, starting layer, cube map face and number of layers of the sub image we want to update are specified with mipLevel, layer, face and layerCount.

The structure of the pixel data pointed to by data is specified by sourceFormat and sourceType. The pixel data upload can optionally be controlled by options.

void QOpenGLTexture::setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode)

If using a texture that has a combined depth/stencil format this function sets which component of the texture is accessed to mode.

When the parameter is set to DepthMode, then accessing it from the shader will access the depth component as a single float, as normal. But when the parameter is set to StencilMode, the shader will access the stencil component.

Note: This function has no effect on Mac and Qt built for OpenGL ES 2.

See also depthStencilMode().

void QOpenGLTexture::setFixedSamplePositions(bool fixed)

Sets whether the sample positions and number of samples used with a multisample capable texture target to fixed. If set to true the sample positions and number of samples used are the same for all texels in the image and will not depend upon the image size or internal format. This function should be called before storage is allocated for the texture.

For targets that do not support multisampling this function has no effect.

The default value is true.

See also isFixedSamplePositions() and isStorageAllocated().

void QOpenGLTexture::setFormat(QOpenGLTexture::TextureFormat format)

Sets the format of this texture object to format. This function must be called before texture storage is allocated.

Note that all formats may not be supported. The exact set of supported formats is dependent upon your OpenGL implementation and version.

See also format() and allocateStorage().

void QOpenGLTexture::setLayers(int layers)

Sets the number of array layers to allocate storage for. This function should be called before storage is allocated for the texture.

For targets that do not support array layers this function has no effect.

See also layers() and isStorageAllocated().

void QOpenGLTexture::setLevelOfDetailRange(float min, float max)

Sets the minimum level of detail parameters to min and the maximum level to max.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also levelOfDetailRange(), setMinimumLevelOfDetail(), and setMaximumLevelOfDetail().

void QOpenGLTexture::setLevelofDetailBias(float bias)

Sets the level of detail bias to bias. Level of detail bias affects the point at which mipmapping levels change. Increasing values for level of detail bias makes the overall images blurrier or smoother. Decreasing values make the overall images sharper.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also levelofDetailBias().

void QOpenGLTexture::setMagnificationFilter(QOpenGLTexture::Filter filter)

Sets the magnification filter to filter.

See also magnificationFilter(), setMinificationFilter(), and setMinMagFilters().

void QOpenGLTexture::setMaximumAnisotropy(float anisotropy)

If your OpenGL implementation supports the GL_EXT_texture_filter_anisotropic extension this function sets the maximum anisotropy level to anisotropy.

See also maximumAnisotropy().

void QOpenGLTexture::setMaximumLevelOfDetail(float value)

Sets the maximum level of detail to value. This limits the selection of lowest resolution mipmap (highest mipmap level). The default value is 1000.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also maximumLevelOfDetail(), setMinimumLevelOfDetail(), and setLevelOfDetailRange().

void QOpenGLTexture::setMinMagFilters(QOpenGLTexture::Filter minificationFilter, QOpenGLTexture::Filter magnificationFilter)

Sets the minification filter to minificationFilter and the magnification filter to magnificationFilter.

See also minMagFilters(), setMinificationFilter(), and setMagnificationFilter().

void QOpenGLTexture::setMinificationFilter(QOpenGLTexture::Filter filter)

Sets the filter used for minification to filter.

See also minificationFilter(), setMagnificationFilter(), and setMinMagFilters().

void QOpenGLTexture::setMinimumLevelOfDetail(float value)

Sets the minimum level of detail to value. This limits the selection of highest resolution mipmap (lowest mipmap level). The default value is -1000.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also minimumLevelOfDetail(), setMaximumLevelOfDetail(), and setLevelOfDetailRange().

void QOpenGLTexture::setMipBaseLevel(int baseLevel)

Sets the base mipmap level used for all texture lookups with this texture to baseLevel.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also mipBaseLevel(), setMipMaxLevel(), and setMipLevelRange().

void QOpenGLTexture::setMipLevelRange(int baseLevel, int maxLevel)

Sets the range of mipmap levels that can be used for texture lookups with this texture to range from baseLevel to maxLevel.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also setMipBaseLevel(), setMipMaxLevel(), and mipLevelRange().

void QOpenGLTexture::setMipLevels(int levels)

For texture targets that support mipmaps, this function sets the requested number of mipmap levels to allocate storage for. This function should be called before storage is allocated for the texture.

If the texture target does not support mipmaps this function has no effect.

See also mipLevels(), maximumMipLevels(), and isStorageAllocated().

void QOpenGLTexture::setMipMaxLevel(int maxLevel)

Sets the maximum mipmap level used for all texture lookups with this texture to maxLevel.

Note: This function has no effect on Qt built for OpenGL ES 2.

See also mipMaxLevel(), setMipBaseLevel(), and setMipLevelRange().

void QOpenGLTexture::setSamples(int samples)

Sets the number of samples to allocate storage for when rendering to a multisample capable texture target. This function should be called before storage is allocated for the texture.

For targets that do not support multisampling this function has no effect.

See also samples() and isStorageAllocated().

void QOpenGLTexture::setSize(int width, int height = 1, int depth = 1)

Sets the dimensions of this texture object to width, height, and depth. The default for each dimension is 1. The maximum allowable texture size is dependent upon your OpenGL implementation. Allocating storage for a texture less than the maximum size can still fail if your system is low on resources.

If a non-power-of-two width, height or depth is provided and your OpenGL implementation doesn't have support for repeating non-power-of-two textures, then the wrap mode is automatically set to ClampToEdge.

See also width(), height(), and depth().

void QOpenGLTexture::setSwizzleMask(QOpenGLTexture::SwizzleComponent component, QOpenGLTexture::SwizzleValue value)

GLSL shaders are able to reorder the components of the vec4 returned by texture functions. It is also desirable to be able to control this reordering from CPU side code. This is made possible by swizzle masks since OpenGL 3.3.

Each component of the texture can be mapped to one of the SwizzleValue options.

This function maps component to the output value.

Note: This function has no effect on Mac and Qt built for OpenGL ES 2.

See also swizzleMask().

void QOpenGLTexture::setSwizzleMask(QOpenGLTexture::SwizzleValue r, QOpenGLTexture::SwizzleValue g, QOpenGLTexture::SwizzleValue b, QOpenGLTexture::SwizzleValue a)

Parameters r, g, b, and a are values used for setting the colors red, green, blue, and the alpha value.

This is an overloaded function.

void QOpenGLTexture::setWrapMode(QOpenGLTexture::WrapMode mode)

Sets the wrap (or repeat mode) for all texture dimensions to mode.

See also wrapMode().

void QOpenGLTexture::setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode)

Holds the texture dimension direction.

This is an overloaded function.

QOpenGLTexture::SwizzleValue QOpenGLTexture::swizzleMask(QOpenGLTexture::SwizzleComponent component) const

Returns the swizzle mask for texture component.

See also setSwizzleMask().

QOpenGLTexture::Target QOpenGLTexture::target() const

Returns the binding target of this texture.

GLuint QOpenGLTexture::textureId() const

Returns the name of the underlying OpenGL texture object or 0 if it has not yet been created.

See also create(), destroy(), and isCreated().

int QOpenGLTexture::width() const

Returns the width of a 1D, 2D or 3D texture.

See also height(), depth(), and setSize().

QOpenGLTexture::WrapMode QOpenGLTexture::wrapMode(QOpenGLTexture::CoordinateDirection direction) const

Returns the wrap mode for the texture dimension direction.

See also setWrapMode().

© 2024 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.