QOpenGLTexture Class

QOpenGLTexture 类封装了一个 OpenGL 纹理对象。更多

Header: #include <QOpenGLTexture>

公共类型

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 }

公共函数

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
std::pair<float, float> levelOfDetailRange() const
float levelofDetailBias() const
QOpenGLTexture::Filter magnificationFilter() const
float maximumAnisotropy() const
float maximumLevelOfDetail() const
int maximumMipLevels() const
std::pair<QOpenGLTexture::Filter, QOpenGLTexture::Filter> minMagFilters() const
QOpenGLTexture::Filter minificationFilter() const
float minimumLevelOfDetail() const
int mipBaseLevel() const
std::pair<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

静态公共成员

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

详细说明

QOpenGLTexture 可根据 OpenGL 实现的功能,轻松处理 OpenGL 纹理及其提供的各种功能和目标。

QOpenGLTexture 的典型使用模式是

  • 实例化对象,指定纹理目标类型
  • 设置影响存储要求的属性,如存储格式、尺寸等
  • 分配服务器端存储空间
  • 可选择上传像素数据
  • 可选择设置其他属性,如过滤和边框选项
  • 使用纹理渲染或渲染到纹理

在使用QImage 作为纹理像素数据源的常见情况下,上述大部分步骤都会自动执行。

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

请注意,QImage 是垂直翻转的,以考虑到 OpenGL 和QImage 在 Y 轴上使用相反的方向。另一种方法是转换纹理坐标。

成员类型文档

enum QOpenGLTexture::BindingTarget

该枚举定义了纹理单元可能的绑定目标。

常数描述
QOpenGLTexture::BindingTarget1D0x8068等价于 GL_TEXTURE_BINDING_1D
QOpenGLTexture::BindingTarget1DArray0x8C1C等价于 GL_TEXTURE_BINDING_1D_ARRAY
QOpenGLTexture::BindingTarget2D0x8069等价于 GL_TEXTURE_BINDING_2D
QOpenGLTexture::BindingTarget2DArray0x8C1D等价于 GL_TEXTURE_BINDING_2D_ARRAY
QOpenGLTexture::BindingTarget3D0x806A等价于 GL_TEXTURE_BINDING_3D
QOpenGLTexture::BindingTargetCubeMap0x8514等价于 GL_TEXTURE_BINDING_CUBE_MAP
QOpenGLTexture::BindingTargetCubeMapArray0x900A等价于 GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
QOpenGLTexture::BindingTarget2DMultisample0x9104等价于 GL_TEXTURE_BINDING_2D_MULTISAMPLE
QOpenGLTexture::BindingTarget2DMultisampleArray0x9105等价于 GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
QOpenGLTexture::BindingTargetRectangle0x84F6等价于 GL_TEXTURE_BINDING_RECTANGLE
QOpenGLTexture::BindingTargetBuffer0x8C2C等价于 GL_TEXTURE_BINDING_BUFFER

enum QOpenGLTexture::ComparisonFunction

此枚举用于指定在此纹理上启用纹理比较功能时使用的比较运算符。

常量说明
QOpenGLTexture::CompareLessEqual0x0203等价于 GL_LEQUAL。
QOpenGLTexture::CompareGreaterEqual0x0206等价于 GL_GEQUAL。
QOpenGLTexture::CompareLess0x0201等价于 GL_LESS。
QOpenGLTexture::CompareGreater0x0204等价于 GL_GREATER。
QOpenGLTexture::CompareEqual0x0202等价于 GL_EQUAL。
QOpenGLTexture::CompareNotEqual0x0205等价于 GL_NOTEQUAL。
QOpenGLTexture::CompareAlways0x0207等价于 GL_ALLWAYS。
QOpenGLTexture::CompareNever0x0200等价于 GL_NEVER。

enum QOpenGLTexture::ComparisonMode

此枚举用于指定对该纹理进行采样时使用的比较模式。

常数说明
QOpenGLTexture::CompareRefToTexture0x884E等同于 GL_COMPARE_REF_TO_TEXTURE。
QOpenGLTexture::CompareNone0x0000等同于 GL_NONE。

enum QOpenGLTexture::CoordinateDirection

此枚举定义了可能的纹理坐标方向

常数说明
QOpenGLTexture::DirectionS0x2802水平方向。等同于 GL_TEXTURE_WRAP_S
QOpenGLTexture::DirectionT0x2803垂直方向。等同于 GL_TEXTURE_WRAP_T
QOpenGLTexture::DirectionR0x8072深度方向。等同于 GL_TEXTURE_WRAP_R

enum QOpenGLTexture::CubeMapFace

此枚举定义了可能的 CubeMap 面。

常数描述
QOpenGLTexture::CubeMapPositiveX0x8515等同于 GL_TEXTURE_CUBE_MAP_POSITIVE_X
QOpenGLTexture::CubeMapNegativeX0x8516等价于 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
QOpenGLTexture::CubeMapPositiveY0x8517等价于 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
QOpenGLTexture::CubeMapNegativeY0x8518等价于 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
QOpenGLTexture::CubeMapPositiveZ0x8519等价于 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
QOpenGLTexture::CubeMapNegativeZ0x851A等价于 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z

enum QOpenGLTexture::DepthStencilMode

此枚举用于指定在纹理采样时访问深度/模版纹理的哪个组件。

常数说明
QOpenGLTexture::DepthMode0x1902等价于 GL_DEPTH_COMPONENT。
QOpenGLTexture::StencilMode0x1901等价于 GL_STENCIL_INDEX。

枚举 QOpenGLTexture::Feature
flags QOpenGLTexture::Features

此枚举定义了可以测试的 OpenGL 纹理相关特性。

常量描述
QOpenGLTexture::ImmutableStorage0x00000001支持不可变纹理存储
QOpenGLTexture::ImmutableMultisampleStorage0x00000002支持多采样目标的不可变纹理存储
QOpenGLTexture::TextureRectangle0x00000004支持 GL_TEXTURE_RECTANGLE 目标点
QOpenGLTexture::TextureArrays0x00000008支持具有数组层的纹理目标
QOpenGLTexture::Texture3D0x00000010支持三维纹理目标
QOpenGLTexture::TextureMultisample0x00000020支持具有多采样功能的纹理目标
QOpenGLTexture::TextureBuffer0x00000040支持使用 OpenGL 缓冲对象作为数据源的纹理
QOpenGLTexture::TextureCubeMapArrays0x00000080支持立方体地图阵列纹理目标
QOpenGLTexture::Swizzle0x00000100支持纹理组件旋转遮罩
QOpenGLTexture::StencilTexturing0x00000200支持模版纹理(即在 GLSL 着色器中查找组合深度/模版格式纹理的深度或模版组件)。
QOpenGLTexture::AnisotropicFiltering0x00000400支持各向异性纹理过滤
QOpenGLTexture::NPOTTextures0x00000800基本支持非二倍幂纹理
QOpenGLTexture::NPOTTextureRepeat0x00001000完全支持非二倍幂纹理,包括纹理重复模式
QOpenGLTexture::Texture1D0x00002000支持 1 维纹理目标
QOpenGLTexture::TextureComparisonOperators0x00004000支持纹理比较运算符
QOpenGLTexture::TextureMipMapLevel0x00008000支持设置基本和最大 mipmap 级别

