From 098b0e0a9328c00f92d519e39c9b326ab6ce3191 Mon Sep 17 00:00:00 2001 From: puxiao Date: Fri, 12 Apr 2024 17:21:38 +0800 Subject: [PATCH] Update WebGPU.js --- examples/jsm/capabilities/WebGPU.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/jsm/capabilities/WebGPU.js b/examples/jsm/capabilities/WebGPU.js index 53397f44f5cc4a..78f37ea035e68d 100644 --- a/examples/jsm/capabilities/WebGPU.js +++ b/examples/jsm/capabilities/WebGPU.js @@ -4,28 +4,31 @@ if ( self.GPUShaderStage === undefined ) { } -// statics - let isAvailable = navigator.gpu !== undefined; +class WebGPU { -if ( typeof window !== 'undefined' && isAvailable ) { + static isAvailable() { - isAvailable = await navigator.gpu.requestAdapter(); + return isAvailable; -} + } -class WebGPU { + static async getStaticAdapter () { - static isAvailable() { + if ( navigator.gpu ) { - return Boolean( isAvailable ); + const adapter = await navigator.gpu.requestAdapter(); - } + if ( !adapter ) { - static getStaticAdapter() { + isAvailable = false; - return isAvailable; + } + + return adapter; + + } }