From 4e9ea0aee6b6d1d246d9af6c46b052916eae3f6b Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Wed, 10 Apr 2019 17:03:13 +0800 Subject: [PATCH] add compressed texture feature to device --- cocos/gfx/define.ts | 11 ++++++++ cocos/gfx/device.ts | 4 +++ cocos/gfx/webgl/WebGL.d.ts | 25 +++++++++++++++++ cocos/gfx/webgl/webgl-commands.ts | 10 +++++++ cocos/gfx/webgl/webgl-device.ts | 37 +++++++++++++++++++++++++ cocos/gfx/webgl2/webgl2-commands.ts | 11 +++++++- cocos/gfx/webgl2/webgl2-device.ts | 42 +++++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 cocos/gfx/webgl/WebGL.d.ts diff --git a/cocos/gfx/define.ts b/cocos/gfx/define.ts index 11b2766967..fbf1f07aa0 100644 --- a/cocos/gfx/define.ts +++ b/cocos/gfx/define.ts @@ -16,6 +16,17 @@ export enum WebGLEXT { COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03, COMPRESSED_RGB_ETC1_WEBGL = 0x8D64, + + COMPRESSED_R11_EAC = 0x9270, + COMPRESSED_SIGNED_R11_EAC = 0x9271, + COMPRESSED_RG11_EAC = 0x9272, + COMPRESSED_SIGNED_RG11_EAC = 0x9273, + COMPRESSED_RGB8_ETC2 = 0x9274, + COMPRESSED_SRGB8_ETC2 = 0x9275, + COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276, + COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277, + COMPRESSED_RGBA8_ETC2_EAC = 0x9278, + COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279, } export const GFX_MAX_VERTEX_ATTRIBUTES: number = 16; diff --git a/cocos/gfx/device.ts b/cocos/gfx/device.ts index dfcb010790..43d343b066 100644 --- a/cocos/gfx/device.ts +++ b/cocos/gfx/device.ts @@ -26,6 +26,10 @@ export enum GFXFeature { TEXTURE_HALF_FLOAT, FORMAT_R11G11B10F, FORMAT_D24S8, + FORMAT_ETC1, + FORMAT_ETC2, + FORMAT_DXT, + FORMAT_PVRTC, MSAA, COUNT, } diff --git a/cocos/gfx/webgl/WebGL.d.ts b/cocos/gfx/webgl/WebGL.d.ts new file mode 100644 index 0000000000..03d5fac310 --- /dev/null +++ b/cocos/gfx/webgl/WebGL.d.ts @@ -0,0 +1,25 @@ + +// note that ETC1 is not supported with the compressedTexSubImage2D() method +interface WEBGL_compressed_texture_etc1 { + readonly COMPRESSED_RGB_ETC1_WEBGL: GLenum; +} + +interface WEBGL_compressed_texture_etc { + readonly COMPRESSED_R11_EAC: GLenum; + readonly COMPRESSED_SIGNED_R11_EAC: GLenum; + readonly COMPRESSED_RG11_EAC: GLenum; + readonly COMPRESSED_SIGNED_RG11_EAC: GLenum; + readonly COMPRESSED_RGB8_ETC2: GLenum; + readonly COMPRESSED_RGBA8_ETC2_EAC: GLenum; + readonly COMPRESSED_SRGB8_ETC2: GLenum; + readonly COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: GLenum; + readonly COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum; + readonly COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: GLenum; +} + +interface WEBGL_compressed_texture_pvrtc { + readonly COMPRESSED_RGB_PVRTC_4BPPV1_IMG: GLenum; + readonly COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: GLenum; + readonly COMPRESSED_RGB_PVRTC_2BPPV1_IMG: GLenum; + readonly COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: GLenum; +} \ No newline at end of file diff --git a/cocos/gfx/webgl/webgl-commands.ts b/cocos/gfx/webgl/webgl-commands.ts index bf3b0b5b4a..c2e47cc03a 100644 --- a/cocos/gfx/webgl/webgl-commands.ts +++ b/cocos/gfx/webgl/webgl-commands.ts @@ -234,6 +234,16 @@ function GFXFormatToWebGLFormat (format: GFXFormat): GLenum { case GFXFormat.BC3_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; case GFXFormat.ETC_RGB8: return WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL; + case GFXFormat.ETC2_RGB8: return WebGLEXT.COMPRESSED_RGB8_ETC2; + case GFXFormat.ETC2_SRGB8: return WebGLEXT.COMPRESSED_SRGB8_ETC2; + case GFXFormat.ETC2_RGB8_A1: return WebGLEXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case GFXFormat.ETC2_SRGB8_A1: return WebGLEXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case GFXFormat.ETC2_RGBA8: return WebGLEXT.COMPRESSED_RGBA8_ETC2_EAC; + case GFXFormat.ETC2_SRGB8_A8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + case GFXFormat.EAC_R11: return WebGLEXT.COMPRESSED_R11_EAC; + case GFXFormat.EAC_R11SN: return WebGLEXT.COMPRESSED_SIGNED_R11_EAC; + case GFXFormat.EAC_RG11: return WebGLEXT.COMPRESSED_RG11_EAC; + case GFXFormat.EAC_RG11SN: return WebGLEXT.COMPRESSED_SIGNED_RG11_EAC; case GFXFormat.PVRTC_RGB2: return WebGLEXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; case GFXFormat.PVRTC_RGBA2: return WebGLEXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; diff --git a/cocos/gfx/webgl/webgl-device.ts b/cocos/gfx/webgl/webgl-device.ts index 25244defc3..95e89e82fa 100644 --- a/cocos/gfx/webgl/webgl-device.ts +++ b/cocos/gfx/webgl/webgl-device.ts @@ -89,6 +89,14 @@ export class WebGLGFXDevice extends GFXDevice { return this._WEBGL_color_buffer_float; } + public get WEBGL_compressed_texture_etc1 (): WEBGL_compressed_texture_etc1 | null { + return this._WEBGL_compressed_texture_etc1; + } + + public get WEBGL_compressed_texture_pvrtc (): WEBGL_compressed_texture_pvrtc | null { + return this._WEBGL_compressed_texture_pvrtc; + } + public get WEBGL_compressed_texture_astc (): WEBGL_compressed_texture_astc | null { return this._WEBGL_compressed_texture_astc; } @@ -160,6 +168,9 @@ export class WebGLGFXDevice extends GFXDevice { private _EXT_sRGB: EXT_sRGB | null = null; private _OES_vertex_array_object: OES_vertex_array_object | null = null; private _WEBGL_color_buffer_float: WEBGL_color_buffer_float | null = null; + private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null; + private _WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null = null; + private _WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null = null; private _WEBGL_compressed_texture_astc: WEBGL_compressed_texture_astc | null = null; private _WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null = null; private _WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null = null; @@ -273,6 +284,9 @@ export class WebGLGFXDevice extends GFXDevice { this._EXT_sRGB = gl.getExtension('EXT_sRGB'); this._OES_vertex_array_object = gl.getExtension('OES_vertex_array_object'); this._WEBGL_color_buffer_float = gl.getExtension('WEBGL_color_buffer_float'); + this._WEBGL_compressed_texture_etc1 = gl.getExtension('WEBGL_compressed_texture_etc1'); + this._WEBGL_compressed_texture_etc = gl.getExtension('WEBGL_compressed_texture_etc'); + this._WEBGL_compressed_texture_pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc'); this._WEBGL_compressed_texture_astc = gl.getExtension('WEBGL_compressed_texture_astc'); this._WEBGL_compressed_texture_s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc'); this._WEBGL_compressed_texture_s3tc_srgb = gl.getExtension('WEBGL_compressed_texture_s3tc_srgb'); @@ -300,6 +314,28 @@ export class WebGLGFXDevice extends GFXDevice { this._features[GFXFeature.FORMAT_D24S8] = true; } + let compressedFormat: string = ''; + + if (this._WEBGL_compressed_texture_etc1) { + this._features[GFXFeature.FORMAT_ETC1] = true; + compressedFormat += 'etc1 '; + } + + if (this._WEBGL_compressed_texture_etc) { + this._features[GFXFeature.FORMAT_ETC2] = true; + compressedFormat += 'etc2 '; + } + + if (this._WEBGL_compressed_texture_s3tc) { + this._features[GFXFeature.FORMAT_DXT] = true; + compressedFormat += 'dxt '; + } + + if (this._WEBGL_compressed_texture_pvrtc) { + this._features[GFXFeature.FORMAT_PVRTC] = true; + compressedFormat += 'pvrtc '; + } + this._features[GFXFeature.MSAA] = false; if (this._OES_vertex_array_object) { @@ -325,6 +361,7 @@ export class WebGLGFXDevice extends GFXDevice { console.info('MAX_TEXTURE_MAX_ANISOTROPY_EXT: ' + this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT); } console.info('USE_VAO: ' + this._useVAO); + console.info('COMPRESSED_FORMAT: ' + compressedFormat); // init states this.initStates(gl); diff --git a/cocos/gfx/webgl2/webgl2-commands.ts b/cocos/gfx/webgl2/webgl2-commands.ts index f1737da981..fd0033a44f 100644 --- a/cocos/gfx/webgl2/webgl2-commands.ts +++ b/cocos/gfx/webgl2/webgl2-commands.ts @@ -248,7 +248,16 @@ function GFXFormatToWebGLInternalFormat (format: GFXFormat): GLenum { case GFXFormat.BC3_SRGB: return WebGLEXT.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; case GFXFormat.ETC_RGB8: return WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL; - case GFXFormat.ETC2_RGB8: return WebGLEXT.COMPRESSED_RGB_ETC1_WEBGL; + case GFXFormat.ETC2_RGB8: return WebGLEXT.COMPRESSED_RGB8_ETC2; + case GFXFormat.ETC2_SRGB8: return WebGLEXT.COMPRESSED_SRGB8_ETC2; + case GFXFormat.ETC2_RGB8_A1: return WebGLEXT.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case GFXFormat.ETC2_SRGB8_A1: return WebGLEXT.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; + case GFXFormat.ETC2_RGBA8: return WebGLEXT.COMPRESSED_RGBA8_ETC2_EAC; + case GFXFormat.ETC2_SRGB8_A8: return WebGLEXT.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; + case GFXFormat.EAC_R11: return WebGLEXT.COMPRESSED_R11_EAC; + case GFXFormat.EAC_R11SN: return WebGLEXT.COMPRESSED_SIGNED_R11_EAC; + case GFXFormat.EAC_RG11: return WebGLEXT.COMPRESSED_RG11_EAC; + case GFXFormat.EAC_RG11SN: return WebGLEXT.COMPRESSED_SIGNED_RG11_EAC; case GFXFormat.PVRTC_RGB2: return WebGLEXT.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; case GFXFormat.PVRTC_RGBA2: return WebGLEXT.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; diff --git a/cocos/gfx/webgl2/webgl2-device.ts b/cocos/gfx/webgl2/webgl2-device.ts index c96e75c711..14a55814f9 100644 --- a/cocos/gfx/webgl2/webgl2-device.ts +++ b/cocos/gfx/webgl2/webgl2-device.ts @@ -77,6 +77,18 @@ export class WebGL2GFXDevice extends GFXDevice { return this._EXT_disjoint_timer_query_webgl2; } + public get WEBGL_compressed_texture_etc1 (): WEBGL_compressed_texture_etc1 | null { + return this._WEBGL_compressed_texture_etc1; + } + + public get WEBGL_compressed_texture_etc (): WEBGL_compressed_texture_etc | null { + return this._WEBGL_compressed_texture_etc; + } + + public get WEBGL_compressed_texture_pvrtc (): WEBGL_compressed_texture_pvrtc | null { + return this._WEBGL_compressed_texture_pvrtc; + } + public get WEBGL_compressed_texture_s3tc (): WEBGL_compressed_texture_s3tc | null { return this._WEBGL_compressed_texture_s3tc; } @@ -99,6 +111,9 @@ export class WebGL2GFXDevice extends GFXDevice { private _OES_texture_float_linear: OES_texture_float_linear | null = null; private _EXT_color_buffer_float: EXT_color_buffer_float | null = null; private _EXT_disjoint_timer_query_webgl2: EXT_disjoint_timer_query_webgl2 | null = null; + private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null; + private _WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null = null; + private _WEBGL_compressed_texture_pvrtc: WEBGL_compressed_texture_pvrtc | null = null; private _WEBGL_compressed_texture_s3tc: WEBGL_compressed_texture_s3tc | null = null; private _WEBGL_compressed_texture_s3tc_srgb: WEBGL_compressed_texture_s3tc_srgb | null = null; private _WEBGL_debug_renderer_info: WEBGL_debug_renderer_info | null = null; @@ -214,6 +229,9 @@ export class WebGL2GFXDevice extends GFXDevice { this._EXT_color_buffer_float = gl.getExtension('EXT_color_buffer_float'); this._EXT_disjoint_timer_query_webgl2 = gl.getExtension('EXT_disjoint_timer_query_webgl2'); this._OES_texture_float_linear = gl.getExtension('OES_texture_float_linear'); + this._WEBGL_compressed_texture_etc1 = gl.getExtension('WEBGL_compressed_texture_etc1'); + this._WEBGL_compressed_texture_etc = gl.getExtension('WEBGL_compressed_texture_etc'); + this._WEBGL_compressed_texture_pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc'); this._WEBGL_compressed_texture_s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc'); this._WEBGL_compressed_texture_s3tc_srgb = gl.getExtension('WEBGL_compressed_texture_s3tc_srgb'); this._WEBGL_texture_storage_multisample = gl.getExtension('WEBGL_texture_storage_multisample'); @@ -225,8 +243,31 @@ export class WebGL2GFXDevice extends GFXDevice { this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true; this._features[GFXFeature.FORMAT_R11G11B10F] = true; this._features[GFXFeature.FORMAT_D24S8] = true; + this._features[GFXFeature.FORMAT_ETC2] = true; this._features[GFXFeature.MSAA] = true; + let compressedFormat: string = ''; + + if (this._WEBGL_compressed_texture_etc1) { + this._features[GFXFeature.FORMAT_ETC1] = true; + compressedFormat += 'etc1 '; + } + + if (this._WEBGL_compressed_texture_etc) { + this._features[GFXFeature.FORMAT_ETC2] = true; + compressedFormat += 'etc2 '; + } + + if (this._WEBGL_compressed_texture_s3tc) { + this._features[GFXFeature.FORMAT_DXT] = true; + compressedFormat += 'dxt '; + } + + if (this._WEBGL_compressed_texture_pvrtc) { + this._features[GFXFeature.FORMAT_PVRTC] = true; + compressedFormat += 'pvrtc '; + } + console.info('RENDERER: ' + this._renderer); console.info('VENDOR: ' + this._vendor); console.info('VERSION: ' + this._version); @@ -250,6 +291,7 @@ export class WebGL2GFXDevice extends GFXDevice { console.info('MAX_TEXTURE_MAX_ANISOTROPY_EXT: ' + this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT); } console.info('USE_VAO: ' + this._useVAO); + console.info('COMPRESSED_FORMAT: ' + compressedFormat); // init states this.initStates(gl);