特征类型是QFlags<Feature> 的类型定义。它存储特征值的 OR 组合。

enum QOpenGLTexture::Filter

该枚举定义了QOpenGLTexture 对象的过滤参数。

常量描述
QOpenGLTexture::Nearest0x2600等同于 GL_NEAREST
QOpenGLTexture::Linear0x2601等价于 GL_LINEAR
QOpenGLTexture::NearestMipMapNearest0x2700等价于 GL_NEAREST_MIPMAP_NEAREST
QOpenGLTexture::NearestMipMapLinear0x2702等价于 GL_NEAREST_MIPMAP_LINEAR
QOpenGLTexture::LinearMipMapNearest0x2701等价于 GL_LINEAR_MIPMAP_NEAREST
QOpenGLTexture::LinearMipMapLinear0x2703等价于 GL_LINEAR_MIPMAP_LINEAR

enum QOpenGLTexture::MipMapGeneration

该枚举定义了控制 mipmap 生成的选项。

常数说明
QOpenGLTexture::GenerateMipMaps0应生成贴图
QOpenGLTexture::DontGenerateMipMaps1不应生成贴图

enum QOpenGLTexture::PixelFormat

该枚举定义了像素传输操作可能使用的客户端像素格式。

常数描述
QOpenGLTexture::NoSourceFormat0等同于 GL_NONE
QOpenGLTexture::Red0x1903等同于 GL_RED
QOpenGLTexture::RG0x8227等价于 GL_RG
QOpenGLTexture::RGB0x1907等价于 GL_RGB
QOpenGLTexture::BGR0x80E0等价于 GL_BGR
QOpenGLTexture::RGBA0x1908等价于 GL_RGBA
QOpenGLTexture::BGRA0x80E1等价于 GL_BGRA
QOpenGLTexture::Red_Integer0x8D94等价于 GL_RED_INTEGER
QOpenGLTexture::RG_Integer0x8228等价于 GL_RG_INTEGER
QOpenGLTexture::RGB_Integer0x8D98等价于 GL_RGB_INTEGER
QOpenGLTexture::BGR_Integer0x8D9A等价于 GL_BGR_INTEGER
QOpenGLTexture::RGBA_Integer0x8D99等价于 GL_RGBA_INTEGER
QOpenGLTexture::BGRA_Integer0x8D9B等价于 GL_BGRA_INTEGER
QOpenGLTexture::Stencil0x1901等价于 GL_STENCIL_INDEX。在 Qt 5.4 中引入
QOpenGLTexture::Depth0x1902等价于 GL_DEPTH_COMPONENT
QOpenGLTexture::DepthStencil0x84F9等价于 GL_DEPTH_STENCIL
QOpenGLTexture::Alpha0x1906等价于 GL_ALPHA(仅 OpenGL ES 2)
QOpenGLTexture::Luminance0x1909等价于 GL_LUMINANCE(仅 OpenGL ES 2)
QOpenGLTexture::LuminanceAlpha0x190A等价于 GL_LUMINANCE_ALPHA(仅 OpenGL ES 2)

enum QOpenGLTexture::PixelType

该枚举定义了像素传输操作可能使用的像素数据类型

常数说明
QOpenGLTexture::NoPixelType0等同于 GL_NONE
QOpenGLTexture::Int80x1400等同于 GL_BYTE
QOpenGLTexture::UInt80x1401等价于 GL_UNSIGNED_BYTE
QOpenGLTexture::Int160x1402等价于 GL_SHORT
QOpenGLTexture::UInt160x1403等价于 GL_UNSIGNED_SHORT
QOpenGLTexture::Int320x1404等价于 GL_INT
QOpenGLTexture::UInt320x1405等价于 GL_UNSIGNED_INT
QOpenGLTexture::Float160x140B等价于 GL_HALF_FLOAT
QOpenGLTexture::Float16OES0x8D61等价于 GL_HALF_FLOAT_OES
QOpenGLTexture::Float320x1406等价于 GL_FLOAT
QOpenGLTexture::UInt32_RGB9_E50x8C3E等价于 GL_UNSIGNED_INT_5_9_9_9_REV
QOpenGLTexture::UInt32_RG11B10F0x8C3B等价于 GL_UNSIGNED_INT_10F_11F_11F_REV
QOpenGLTexture::UInt8_RG3B20x8032等价于 GL_UNSIGNED_BYTE_3_3_2
QOpenGLTexture::UInt8_RG3B2_Rev0x8362等价于 GL_UNSIGNED_BYTE_2_3_3_REV
QOpenGLTexture::UInt16_RGB5A10x8034等价于 GL_UNSIGNED_SHORT_5_5_5_1
QOpenGLTexture::UInt16_RGB5A1_Rev0x8366等价于 GL_UNSIGNED_SHORT_1_5_5_REV
QOpenGLTexture::UInt16_R5G6B50x8363等价于 GL_UNSIGNED_SHORT_5_6_5
QOpenGLTexture::UInt16_R5G6B5_Rev0x8364等价于 GL_UNSIGNED_SHORT_5_6_5_REV
QOpenGLTexture::UInt16_RGBA40x8033等价于 GL_UNSIGNED_SHORT_4_4_4
QOpenGLTexture::UInt16_RGBA4_Rev0x8365等价于 GL_UNSIGNED_SHORT_4_4_4_REV
QOpenGLTexture::UInt32_RGBA80x8035等价于 GL_UNSIGNED_INT_8_8_8
QOpenGLTexture::UInt32_RGBA8_Rev0x8367等价于 GL_UNSIGNED_INT_8_8_8_REV
QOpenGLTexture::UInt32_RGB10A20x8036等价于 GL_UNSIGNED_INT_10_10_10_2
QOpenGLTexture::UInt32_RGB10A2_Rev0x8368等价于 GL_UNSIGNED_INT_2_10_10_10_REV
QOpenGLTexture::UInt32_D24S80x84FA等价于 GL_UNSIGNED_INT_24_8。在 Qt 5.4 中引入
QOpenGLTexture::Float32_D32_UInt32_S8_X240x8DAD等价于 GL_FLOAT_32_UNSIGNED_INT_24_8_REV。在 Qt 5.4 中引入

