官方文档:https://docs.gl/es2/glCompressedTexImage2D
一、描述
指定一个压缩格式的二维纹理。
specify a two-dimensional texture image in a compressed format.
纹理将指定纹理图像的一部分映射到纹理处于活动状态的每个图形基元上。当前片段着色器或顶点着色器使用内置纹理查找功能时,纹理处于活动状态。
glCompressedTexImage2D使用来自客户端内存的压缩图像数据定义二维纹理图像或立方体贴图纹理图像。根据定义指定内部格式的扩展规范来解码纹理图像。OpenGL ES没有定义特定的压缩纹理格式,但确实提供了一种机制来获取扩展提供的这种格式的符号常量。通过查询GL_NUM_COMPRESSED_TEXTURE_FORMATS的值可以获得支持的压缩纹理格式的数量。支持的特定压缩纹理格式列表可以通过查询GL_COMPRESSED_TEXTURE_FORMATS的值来获得。
二、C函数
void glCompressedTexImage2D(
GLenum target,
GLint level,
GLenum internalformat,
GLsizei width,
GLsizei height,
GLint border,
GLsizei imageSize,
const GLvoid * data);
参数_target
Specifies the target texture of the active texture unit. Must be:
- GL_TEXTURE_2D
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
- GL_TEXTURE_CUBE_MAP_NEGATIVE_X
- GL_TEXTURE_CUBE_MAP_POSITIVE_Y
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
- GL_TEXTURE_CUBE_MAP_POSITIVE_Z
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
参数_level
Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.参数_internalformat
Specifies the format of the compressed image data stored at address data.参数_width/height
Specifies the width/height of the texture image. All implementations support 2D texture images that are at least 64 texels wide/high and cube-mapped texture images that are at least 16 texels wide/high.参数_border
Specifies the width of the border. Must be 0.参数_imageSize
Specifies the number of unsigned bytes of image data starting at the address specified by data.参数_data
Specifies a pointer to the compressed image data in memory.三、错误
GL_INVALID_ENUM
generated iftarget
is notGL_TEXTURE_2D
,GL_TEXTURE_CUBE_MAP_POSITIVE_X
,GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
.
generated if internalformat
is not a supported format returned in GL_COMPRESSED_TEXTURE_FORMATS
.
GL_INVALID_VALUE
generated if level
is less than 0.
may be generated if level
is greater than [Math Processing Error]log2max, where [Math Processing Error]max is the returned value of GL_MAX_TEXTURE_SIZE
when target
is GL_TEXTURE_2D
or GL_MAX_CUBE_MAP_TEXTURE_SIZE
when target
is not GL_TEXTURE_2D
.
generated if width
or height
is less than 0 or greater than GL_MAX_TEXTURE_SIZE
when target
is GL_TEXTURE_2D
or GL_MAX_CUBE_MAP_TEXTURE_SIZE
when target
is not GL_TEXTURE_2D
.
generated if border
is not 0.
generated if imageSize
is not consistent with the format, dimensions, and contents of the specified compressed image data.
GL_INVALID_OPERATION
generated if parameter combinations are not supported by the specific compressed internal format as specified in the specific texture compression extension.
特定纹理压缩扩展中指定的特定压缩内部格式不支持参数组合。
Undefined results
including abnormal program termination.
generated if data is not encoded in a manner consistent with the extension specification defining the internal compression format.
如果数据的编码方式与定义内部压缩格式的扩展规范不一致,则会生成未定义的结果,包括异常的程序终止。