WebGLRenderingContext.compressedTexSubImage2D()
compressedTexSubImage2D办法以压缩格式为纹理图片指定的二维子矩形(sub-rectangle)。
使用此方法之前,压缩的图像格式必须通过WebGL extension是可用的,或者必须使用WebGL2RenderingContext。
语法
void gl.compressedTexSubImage2D(target, level, internalformat, width, height, border,
ArrayBufferView? pixels);
参数
target
GLenum类型,指定压缩纹理(active compressed texture)的绑定点(目标)。可能的值如下:
gl.TEXTURE_2D:一个二进制纹理。
gl.TEXTURE_CUBE_MAP_POSITIVE_X:立方体映射的X正方向的面。
gl.TEXTURE_CUBE_MAP_NEGATIVE_X :立方体映射的X负方向的面。
gl.TEXTURE_CUBE_MAP_POSITIVE_Y :立方体映射的Y正方向的面。
gl.TEXTURE_CUBE_MAP_NEGATIVE_Y :立方体映射的Y负方向的面。
gl.TEXTURE_CUBE_MAP_POSITIVE_Z :立方体映射的Z正方向的面。
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z :立方体映射的Z负方向的面。
level
GLint类型, 指定详细的程度。0级是基本图像水平,n级为第n的mipmap降低级别。
xoffset
GLint类型,指定压缩纹理图像中的水平偏移。
yoffset
GLint类型,指定压缩纹理图像中的垂直偏移。
width
GLsizei类型,指定压缩纹理的宽度。
height
GLsizei类型,指定压缩纹理的高度。
format
GLenum类型,指定压缩图像格式。在使用此方法之前,压缩图像格式必须是通过WebGL extensions可用的。可能的值有:
当使用WEBGL_compressed_texture_s3tc拓展:
ext.COMPRESSED_RGB_S3TC_DXT1_EXT
ext.COMPRESSED_RGBA_S3TC_DXT1_EXT
ext.COMPRESSED_RGBA_S3TC_DXT3_EXT
ext.COMPRESSED_RGBA_S3TC_DXT5_EXT
当使用WEBGL_compressed_texture_es3拓展:
ext.COMPRESSED_R11_EAC
ext.COMPRESSED_SIGNED_R11_EAC
ext.COMPRESSED_RG11_EAC
ext.COMPRESSED_SIGNED_RG11_EAC
ext.COMPRESSED_RGB8_ETC2
ext.COMPRESSED_RGBA8_ETC2_EAC
ext.COMPRESSED_SRGB8_ETC2
ext.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
ext.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
ext.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
当使用WEBGL_compressed_texture_pvrtc拓展:
ext.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
ext.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
ext.COMPRESSED_RGB_PVRTC_2BPPV1_IMG
ext.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
当使用WEBGL_compressed_texture_atc拓展:
ext.COMPRESSED_RGB_ATC_WEBGL
ext.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL
ext.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
当使用WebGL 2 背景,下列的值可用:
gl.COMPRESSED_R11_EAC
gl.COMPRESSED_SIGNED_R11_EAC
gl.COMPRESSED_RG11_EAC
gl.COMPRESSED_SIGNED_RG11_EAC
gl.COMPRESSED_RGB8_ETC2
gl.COMPRESSED_RGBA8_ETC2_EAC
gl.COMPRESSED_SRGB8_ETC2
gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
gl.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
gl.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
pixels
ArrayBufferView类型,作为 在存储器中的压缩图像数据的数据存储。
返回值
无
例子
var ext = (
gl.getExtension("WEBGL_compressed_texture_s3tc") ||
gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") ||
gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc")
);
gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 256, 256, 512, 512, ext.COMPRESSED_RGBA_S3TC_DXT5_EXT, textureData);
规范
浏览器兼容
Desktop:Chrome 9、 Edge 12、Firefox 4.0 、 Internet Explorer 11 、Opera 12、Safari 5.1;
Mobile: Android ?、 Chrome for Android 25、 Firefox Mobile 4.0、Firefox OS 1.0、 IE Mobile ?、 Opera Mobile 12、 Safari Mobile 8.0;
Chrome、FireFox 发行版本需要在偏好设置启用WebGL2。