enum QOpenGLTexture::SwizzleComponent

此枚举定义了可分配旋转遮罩的纹理颜色成分。

常数说明
QOpenGLTexture::SwizzleRed0x8E42红色分量。等同于 GL_TEXTURE_SWIZZLE_R
QOpenGLTexture::SwizzleGreen0x8E43绿色分量。等价于 GL_TEXTURE_SWIZZLE_G
QOpenGLTexture::SwizzleBlue0x8E44蓝色分量。等价于 GL_TEXTURE_SWIZZLE_B
QOpenGLTexture::SwizzleAlpha0x8E45阿尔法分量。等价于 GL_TEXTURE_SWIZZLE_A

enum QOpenGLTexture::SwizzleValue

此枚举定义了纹理旋转的可能遮罩值。

常量描述
QOpenGLTexture::RedValue0x1903将组件映射到红色通道。等同于 GL_RED
QOpenGLTexture::GreenValue0x1904将组件映射到绿色通道。等同于 GL_GREEN
QOpenGLTexture::BlueValue0x1905将组件映射到蓝色通道。等同于 GL_BLUE
QOpenGLTexture::AlphaValue0x1906将组件映射到 alpha 通道。等同于 GL_ALPHA
QOpenGLTexture::ZeroValue0将分量映射到固定值 0。 等同于 GL_ZERO
QOpenGLTexture::OneValue1将分量映射到固定值 1。 相当于 GL_ONE

enum QOpenGLTexture::Target

该枚举定义了QOpenGLTexture 对象的纹理目标。有关创建数组纹理的更多信息,请参阅数组纹理

常数描述
QOpenGLTexture::Target1D0x0DE0一维纹理。等同于 GL_TEXTURE_1D。
QOpenGLTexture::Target1DArray0x8C18一个一维纹理数组。等同于 GL_TEXTURE_1D_ARRAY。
QOpenGLTexture::Target2D0x0DE1二维纹理。等同于 GL_TEXTURE_2D
QOpenGLTexture::Target2DArray0x8C1A二维纹理数组。等同于 GL_TEXTURE_2D_ARRAY
QOpenGLTexture::Target3D0x806F三维纹理。等同于 GL_TEXTURE_3D
QOpenGLTexture::TargetCubeMap0x8513立方体贴图纹理。等价于 GL_TEXTURE_CUBE_MAP
QOpenGLTexture::TargetCubeMapArray0x9009一个立方体贴图纹理数组。等同于 GL_TEXTURE_CUBE_MAP_ARRAY
QOpenGLTexture::Target2DMultisample0x9100支持多采样的二维纹理。等同于 GL_TEXTURE_2D_MULTISAMPLE
QOpenGLTexture::Target2DMultisampleArray0x9102支持多采样的二维纹理数组。等价于 GL_TEXTURE_2D_MULTISAMPLE_ARRAY
QOpenGLTexture::TargetRectangle0x84F5矩形二维纹理。等价于 GL_TEXTURE_RECTANGLE
QOpenGLTexture::TargetBuffer0x8C2A带有 OpenGL 缓冲对象数据的纹理。等价于 GL_TEXTURE_BUFFER

enum QOpenGLTexture::TextureFormat

该枚举定义了可能的纹理格式。根据您的 OpenGL 实现,可能只支持其中的一个子集。

