压缩纹理图像 Compressed Texture Images
纹理图像也可以使用已存储在已知压缩图像格式中的图像数据来指定或修改,这些格式包括附录D中定义的格式以及由扩展定义的任何额外格式。
void glCompressedTexImage1D( enum target, int level, enum internalformat, sizei width, int border, sizei imageSize, const void *data );
void glCompressedTexImage2D( enum target, int level, enum internalformat, sizei width, sizei height, int border, sizei imageSize, const void *data );
void glCompressedTexImage3D( enum target, int level, enum internalformat, sizei width, sizei height, sizei depth, int border, sizei imageSize, const void *data );
分别定义了一维、二维和三维纹理图像,其中传入的数据以特定压缩图像格式存储。target、level、internalformat、width、height、depth和border参数的含义与TexImage1D、TexImage2D和TexImage3D中的相同,但不支持压缩矩形纹理格式。data参数是指向对应于internalformat的特定压缩图像格式存储的压缩图像数据。
如果绑定了像素解包缓冲区(通过PIXEL_UNPACK_BUFFER_BINDING非零值表示),则data是像素解包缓冲区中的偏移量,并且根据此偏移量从缓冲区中读取压缩数据;否则,data是一个指向客户端内存的指针,并从该指针相对应的客户端内存中读取压缩数据。
压缩图像将根据定义internalformat标记的规范进行解码。压缩纹理图像被视为相对于data的一个大小为imageSize字节的ubytes数组。
如果压缩图像未按照定义的图像格式编码,则调用结果未定义。
如果压缩数据按固定大小的纹理块排列,可以使用像素存储模式来选择来自较大包含矩形的子矩形。这些像素存储模式在工作方式上与TexImage*D相同,并如第8.4.4节所述。在本节剩余部分,用blocksize、bw、bh和bd分别表示像素存储模式UNPACK_COMPRESSED_BLOCK_SIZE、UNPACK_COMPRESSED_BLOCK_WIDTH、UNPACK_COMPRESSED_BLOCK_HEIGHT和UNPACK_COMPRESSED_BLOCK_DEPTH的值。blocksize是以字节为单位的压缩块大小;bw、bh和bd分别是压缩块的宽度、高度和深度(以像素为单位)。
默认情况下,对于压缩图像会忽略像素存储模式UNPACK_ROW_LENGTH、UNPACK_SKIP_ROWS、UNPACK_SKIP_PIXELS、UNPACK_IMAGE_HEIGHT和UNPACK_SKIP_IMAGES。要启用UNPACK_SKIP_PIXELS和UNPACK_ROW_LENGTH,blocksize和bw都必须不为零。若还要启用UNPACK_SKIP_ROWS和UNPACK_IMAGE_HEIGHT,则bh必须不为零。若还希望启用UNPACK_SKIP_IMAGES,则bd必须不为零。所有参数必须与压缩格式一致才能获得期望的结果。
如果CompressedTexImage1D、CompressedTexImage2D或CompressedTexImage3D函数的数据参数data为NULL,并且像素解包缓冲对象为零,则会创建一个具有未指定图像内容的纹理图像,就像将NULL指针传递给TexImage1D、TexImage2D或TexImage3D时一样。
要仅使用特定压缩图像格式存储的输入数据重新指定纹理对象纹理图像的矩形子区域,请使用以下命令:
void glCompressedTexSubImage1D( enum target, int level, int xoffset, sizei width, enum format, sizei imageSize, const void *data );
void glCompressedTexSubImage2D( enum target, int level, int xoffset, int yoffset, sizei width, sizei height, enum format, sizei imageSize, const void *data );
void glCompressedTexSubImage3D( enum target, int level, int xoffset, int yoffset, int zoffset, sizei width, sizei height, sizei depth, enum format, sizei imageSize, const void *data );void glCompressedTextureSubImage1D( uint texture, int level, int xoffset, sizei width, enum format, sizei imageSize, const void *data );
void glCompressedTextureSubImage2D( uint texture, int level, int xoffset, int yoffset, sizei width, sizei height, enum format, sizei imageSize, const void *data );
void glCompressedTextureSubImage3D( uint texture, int level, int xoffset, int yoffset, int zoffset, sizei width, sizei height, sizei depth, enum format, sizei imageSize, const void *data );
target、texture、level、xoffset、yoffset、zoffset、width、height和depth参数与第8.6节中对应的不含“Compressed”前缀的命令中的含义相同(在这些参数出现的情况下)。data指向以format所对应的压缩图像格式存储的压缩图像数据。
指向由data和imageSize参数表示的图像被视为提供给CompressedTexImage1D、CompressedTexImage2D和CompressedTexImage3D的情况进行解释。
特定压缩内部格式施加的任何限制都是不变的,这意味着如果GL接受并以压缩形式存储纹理图像,在满足以下条件时,向CompressedTex*Image*提供相同的图像不会生成错误:
data指向由GetCompressedTexImage(第8.11节)返回的压缩纹理图像。target、level和format与向返回data的GetCompressedTexImage调用提供的target、level和format参数相匹配。width、height、depth、format和imageSize分别与TEXTURE_WIDTH、TEXTURE_HEIGHT、TEXTURE_DEPTH、TEXTURE_INTERNAL_FORMAT以及在返回data时有效图像级别level的TEXTURE_COMPRESSED_IMAGE_SIZE值相匹配。width、height、depth和format与当前有效图像级别level下的TEXTURE_WIDTH、TEXTURE_HEIGHT、TEXTURE_DEPTH和TEXTURE_INTERNAL_FORMAT值相匹配。xoffset、yoffset和zoffset均为零。
这个保证不仅适用于由GetCompressedTexImage返回的图像,而且也适用于任何其他同样大小的正确编码的压缩纹理图像。
若修改的图像内部格式是Table 8.14中描述的具体压缩格式之一,则纹理将以相应的纹理图像编码方式存储(参见附录D)。
由于这些特定压缩格式可以轻松地沿4×4纹理单元边界编辑,因此对于CompressedTex*SubImage2D和CompressedTex*SubImage3D,对子图像位置和尺寸的限制有所放宽。
在执行CompressedTex*SubImage*调用期间,对于这些具体压缩格式的压缩纹理图像中不与正在修改区域相交的任何4×4纹理单元块,其内容都会被保留。