Просмотр исходного кода

Wait for device initialization in hasFeatureAsync() (#28218)

sunag 1 год назад
Родитель
Сommit
20019c3a43

+ 12 - 2
examples/jsm/renderers/common/Renderer.js

@@ -1054,14 +1054,24 @@ class Renderer {
 
 	}
 
-	hasFeatureAsync( name ) {
+	async hasFeatureAsync( name ) {
 
-		return this.backend.hasFeatureAsync( name );
+		if ( this._initialized === false ) await this.init();
+
+		return this.backend.hasFeature( name );
 
 	}
 
 	hasFeature( name ) {
 
+		if ( this._initialized === false ) {
+
+			console.warn( 'THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead.' );
+
+			return false;
+
+		}
+
 		return this.backend.hasFeature( name );
 
 	}

+ 0 - 7
examples/jsm/renderers/webgl/WebGLBackend.js

@@ -1108,12 +1108,6 @@ class WebGLBackend extends Backend {
 
 	}
 
-	async hasFeatureAsync( name ) {
-
-		return this.hasFeature( name );
-
-	}
-
 	hasFeature( name ) {
 
 		const keysMatching = Object.keys( GLFeatureName ).filter( key => GLFeatureName[ key ] === name );
@@ -1122,7 +1116,6 @@ class WebGLBackend extends Backend {
 
 		for ( let i = 0; i < keysMatching.length; i ++ ) {
 
-
 			if ( extensions.has( keysMatching[ i ] ) ) return true;
 
 		}

+ 1 - 22
examples/jsm/renderers/webgpu/WebGPUBackend.js

@@ -14,7 +14,6 @@ import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
 import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
 import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
 import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
-import WebGPU from '../../capabilities/WebGPU.js';
 
 //
 
@@ -1230,29 +1229,9 @@ class WebGPUBackend extends Backend {
 
 	}
 
-	async hasFeatureAsync( name ) {
-
-		const device = this.device || await WebGPU.getStaticAdapter();
-
-		//
-
-		return device.features.has( name );
-
-	}
-
 	hasFeature( name ) {
 
-		const device = this.device;
-
-		if ( ! device ) {
-
-			console.warn( 'WebGPUBackend: WebGPU device has not been initialized yet. Please use hasFeatureAsync() instead.' );
-
-			return false;
-
-		}
-
-		return device.features.has( name );
+		return this.device.features.has( name );
 
 	}