常量描述
QOpenGLTexture::NoFormat0等同于 GL_NONE
QOpenGLTexture::R8_UNorm0x8229等同于 GL_R8
QOpenGLTexture::RG8_UNorm0x822B等价于 GL_RG8
QOpenGLTexture::RGB8_UNorm0x8051等价于 GL_RGB8
QOpenGLTexture::RGBA8_UNorm0x8058等价于 GL_RGBA8
QOpenGLTexture::R16_UNorm0x822A等价于 GL_R16
QOpenGLTexture::RG16_UNorm0x822C等价于 GL_RG16
QOpenGLTexture::RGB16_UNorm0x8054等价于 GL_RGB16
QOpenGLTexture::RGBA16_UNorm0x805B等价于 GL_RGBA16
QOpenGLTexture::R8_SNorm0x8F94等价于 GL_R8_SNORM
QOpenGLTexture::RG8_SNorm0x8F95等价于 GL_RG8_SNORM
QOpenGLTexture::RGB8_SNorm0x8F96等价于 GL_RGB8_SNORM
QOpenGLTexture::RGBA8_SNorm0x8F97等价于 GL_RGBA8_SNORM
QOpenGLTexture::R16_SNorm0x8F98等价于 GL_R16_SNORM
QOpenGLTexture::RG16_SNorm0x8F99等价于 GL_RG16_SNORM
QOpenGLTexture::RGB16_SNorm0x8F9A等价于 GL_RGB16_SNORM
QOpenGLTexture::RGBA16_SNorm0x8F9B等价于 GL_RGBA16_SNORM
QOpenGLTexture::R8U0x8232等价于 GL_R8UI
QOpenGLTexture::RG8U0x8238等效于 GL_RG8UI
QOpenGLTexture::RGB8U0x8D7D等价于 GL_RGB8UI
QOpenGLTexture::RGBA8U0x8D7C等价于 GL_RGBA8UI
QOpenGLTexture::R16U0x8234等价于 GL_R16UI
QOpenGLTexture::RG16U0x823A等价于 GL_RG16UI
QOpenGLTexture::RGB16U0x8D77等价于 GL_RGB16UI
QOpenGLTexture::RGBA16U0x8D76等价于 GL_RGBA16UI
QOpenGLTexture::R32U0x8236等价于 GL_R32UI
QOpenGLTexture::RG32U0x823C等价于 GL_RG32UI
QOpenGLTexture::RGB32U0x8D71等价于 GL_RGB32UI
QOpenGLTexture::RGBA32U0x8D70等价于 GL_RGBA32UI
QOpenGLTexture::R8I0x8231等价于 GL_R8I
QOpenGLTexture::RG8I0x8237等价于 GL_RG8I
QOpenGLTexture::RGB8I0x8D8F等价于 GL_RGB8I
QOpenGLTexture::RGBA8I0x8D8E等价于 GL_RGBA8I
QOpenGLTexture::R16I0x8233等价于 GL_R16I
QOpenGLTexture::RG16I0x8239等效于 GL_RG16I
QOpenGLTexture::RGB16I0x8D89等效于 GL_RGB16I
QOpenGLTexture::RGBA16I0x8D88等价于 GL_RGBA16I
QOpenGLTexture::R32I0x8235等价于 GL_R32I
QOpenGLTexture::RG32I0x823B等效于 GL_RG32I
QOpenGLTexture::RGB32I0x8D83等效于 GL_RGB32I
QOpenGLTexture::RGBA32I0x8D82等价于 GL_RGBA32I
QOpenGLTexture::R16F0x822D等价于 GL_R16F
QOpenGLTexture::RG16F0x822F等效于 GL_RG16F
QOpenGLTexture::RGB16F0x881B等效于 GL_RGB16F
QOpenGLTexture::RGBA16F0x881A等价于 GL_RGBA16F
QOpenGLTexture::R32F0x822E等效于 GL_R32F
QOpenGLTexture::RG32F0x8230等效于 GL_RG32F
QOpenGLTexture::RGB32F0x8815等效于 GL_RGB32F
QOpenGLTexture::RGBA32F0x8814等价于 GL_RGBA32F
QOpenGLTexture::RGB9E50x8C3D等效于 GL_RGB9_E5
QOpenGLTexture::RG11B10F0x8C3A等效于 GL_R11F_G11F_B10F
QOpenGLTexture::RG3B20x2A10等效于 GL_R3_G3_B2
QOpenGLTexture::R5G6B50x8D62等效于 GL_RGB565
QOpenGLTexture::RGB5A10x8057等效于 GL_RGB5_A1
QOpenGLTexture::RGBA40x8056等效于 GL_RGBA4
QOpenGLTexture::RGB10A20x906F等效于 GL_RGB10_A2UI
QOpenGLTexture::D160x81A5等效于 GL_DEPTH_COMPONENT16
QOpenGLTexture::D240x81A6等效于 GL_DEPTH_COMPONENT24
QOpenGLTexture::D24S80x88F0等价于 GL_DEPTH24_STENCIL8
QOpenGLTexture::D320x81A7等价于 GL_DEPTH_COMPONENT32
QOpenGLTexture::D32F0x8CAC等价于 GL_DEPTH_COMPONENT32F
QOpenGLTexture::D32FS8X240x8CAD等价于 GL_DEPTH32F_STENCIL8
QOpenGLTexture::S80x8D48等价于 GL_STENCIL_INDEX8。在 Qt 5.4 中引入
QOpenGLTexture::RGB_DXT10x83F0等价于 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
QOpenGLTexture::RGBA_DXT10x83F1等价于 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
QOpenGLTexture::RGBA_DXT30x83F2等价于 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
QOpenGLTexture::RGBA_DXT50x83F3等价于 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
QOpenGLTexture::R_ATI1N_UNorm0x8DBB等价于 GL_COMPRESSED_RED_RGTC1
QOpenGLTexture::R_ATI1N_SNorm0x8DBC等价于 GL_COMPRESSED_SIGNED_RED_RGTC1
QOpenGLTexture::RG_ATI2N_UNorm0x8DBD等价于 GL_COMPRESSED_RG_RGTC2
QOpenGLTexture::RG_ATI2N_SNorm0x8DBE等价于 GL_COMPRESSED_SIGNED_RG_RGTC2
QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT0x8E8F等价于 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
QOpenGLTexture::RGB_BP_SIGNED_FLOAT0x8E8E等价于 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
QOpenGLTexture::RGB_BP_UNorm0x8E8C等价于 GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
QOpenGLTexture::R11_EAC_UNorm0x9270等价于 GL_COMPRESSED_R11_EAC
QOpenGLTexture::R11_EAC_SNorm0x9271等价于 GL_COMPRESSED_SIGNED_R11_EAC
QOpenGLTexture::RG11_EAC_UNorm0x9272等价于 GL_COMPRESSED_RG11_EAC
QOpenGLTexture::RG11_EAC_SNorm0x9273等价于 GL_COMPRESSED_SIGNED_RG11_EAC
QOpenGLTexture::RGB8_ETC20x9274等价于 GL_COMPRESSED_RGB8_ETC2
QOpenGLTexture::SRGB8_ETC20x9275等价于 GL_COMPRESSED_SIGNED_RGB8_ETC2
QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC20x9276等价于 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC20x9277等价于 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
QOpenGLTexture::RGBA8_ETC2_EAC0x9278等价于 GL_COMPRESSED_RGBA8_ETC2_EAC
QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC0x9279等价于 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
QOpenGLTexture::RGB8_ETC10x8D64等价于 GL_ETC1_RGB8_OES
QOpenGLTexture::RGBA_ASTC_4x40x93B0等价于 GL_COMPRESSED_RGBA_ASTC_4x4_KHR
QOpenGLTexture::RGBA_ASTC_5x40x93B1等价于 GL_COMPRESSED_RGBA_ASTC_5x4_KHR
QOpenGLTexture::RGBA_ASTC_5x50x93B2等价于 GL_COMPRESSED_RGBA_ASTC_5x5_KHR
QOpenGLTexture::RGBA_ASTC_6x50x93B3等价于 GL_COMPRESSED_RGBA_ASTC_6x5_KHR
QOpenGLTexture::RGBA_ASTC_6x60x93B4等价于 GL_COMPRESSED_RGBA_ASTC_6x6_KHR
QOpenGLTexture::RGBA_ASTC_8x50x93B5等价于 GL_COMPRESSED_RGBA_ASTC_8x5_KHR
QOpenGLTexture::RGBA_ASTC_8x60x93B6等价于 GL_COMPRESSED_RGBA_ASTC_8x6_KHR
QOpenGLTexture::RGBA_ASTC_8x80x93B7等价于 GL_COMPRESSED_RGBA_ASTC_8x8_KHR
QOpenGLTexture::RGBA_ASTC_10x50x93B8等价于 GL_COMPRESSED_RGBA_ASTC_10x5_KHR
QOpenGLTexture::RGBA_ASTC_10x60x93B9等价于 GL_COMPRESSED_RGBA_ASTC_10x6_KHR
QOpenGLTexture::RGBA_ASTC_10x80x93BA等价于 GL_COMPRESSED_RGBA_ASTC_10x8_KHR
QOpenGLTexture::RGBA_ASTC_10x100x93BB等价于 GL_COMPRESSED_RGBA_ASTC_10x10_KHR
QOpenGLTexture::RGBA_ASTC_12x100x93BC等价于 GL_COMPRESSED_RGBA_ASTC_12x10_KHR
QOpenGLTexture::RGBA_ASTC_12x120x93BD等价于 GL_COMPRESSED_RGBA_ASTC_12x12_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_4x40x93D0等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_5x40x93D1等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_5x50x93D2等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_6x50x93D3等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_6x60x93D4等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x50x93D5等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x60x93D6等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_8x80x93D7等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x50x93D8等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x60x93D9等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x80x93DA等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_10x100x93DB等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_12x100x93DC等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
QOpenGLTexture::SRGB8_Alpha8_ASTC_12x120x93DD等价于 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
QOpenGLTexture::SRGB80x8C41等价于 GL_SRGB8
QOpenGLTexture::SRGB8_Alpha80x8C43等价于 GL_SRGB8_ALPHA8
QOpenGLTexture::SRGB_DXT10x8C4C等价于 GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
QOpenGLTexture::SRGB_Alpha_DXT10x8C4D等价于 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
QOpenGLTexture::SRGB_Alpha_DXT30x8C4E等价于 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
QOpenGLTexture::SRGB_Alpha_DXT50x8C4F等价于 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
QOpenGLTexture::SRGB_BP_UNorm0x8E8D等价于 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
QOpenGLTexture::DepthFormat0x1902等价于 GL_DEPTH_COMPONENT(仅适用于带有 OES_depth_texture 的 OpenGL ES 3 或 ES 2)
QOpenGLTexture::AlphaFormat0x1906等价于 GL_ALPHA(仅限 OpenGL ES 2)
QOpenGLTexture::RGBFormat0x1907等价于 GL_RGB(仅限 OpenGL ES 2)
QOpenGLTexture::RGBAFormat0x1908等价于 GL_RGBA(仅 OpenGL ES 2)
QOpenGLTexture::LuminanceFormat0x1909等价于 GL_LUMINANCE(仅 OpenGL ES 2)
QOpenGLTexture::LuminanceAlphaFormat0x190A等效于 GL_LUMINANCE_ALPHA(仅 OpenGL ES 2)

