From e7fc4391990c121ee9950d3b97493adff1033012 Mon Sep 17 00:00:00 2001 From: shrekshao Date: Mon, 13 May 2019 18:39:37 -0700 Subject: [PATCH] wip: pvrtc --- webgl/gltf-demo/README.md | 2 ++ webgl/gltf-demo/index.html | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/webgl/gltf-demo/README.md b/webgl/gltf-demo/README.md index 3f28c45..111a377 100644 --- a/webgl/gltf-demo/README.md +++ b/webgl/gltf-demo/README.md @@ -6,6 +6,8 @@ A WebGL demo rendering a glTF 3D model with `.basis` texture files transcoded in * ETC1 * TODO: PVRTC +Note the glTF model is using a temperoray hypothetical extension at this moment. It should rely on a KTX2 wrapper when offically released. + ## Run on PC Launuch an http server under `webgl/gltf-demo/`. For example if you have node installed you can install `http-server` globally and run diff --git a/webgl/gltf-demo/index.html b/webgl/gltf-demo/index.html index d118afc..4ba39b5 100644 --- a/webgl/gltf-demo/index.html +++ b/webgl/gltf-demo/index.html @@ -92,8 +92,14 @@ const etcSupported = renderer.context.getExtension('WEBGL_compressed_texture_etc1'); const dxtSupported = renderer.context.getExtension('WEBGL_compressed_texture_s3tc'); + const pvrtcSupported = renderer.context.getExtension('WEBGL_compressed_texture_pvrtc'); - let format = etcSupported ? BASIS_FORMAT.cTFETC1 : BASIS_FORMAT.cTFBC1; + if (!etcSupported && !dxtSupported && !pvrtcSupported) { + log('No suitable compressed texture format supported!!'); + return; + } + + let format = etcSupported ? BASIS_FORMAT.cTFETC1 : (dxtSupported ? BASIS_FORMAT.cTFBC1 : BASIS_FORMAT.cTFPVRTC1_4_OPAQUE_ONLY); log('Transcode to Compressed Texture Format: ' + BASIS_FORMAT_NAMES[format] + ''); @@ -152,14 +158,14 @@ const mipmaps = [ { data: dst, width, height } ]; let texture; - if (!etcSupported) { - const type = dxtSupported ? THREE.UnsignedByteType : THREE.UnsignedShort565Type; - - const f = dxtSupported ? DXT_FORMAT_MAP[ format ] : THREE.RGBFormat; - - texture = new THREE.CompressedTexture( mipmaps, width, height, f, type ); - } else { + if (etcSupported) { texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.RGB_ETC1_Format ); + } else if (dxtSupported) { + const type = dxtSupported ? THREE.UnsignedByteType : THREE.UnsignedShort565Type; + const f = dxtSupported ? DXT_FORMAT_MAP[ format ] : THREE.RGBFormat; + texture = new THREE.CompressedTexture( mipmaps, width, height, f, type ); + } else if (pvrtcSupported) { + texture = new THREE.CompressedTexture( mipmaps, width, height, THREE.THREE.RGB_PVRTC_4BPPV1_Format ); } texture.minFilter = THREE.LinearFilter;