Skip to content

Commit 785031e

Browse files
authored
Renderer: Deprecate some async methods. (#32026)
* Renderer: Deprecate some async methods. * Renderer: More deprecation. * Renderer: Simplify code.
1 parent 69317a8 commit 785031e

File tree

7 files changed

+44
-53
lines changed

7 files changed

+44
-53
lines changed

examples/jsm/inspector/Inspector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ class Inspector extends RendererInspector {
168168

169169
renderer.backend.trackTimestamp = true;
170170

171-
renderer.hasFeatureAsync( 'timestamp-query' ).then( ( available ) => {
171+
renderer.init().then( () => {
172172

173-
if ( available !== true ) {
173+
if ( renderer.hasFeature( 'timestamp-query' ) !== true ) {
174174

175175
this.console.addMessage( 'error', 'THREE.Inspector: GPU Timestamp Queries not available.' );
176176

examples/jsm/loaders/KTX2Loader.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,17 @@ class KTX2Loader extends Loader {
194194
* Async version of {@link KTX2Loader#detectSupport}.
195195
*
196196
* @async
197+
* @deprecated
197198
* @param {WebGPURenderer} renderer - The renderer.
198199
* @return {Promise} A Promise that resolves when the support has been detected.
199200
*/
200201
async detectSupportAsync( renderer ) {
201202

202-
this.workerConfig = {
203-
astcSupported: await renderer.hasFeatureAsync( 'texture-compression-astc' ),
204-
astcHDRSupported: false, // https://github.com/gpuweb/gpuweb/issues/3856
205-
etc1Supported: await renderer.hasFeatureAsync( 'texture-compression-etc1' ),
206-
etc2Supported: await renderer.hasFeatureAsync( 'texture-compression-etc2' ),
207-
dxtSupported: await renderer.hasFeatureAsync( 'texture-compression-s3tc' ),
208-
bptcSupported: await renderer.hasFeatureAsync( 'texture-compression-bc' ),
209-
pvrtcSupported: await renderer.hasFeatureAsync( 'texture-compression-pvrtc' )
210-
};
203+
console.warn( 'KTX2Loader: "detectSupportAsync()" has been deprecated. Use "detectSupport()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
211204

212-
return this;
205+
await renderer.init();
206+
207+
return this.detectSupport( renderer );
213208

214209
}
215210

examples/webgpu_loader_gltf_compressed.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@
7070
renderer.toneMappingExposure = 1;
7171
document.body.appendChild( renderer.domElement );
7272

73+
await renderer.init();
74+
7375
const controls = new OrbitControls( camera, renderer.domElement );
7476
controls.minDistance = 3;
7577
controls.maxDistance = 6;
7678
controls.update();
7779

7880
const ktx2Loader = await new KTX2Loader()
7981
.setTranscoderPath( 'jsm/libs/basis/' )
80-
.detectSupportAsync( renderer );
82+
.detectSupport( renderer );
8183

8284
const loader = new GLTFLoader();
8385
loader.setKTX2Loader( ktx2Loader );

examples/webgpu_morphtargets_face.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
const ktx2Loader = await new KTX2Loader()
7575
.setTranscoderPath( 'jsm/libs/basis/' )
76-
.detectSupportAsync( renderer );
76+
.detectSupport( renderer );
7777

7878
new GLTFLoader()
7979
.setKTX2Loader( ktx2Loader )

examples/webgpu_sandbox.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@
5757
renderer.setPixelRatio( window.devicePixelRatio );
5858
renderer.setSize( window.innerWidth, window.innerHeight );
5959
renderer.setAnimationLoop( animate );
60-
document.body.appendChild( renderer.domElement );
61-
6260
renderer.inspector = new Inspector();
61+
document.body.appendChild( renderer.domElement );
62+
63+
await renderer.init();
6364

6465
// textures
6566

@@ -75,7 +76,7 @@
7576

7677
const ktxLoader = await new KTX2Loader()
7778
.setTranscoderPath( 'jsm/libs/basis/' )
78-
.detectSupportAsync( renderer );
79+
.detectSupport( renderer );
7980

8081
const ktxTexture = await ktxLoader.loadAsync( './textures/ktx2/2d_uastc.ktx2' );
8182

examples/webgpu_textures_2d-array_compressed.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@
7373
renderer.setAnimationLoop( animate );
7474
container.appendChild( renderer.domElement );
7575

76+
await renderer.init();
77+
7678
//
7779

7880
const ktx2Loader = new KTX2Loader();
7981
ktx2Loader.setTranscoderPath( 'jsm/libs/basis/' );
80-
await ktx2Loader.detectSupportAsync( renderer );
82+
ktx2Loader.detectSupport( renderer );
8183

8284
ktx2Loader.load( 'textures/spiritedaway.ktx2', function ( texturearray ) {
8385

src/renderers/common/Renderer.js

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,6 @@ class Renderer {
722722
*/
723723
async init() {
724724

725-
if ( this._initialized ) {
726-
727-
throw new Error( 'Renderer: Backend has already been initialized.' );
728-
729-
}
730-
731725
if ( this._initPromise !== null ) {
732726

733727
return this._initPromise;
@@ -2024,16 +2018,12 @@ class Renderer {
20242018
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
20252019
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
20262020
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
2027-
* @return {Promise} A Promise that resolves when the clear operation has been executed.
2028-
* Only returned when the renderer has not been initialized.
20292021
*/
20302022
clear( color = true, depth = true, stencil = true ) {
20312023

20322024
if ( this._initialized === false ) {
20332025

2034-
warn( 'Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead.' );
2035-
2036-
return this.clearAsync( color, depth, stencil );
2026+
throw new Error( 'Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
20372027

20382028
}
20392029

@@ -2074,52 +2064,44 @@ class Renderer {
20742064

20752065
/**
20762066
* Performs a manual clear operation of the color buffer. This method ignores `autoClear` properties.
2077-
*
2078-
* @return {Promise} A Promise that resolves when the clear operation has been executed.
2079-
* Only returned when the renderer has not been initialized.
20802067
*/
20812068
clearColor() {
20822069

2083-
return this.clear( true, false, false );
2070+
this.clear( true, false, false );
20842071

20852072
}
20862073

20872074
/**
20882075
* Performs a manual clear operation of the depth buffer. This method ignores `autoClear` properties.
2089-
*
2090-
* @return {Promise} A Promise that resolves when the clear operation has been executed.
2091-
* Only returned when the renderer has not been initialized.
20922076
*/
20932077
clearDepth() {
20942078

2095-
return this.clear( false, true, false );
2079+
this.clear( false, true, false );
20962080

20972081
}
20982082

20992083
/**
21002084
* Performs a manual clear operation of the stencil buffer. This method ignores `autoClear` properties.
2101-
*
2102-
* @return {Promise} A Promise that resolves when the clear operation has been executed.
2103-
* Only returned when the renderer has not been initialized.
21042085
*/
21052086
clearStencil() {
21062087

2107-
return this.clear( false, false, true );
2088+
this.clear( false, false, true );
21082089

21092090
}
21102091

21112092
/**
21122093
* Async version of {@link Renderer#clear}.
21132094
*
21142095
* @async
2096+
* @deprecated
21152097
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
21162098
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
21172099
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
21182100
* @return {Promise} A Promise that resolves when the clear operation has been executed.
21192101
*/
21202102
async clearAsync( color = true, depth = true, stencil = true ) {
21212103

2122-
if ( this._initialized === false ) await this.init();
2104+
warnOnce( 'Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
21232105

21242106
this.clear( color, depth, stencil );
21252107

@@ -2129,35 +2111,44 @@ class Renderer {
21292111
* Async version of {@link Renderer#clearColor}.
21302112
*
21312113
* @async
2114+
* @deprecated
21322115
* @return {Promise} A Promise that resolves when the clear operation has been executed.
21332116
*/
21342117
async clearColorAsync() {
21352118

2136-
this.clearAsync( true, false, false );
2119+
warnOnce( 'Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
2120+
2121+
this.clear( true, false, false );
21372122

21382123
}
21392124

21402125
/**
21412126
* Async version of {@link Renderer#clearDepth}.
21422127
*
21432128
* @async
2129+
* @deprecated
21442130
* @return {Promise} A Promise that resolves when the clear operation has been executed.
21452131
*/
21462132
async clearDepthAsync() {
21472133

2148-
this.clearAsync( false, true, false );
2134+
warnOnce( 'Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
2135+
2136+
this.clear( false, true, false );
21492137

21502138
}
21512139

21522140
/**
21532141
* Async version of {@link Renderer#clearStencil}.
21542142
*
21552143
* @async
2144+
* @deprecated
21562145
* @return {Promise} A Promise that resolves when the clear operation has been executed.
21572146
*/
21582147
async clearStencilAsync() {
21592148

2160-
this.clearAsync( false, false, true );
2149+
warnOnce( 'Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
2150+
2151+
this.clear( false, false, true );
21612152

21622153
}
21632154

@@ -2550,14 +2541,15 @@ class Renderer {
25502541
* Checks if the given feature is supported by the selected backend.
25512542
*
25522543
* @async
2544+
* @deprecated
25532545
* @param {string} name - The feature's name.
25542546
* @return {Promise<boolean>} A Promise that resolves with a bool that indicates whether the feature is supported or not.
25552547
*/
25562548
async hasFeatureAsync( name ) {
25572549

2558-
if ( this._initialized === false ) await this.init();
2550+
warnOnce( 'Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
25592551

2560-
return this.backend.hasFeature( name );
2552+
return this.hasFeature( name );
25612553

25622554
}
25632555

@@ -2580,9 +2572,7 @@ class Renderer {
25802572

25812573
if ( this._initialized === false ) {
25822574

2583-
warn( 'Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead.' );
2584-
2585-
return false;
2575+
throw new Error( 'Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
25862576

25872577
}
25882578

@@ -2606,14 +2596,15 @@ class Renderer {
26062596
* (which can cause noticeable lags due to decode and GPU upload overhead).
26072597
*
26082598
* @async
2599+
* @deprecated
26092600
* @param {Texture} texture - The texture.
26102601
* @return {Promise} A Promise that resolves when the texture has been initialized.
26112602
*/
26122603
async initTextureAsync( texture ) {
26132604

2614-
if ( this._initialized === false ) await this.init();
2605+
warnOnce( 'Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
26152606

2616-
this._textures.updateTexture( texture );
2607+
this.initTexture( texture );
26172608

26182609
}
26192610

@@ -2629,7 +2620,7 @@ class Renderer {
26292620

26302621
if ( this._initialized === false ) {
26312622

2632-
warn( 'Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead.' );
2623+
throw new Error( 'Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
26332624

26342625
}
26352626

0 commit comments

Comments
 (0)