enum QOpenGLTexture::TextureUnitReset

该枚举定义了控制纹理单元激活的选项。

常数说明
QOpenGLTexture::ResetTextureUnit0上一个激活的纹理单元将被重置
QOpenGLTexture::DontResetTextureUnit1上一个激活的纹理单元不会重置

enum QOpenGLTexture::WrapMode

此枚举定义了可能的纹理坐标包模式。

常数说明
QOpenGLTexture::Repeat0x2901纹理坐标重复。等同于 GL_REPEAT
QOpenGLTexture::MirroredRepeat0x8370纹理坐标在 0 和 1 之间反射。 相当于 GL_MIRRORED_REPEAT
QOpenGLTexture::ClampToEdge0x812F将纹理坐标锁定为 [0,1]。等价于 GL_CLAMP_TO_EDGE
QOpenGLTexture::ClampToBorder0x812D与 ClampToEdge 相同,但也会用固定的边框颜色混合 0 和 1 处的样本。等价于 GL_CLAMP_TO_BORDER

成员函数文档

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

创建一个 QOpenGLTexture 对象,稍后可将其绑定到target

这不会创建底层的 OpenGL 纹理对象。因此,使用此构造函数进行构造不需要有效的当前 OpenGL 上下文。

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

创建一个 QOpenGLTexture 对象,该对象稍后可绑定到 2D 纹理目标,并包含image 中的像素数据。如果希望生成一连串的 mipmaps,可将genMipMaps 设置为true (这是默认值)。

这将创建底层的 OpenGL 纹理对象。因此,使用此构造函数进行构造时需要有效的当前 OpenGL 上下文。

注意: image 会自动转换为QImage::Format_RGBA8888 ,这可能会对使用不同格式的大型图像的性能产生影响。

void QOpenGLTexture::allocateStorage()

为该纹理对象分配服务器端存储空间,同时考虑格式、尺寸、mipmap 级别、阵列层和立方体贴图面。

一旦分配了存储空间,就无法再更改这些属性。

如果支持QOpenGLTexture ,则可使用不可变的纹理存储。

一旦为纹理分配了存储空间,就可以通过setData() 重载之一上传像素数据。

注: 如果不可变纹理存储不可用,那么将使用默认像素格式和像素类型来创建可变存储。您可以使用其他 allocateStorage() 重载来精确指定分配可变存储时要使用的像素格式和像素类型;这在某些 OpenGL ES 实现(特别是 OpenGL ES 2)中特别有用,因为在这些实现中,分配时使用的像素格式和像素类型必须与传递给任何后续setData() 调用的格式和类型完全匹配。

另请参见 isStorageAllocated() 和setData()。

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

为该纹理对象分配服务器端存储空间,同时考虑格式、尺寸、mipmap 级别、阵列层和立方体贴图面。

一旦分配了存储空间,就无法再更改这些属性。

如果支持QOpenGLTexture ,则可使用不可变纹理存储。不过,如果不可变纹理存储不可用,那么指定的pixelFormatpixelType 将用于分配可变存储;请注意,在某些 OpenGL 实现(特别是 OpenGL ES 2)中,它们必须与传递给任何后续setData() 调用的格式和类型完全匹配。

一旦为纹理分配了存储空间,就可以通过setData() 重载之一上传像素数据。

另请参阅 isStorageAllocated() 和setData()。

void QOpenGLTexture::bind()

将此纹理绑定到当前活动的纹理单元,以备渲染。请注意,您不需要绑定QOpenGLTexture 对象就能修改它们,因为该实现在可用的地方使用 EXT_direct_state_access 扩展,在不可用的地方模拟 EXT_direct_state_access 扩展。

另请参见 release().

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

将此纹理绑定到纹理单元unit ,以便进行渲染。请注意,您不需要绑定QOpenGLTexture 对象就可以修改它们,因为在可用的情况下会使用 EXT_direct_state_access 扩展,而在不可用的情况下则会模拟 EXT_direct_state_access 扩展。

如果参数resettrue ,则此函数将把活动单元恢复为进入时的纹理单元。

另请参见 release()。

QColor QOpenGLTexture::borderColor() const

返回此纹理的 borderColor。

另请参阅 setBorderColor()。

void QOpenGLTexture::borderColor(float *border) const

将纹理边框颜色写入border 所指向数组的前四个元素。

另请参见 setBorderColor().

void QOpenGLTexture::borderColor(int *border) const

将纹理边框颜色写入border 所指向数组的前四个元素。

这是一个重载函数。

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

将纹理边框颜色写入border 所指向数组的前四个元素。

这是一个重载函数。

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

返回绑定到当前活动纹理单元target 的纹理的textureId

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

返回绑定到纹理单元target 的纹理textureId unit

QOpenGLTexture::ComparisonFunction QOpenGLTexture::comparisonFunction() const

返回在此纹理上设置的纹理比较操作符。默认情况下,纹理具有CompareLessEqual 比较函数。

另请参阅 setComparisonFunction()。

QOpenGLTexture::ComparisonMode QOpenGLTexture::comparisonMode() const

返回在此纹理上设置的纹理对比模式。默认情况下,纹理的比较模式为CompareNone (即禁用比较)。

另请参阅 setComparisonMode()。

bool QOpenGLTexture::create()

创建底层 OpenGL 纹理对象。这需要当前有效的 OpenGL 上下文。如果纹理对象已经存在,则此函数不会执行任何操作。

创建纹理对象后,您可以从textureId() 函数中获取对象名称。如果您希望调用与该纹理相关的一些原始 OpenGL 调用,这可能会很有用。

通常情况下,没有必要直接调用此函数,因为所有设置纹理对象属性的函数都会隐式调用 create() 函数。

如果创建成功,则返回true ,否则返回false

另请参阅 destroy()、isCreated() 和textureId()。

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

尝试在此纹理上创建纹理视图。纹理视图在某种程度上类似于 SQL 中的视图,它呈现的是原始数据的受限视图或重新诠释的视图。纹理视图不会分配更多的服务器端存储空间,而是依赖源纹理的存储缓冲区。

纹理视图仅在使用不可变存储时可用。有关纹理视图的更多信息,请参阅 http://www.opengl.org/wiki/Texture_Storage#Texture_views。

target 参数指定了视图要使用的目标。只有某些目标可以使用,具体取决于原始目标的目标。例如,在Target1DArray 纹理上的视图可以指定Target1DArrayTarget1D ,但对于后者,用minimumLayermaximumLayer 指定的数组层数必须正好为 1。

类似的限制也适用于viewFormat 。更多详情,请参阅上述链接和规范。

minimumMipmapLevelmaximumMipmapLevelminimumLayermaximumLayer 参数用于限制纹理视图可访问的纹理部分。

如果创建纹理视图失败,该函数将返回 0。如果函数创建成功,它将返回一个指向新QOpenGLTexture 对象的指针,该对象将从其isTextureView() 函数中返回true

另请参阅 isTextureView()。

int QOpenGLTexture::depth() const

返回三维纹理的深度。

另请参阅 width()、height() 和setSize()。

QOpenGLTexture::DepthStencilMode QOpenGLTexture::depthStencilMode() const

返回使用深度/模版组合格式的纹理的深度模版模式。

另请参见 setDepthStencilMode()。

void QOpenGLTexture::destroy()

销毁底层 OpenGL 纹理对象。这需要当前有效的 OpenGL 上下文。

另请参阅 create()、isCreated() 和textureId()。

int QOpenGLTexture::faces() const

返回此纹理的面数。对于 cubemap 和 cubemap 阵列类型的目标,返回值为 6。

对于非 cubemap 类型的目标,将返回 1。

QOpenGLTexture::TextureFormat QOpenGLTexture::format() const

返回此纹理对象的格式。

另请参阅 setFormat()。

void QOpenGLTexture::generateMipMaps()

从 mipmap 0 级开始为该纹理对象生成 mipmap。如果正在使用需要 mipmap 的纹理目标和过滤选项,并且已禁用自动 mipmap 生成功能,则需要调用此函数或重载来创建 mipmap 链。

注意: OpenGL ES 不支持压缩纹理的 mipmap 生成。

另请参阅 setAutoMipMapGenerationEnabled()、setMipLevels() 和mipLevels()。

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

从贴图级别baseLevel 生成此纹理对象的贴图。如果您使用的纹理目标和过滤选项需要 mipmaps,而且您已禁用自动 mipmap 生成功能,则需要调用此函数或重载函数来创建 mipmap 链。

通过将 mipmap 基本级别设置为baseLevel ,然后生成 mipmap 链,就可以生成baseLevel 以上的 mipmap。如果resetBaseLeveltrue ,那么纹理的 baseLevel 将重置为之前的值。

另请参阅 setAutoMipMapGenerationEnabled()、setMipLevels() 和mipLevels()。

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

如果您的 OpenGL 实现和版本支持纹理功能,则返回true feature

int QOpenGLTexture::height() const

返回二维或三维纹理的高度。

另请参阅 width()、depth() 和setSize()。

bool QOpenGLTexture::isAutoMipMapGenerationEnabled() const

返回此纹理对象是否已启用自动 mipmap 生成。

另请参阅 setAutoMipMapGenerationEnabled() 和generateMipMaps()。

bool QOpenGLTexture::isBound() const

如果此纹理与当前活动纹理单元的相应目标绑定,则返回true

另请参阅 bind() 和release()。

bool QOpenGLTexture::isBound(uint unit)

如果此纹理与纹理单元unit 的相应目标绑定,则返回true

另请参阅 bind() 和release()。

bool QOpenGLTexture::isCreated() const

如果底层 OpenGL 纹理对象已创建,则返回true

另请参阅 create()、destroy() 和textureId()。

bool QOpenGLTexture::isFixedSamplePositions() const

返回此纹理是否使用固定的多采样样本模式。如果尚未为该纹理分配存储空间,该函数将返回所请求的固定采样位置设置。

对于不支持多重采样的纹理目标,将返回true

另请参阅 setFixedSamplePositions() 和isStorageAllocated()。

bool QOpenGLTexture::isStorageAllocated() const

如果此纹理的服务器端存储空间已分配,则返回true

一旦存储空间分配完毕,就不能更改纹理格式、尺寸、mipmap 级别和数组层。

另请参阅 allocateStorage()、setSize()、setMipLevels()、setLayers() 和setFormat()。

bool QOpenGLTexture::isTextureView() const

如果此纹理对象实际上是另一个纹理对象的视图,则返回true

另请参阅 createTextureView()。

int QOpenGLTexture::layers() const

返回此纹理的数组层数。如果尚未为该纹理分配存储空间,该函数将返回所请求的数组层数。

对于不支持数组层的纹理目标,此函数将返回 1。

另请参阅 setLayers() 和isStorageAllocated()。

std::pair<float, float> QOpenGLTexture::levelOfDetailRange() const

返回最小和最大详细程度参数。

另请参阅 setLevelOfDetailRange()、minimumLevelOfDetail() 和maximumLevelOfDetail()。

float QOpenGLTexture::levelofDetailBias() const

返回偏置参数的详细程度。

另请参见 setLevelofDetailBias()。

QOpenGLTexture::Filter QOpenGLTexture::magnificationFilter() const

返回放大倍数滤波器。

另请参阅 setMagnificationFilter()。

float QOpenGLTexture::maximumAnisotropy() const

返回执行纹理查找时要考虑的最大各向异性程度。这需要 GL_EXT_texture_filter_anisotropic 扩展。

另请参阅 setMaximumAnisotropy().

float QOpenGLTexture::maximumLevelOfDetail() const

返回参数的最大详细程度。

另请参阅 setMaximumLevelOfDetail()、minimumLevelOfDetail() 和levelOfDetailRange()。

int QOpenGLTexture::maximumMipLevels() const

返回此纹理在当前尺寸下的最大 mipmap 层数。

另请参阅 setMipLevels()、mipLevels() 和setSize()。

std::pair<QOpenGLTexture::Filter, QOpenGLTexture::Filter> QOpenGLTexture::minMagFilters() const

返回当前最小化和放大过滤器。

另请参阅 setMinMagFilters()。

QOpenGLTexture::Filter QOpenGLTexture::minificationFilter() const

返回最小化过滤器。

另请参见 setMinificationFilter().

float QOpenGLTexture::minimumLevelOfDetail() const

返回参数的最小详细程度。

另请参阅 setMinimumLevelOfDetail()、maximumLevelOfDetail() 和levelOfDetailRange()。

int QOpenGLTexture::mipBaseLevel() const

返回使用此纹理进行所有纹理查找时使用的 mipmap 基本级别。默认值为 0。

另请参阅 setMipBaseLevel()、mipMaxLevel() 和mipLevelRange()。

std::pair<int, int> QOpenGLTexture::mipLevelRange() const

返回可用于此纹理查找的 mipmap 级别范围。

另请参阅 setMipLevelRange()、mipBaseLevel() 和mipMaxLevel()。

int QOpenGLTexture::mipLevels() const

返回此纹理的 mipmap 层数。如果尚未为该纹理分配存储空间,则返回请求的 mipmap 层数。

另请参阅 setMipLevels()、maximumMipLevels() 和isStorageAllocated()。

int QOpenGLTexture::mipMaxLevel() const

返回使用此纹理进行所有纹理查找时使用的 mipmap 最大级别。

另请参阅 setMipMaxLevel()、mipBaseLevel() 和mipLevelRange()。

void QOpenGLTexture::release()

将此纹理从当前活动纹理单元中解除绑定。

另请参阅 bind()。

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

从纹理单元unit 解除对该纹理的绑定。

如果参数resettrue ,则此函数将把活动单元恢复为进入时的活动纹理单元。

int QOpenGLTexture::samples() const

返回此纹理的多采样点数。如果尚未为该纹理分配存储空间,该函数将返回所请求的采样点数。

对于不支持多重采样的纹理目标,此函数将返回 0。

另请参阅 setSamples() 和isStorageAllocated()。

void QOpenGLTexture::setAutoMipMapGenerationEnabled(bool enabled)

如果enabledtrue ,则每当通过setData() 设置 0 级 mipmap 数据时,都会为该纹理对象自动生成 mipmap。

自动 mipmap 生成默认为启用。

注意: OpenGL ES 2.0 不支持压缩纹理的 mipmap 生成。

另请参阅 isAutoMipMapGenerationEnabled() 和generateMipMaps()。

void QOpenGLTexture::setBorderColor(const QColor &color)

将纹理的边框颜色设置为color

注意: 此函数对 Mac 和为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 borderColor() 。

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

将红色设置为r ,将绿色设置为g ,将蓝色设置为b ,将a 设置为 alpha 值。

这是一个重载函数。

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

将红色设置为r ,将绿色设置为g ,将蓝色设置为b ,将 alpha 值设置为a

这是一个重载函数。

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

将红色设置为r ,将绿色设置为g ,将蓝色设置为b ,将 alpha 值设置为a

这是一个重载函数。

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

将此纹理的纹理比较函数设置为function 。阴影采样器在对深度纹理进行采样时会用到纹理比较函数。

另请参阅 comparisonFunction()。

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

将此纹理的纹理比较模式设置为mode 。阴影采样器在对深度纹理进行采样时会使用纹理比较模式。

另请参阅 comparisonMode()。

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

将压缩像素data 上传到mipLevel 、阵列layercubeFace 。像素传输可选择由options 控制。dataSize 参数应指定data 所指向数据的大小。

如果不使用压缩的format() ,则应使用setData() 代替此函数。

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

这是一个重载函数。

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

这是一个重载函数。

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

这是一个重载函数。

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

这是一个重载函数。

参数layerCount 是本次调用上传/填充的纹理数组中的层数。

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

上传此纹理对象的像素data mipLevel 、数组layercubeFace 。上传像素数据前必须已分配存储空间。setData()的某些重载会设置适当的尺寸、mipmap 级别和数组层,然后在有足够信息的情况下为您分配存储空间。这一点会在函数文档中注明。

data 指向的像素数据结构由sourceFormatsourceType 指定。像素数据上传可选择由options 控制。

如果使用压缩的format() ,则应使用setCompressedData() 代替此函数。

另请参见 setCompressedData()。

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

setData() 的重载将为您分配存储空间。像素数据包含在image 中。默认情况下会生成 mipmap。将genMipMaps 设置为DontGenerateMipMaps 可关闭 mipmap 生成。

注意: image 会自动转换为QImage::Format_RGBA8888 ,这可能会对使用不同格式的大型图像的性能产生影响。

这是一个重载函数。

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

这是一个重载函数。

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

这是一个重载函数。

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

这是一个重载函数。

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)

这是一个重载函数。

参数layerCount 是本次调用上传/填充的纹理数组中的层数。

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)

这是一个重载函数。

此重载用于更新纹理的一部分。参数xOffset,yOffset,zOffset 指定纹理中的像素偏移。参数width,heightdepth 指定子图像的尺寸。

data 指向的像素数据结构由sourceFormatsourceType 指定。像素数据的上传可选择由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)

这是一个重载函数。

此重载用于更新纹理的一部分。参数xOffset,yOffset,zOffset 指定纹理中的像素偏移。参数width,heightdepth 指定子图像的尺寸。mipLevel 指定了要更新的子图像的 mip 地图级别。

data 指向的像素数据结构由sourceFormatsourceType 指定。像素数据的上传可选择由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)

这是一个重载函数。

此重载用于更新纹理的一部分。参数xOffset,yOffset,zOffset 指定纹理中的像素偏移。参数width,heightdepth 指定子图像的尺寸。mipLevellayer 指定了要更新的子图像的 mip 地图级别和层数。

data 指向的像素数据结构由sourceFormatsourceType 指定。像素数据的上传可选择由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)

这是一个重载函数。

此重载用于更新纹理的一部分。参数xOffset,yOffset,zOffset 指定纹理中的像素偏移。参数widthheightdepth 指定子图像的尺寸。我们要更新的子图像的 mip 贴图层、图层和立方体贴图面由mipLevellayerface 指定。

data 指向的像素数据结构由sourceFormatsourceType 指定。像素数据的上传可选择由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)

这是一个重载函数。

此重载用于更新纹理的一部分。参数xOffset,yOffset,zOffset 指定纹理中的像素偏移。参数width,heightdepth 指定子图像的尺寸。我们要更新的子图像的 mip 贴图层、起始层、立方体贴图面和层数由mipLevel,layer,facelayerCount 指定。

data 所指向的像素数据结构由sourceFormatsourceType 指定。像素数据的上传可选择由options 控制。

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

如果使用的纹理具有深度/模版组合格式,此函数会将访问纹理的哪个分量设置为mode

当参数设置为DepthMode 时,着色器将按照正常方式以单个浮点形式访问深度分量。但当参数设置为StencilMode 时,着色器将访问模版分量。

注意: 此函数对 Mac 和为 OpenGL ES 2 构建的 Qt 没有影响。

另请参见 depthStencilMode()。

void QOpenGLTexture::setFixedSamplePositions(bool fixed)

设置具有多采样功能的纹理目标的采样位置和采样个数是否为fixed 。如果设置为true ,则图像中所有纹理的采样位置和采样个数都相同,且不取决于图像大小或内部格式。应在为纹理分配存储空间之前调用此函数。

对于不支持多重采样的目标,此函数不起作用。

默认值为true

另请参阅 isFixedSamplePositions() 和isStorageAllocated()。

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

将此纹理对象的格式设置为format 。必须在分配纹理存储空间之前调用此函数。

请注意,并非所有格式都受支持。受支持格式的确切集合取决于您的 OpenGL 实现和版本。

另请参阅 format() 和allocateStorage()。

void QOpenGLTexture::setLayers(int layers)

设置要分配存储空间的数组layers 。应在为纹理分配存储空间之前调用此函数。

对于不支持数组层的目标,此函数不起作用。

另请参阅 layers() 和isStorageAllocated()。

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

将细节参数的最小级别设置为min ,最大级别设置为max

注意: 此函数对为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 levelOfDetailRange()、setMinimumLevelOfDetail() 和setMaximumLevelOfDetail()。

void QOpenGLTexture::setLevelofDetailBias(float bias)

将详细程度偏差设置为bias 。细节层次偏差会影响贴图层次的变化点。增加细节偏差值会使整体图像更模糊或更平滑。降低数值则会使整体图像更清晰。

注意: 此函数对为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 levelofDetailBias()。

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

将放大过滤器设置为filter

另请参阅 magnificationFilter()、setMinificationFilter() 和setMinMagFilters()。

void QOpenGLTexture::setMaximumAnisotropy(float anisotropy)

如果您的 OpenGL 实现支持 GL_EXT_texture_filter_anisotropic 扩展,则此函数会将最大各向异性级别设置为anisotropy

另请参见 maximumAnisotropy().

void QOpenGLTexture::setMaximumLevelOfDetail(float value)

将最大细节级别设置为value 。这限制了最低分辨率 mipmap(最高 mipmap 级别)的选择。默认值为 1000。

注意: 此函数对为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 maximumLevelOfDetail()、setMinimumLevelOfDetail() 和setLevelOfDetailRange()。

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

将最小化过滤器设置为minificationFilter ,将放大过滤器设置为magnificationFilter

另请参阅 minMagFilters()、setMinificationFilter() 和setMagnificationFilter()。

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

将用于最小化的过滤器设置为filter

另请参阅 minificationFilter()、setMagnificationFilter() 和setMinMagFilters()。

void QOpenGLTexture::setMinimumLevelOfDetail(float value)

将最小细节级别设置为value 。这将限制选择最高分辨率的 mipmap(最低 mipmap 级别)。默认值为-1000。

注意: 此函数对为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 minimumLevelOfDetail()、setMaximumLevelOfDetail() 和setLevelOfDetailRange()。

void QOpenGLTexture::setMipBaseLevel(int baseLevel)

将用于此纹理的所有纹理查找的基本 mipmap 级别设置为baseLevel

注意: 此函数对为 OpenGL ES 2 构建的 Qt 无效。

另请参阅 mipBaseLevel()、setMipMaxLevel() 和setMipLevelRange()。

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

设置可用于此纹理查找的 mipmap 级别范围,从baseLevelmaxLevel

注意: 此函数对为 OpenGL ES 2 构建的 Qt 无效。

另请参阅 setMipBaseLevel()、setMipMaxLevel() 和mipLevelRange()。

void QOpenGLTexture::setMipLevels(int levels)

对于支持 mipmap 的纹理目标,该函数会设置请求分配存储空间的 mipmaplevels 数量。此函数应在为纹理分配存储空间之前调用。

如果纹理目标不支持 mipmaps,则此函数不起作用。

另请参阅 mipLevels()、maximumMipLevels() 和isStorageAllocated()。

void QOpenGLTexture::setMipMaxLevel(int maxLevel)

将此纹理的所有纹理查找所使用的最大 mipmap 级别设置为maxLevel

注意: 此函数对为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 mipMaxLevel()、setMipBaseLevel() 和setMipLevelRange()。

void QOpenGLTexture::setSamples(int samples)

设置在渲染到具有多采样功能的纹理目标时分配存储空间的samples 数量。应在为纹理分配存储空间之前调用此函数。

对于不支持多重采样的目标,此函数不起作用。

另请参阅 samples() 和isStorageAllocated()。

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

将此纹理对象的尺寸设置为widthheightdepth 。每个维度的默认值都是 1。允许的最大纹理尺寸取决于您的 OpenGL 实现。如果系统资源不足,为小于最大尺寸的纹理分配存储空间仍可能失败。

如果提供的是非幂次的widthheightdepth ,而您的 OpenGL 实现不支持重复非幂次的纹理,那么包模式将自动设置为ClampToEdge

另请参阅 width()、height() 和depth()。

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

GLSL 着色器可以对纹理函数返回的 vec4 分量重新排序。最好还能通过 CPU 端代码控制这种重新排序。从 OpenGL 3.3 开始,swizzle masks 就可以实现这一点。

纹理的每个组件都可以映射到SwizzleValue 选项之一。

此函数将component 映射到输出value

注意: 此函数对 Mac 和为 OpenGL ES 2 构建的 Qt 没有影响。

另请参阅 swizzleMask() 。

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

参数rgba 是用于设置颜色红、绿、蓝和阿尔法值的值。

这是一个重载函数。

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

将所有纹理尺寸的换行(或重复模式)设置为mode

另请参阅 wrapMode() 。

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

设置纹理维度directionmode 的换行(或重复模式)。

这是一个重载函数。

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

返回纹理component 的旋转遮罩。

另请参阅 setSwizzleMask().

QOpenGLTexture::Target QOpenGLTexture::target() const

返回此纹理的绑定目标。

GLuint QOpenGLTexture::textureId() const

返回底层 OpenGL 纹理对象的名称,如果尚未创建,则返回 0。

另请参阅 create()、destroy() 和isCreated()。

int QOpenGLTexture::width() const

返回一维、二维或三维纹理的宽度。

另请参阅 height()、depth() 和setSize()。

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

返回纹理维度direction 的换行模式。

另请参阅 setWrapMode() 。

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