|
@@ -1,4 +1,5 @@
|
|
|
import { GPUIndexFormat, GPUTextureFormat, GPUStoreOp } from './constants.js';
|
|
|
+import WebGPUAnimation from './WebGPUAnimation.js';
|
|
|
import WebGPUObjects from './WebGPUObjects.js';
|
|
|
import WebGPUAttributes from './WebGPUAttributes.js';
|
|
|
import WebGPUGeometries from './WebGPUGeometries.js';
|
|
@@ -132,6 +133,8 @@ class WebGPURenderer {
|
|
|
this._textures = null;
|
|
|
this._background = null;
|
|
|
|
|
|
+ this._animation = new WebGPUAnimation();
|
|
|
+
|
|
|
this._renderPassDescriptor = null;
|
|
|
|
|
|
this._currentRenderState = null;
|
|
@@ -147,6 +150,8 @@ class WebGPURenderer {
|
|
|
|
|
|
this._renderTarget = null;
|
|
|
|
|
|
+ this._initialized = false;
|
|
|
+
|
|
|
// some parameters require default values other than "undefined"
|
|
|
|
|
|
this._parameters.antialias = ( parameters.antialias === true );
|
|
@@ -168,6 +173,12 @@ class WebGPURenderer {
|
|
|
|
|
|
async init() {
|
|
|
|
|
|
+ if ( this._initialized === true ) {
|
|
|
+
|
|
|
+ throw new Error( 'WebGPURenderer: Device has already been initialized.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
const parameters = this._parameters;
|
|
|
|
|
|
const adapterOptions = {
|
|
@@ -192,7 +203,7 @@ class WebGPURenderer {
|
|
|
const context = ( parameters.context !== undefined ) ? parameters.context : this.domElement.getContext( 'webgpu' );
|
|
|
|
|
|
context.configure( {
|
|
|
- device: device,
|
|
|
+ device,
|
|
|
format: GPUTextureFormat.BGRA8Unorm, // this is the only valid context format right now (r121)
|
|
|
alphaMode: 'premultiplied'
|
|
|
} );
|
|
@@ -232,16 +243,21 @@ class WebGPURenderer {
|
|
|
this._setupColorBuffer();
|
|
|
this._setupDepthBuffer();
|
|
|
|
|
|
- }
|
|
|
+ this._animation.setNodes( this._nodes );
|
|
|
+ this._animation.start();
|
|
|
|
|
|
- render( scene, camera ) {
|
|
|
+ this._initialized = true;
|
|
|
|
|
|
- // @TODO: move this to animation loop
|
|
|
+ }
|
|
|
+
|
|
|
+ async render( scene, camera ) {
|
|
|
|
|
|
- this._nodes.updateFrame();
|
|
|
+ if ( this._initialized === false ) return await this.init();
|
|
|
|
|
|
//
|
|
|
|
|
|
+ if ( this._animation.isAnimating === false ) this._nodes.updateFrame();
|
|
|
+
|
|
|
if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
|
|
|
|
|
|
if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
|
|
@@ -276,6 +292,8 @@ class WebGPURenderer {
|
|
|
|
|
|
if ( renderTarget !== null ) {
|
|
|
|
|
|
+ this._textures.initRenderTarget( renderTarget );
|
|
|
+
|
|
|
// @TODO: Support RenderTarget with antialiasing.
|
|
|
|
|
|
const renderTargetProperties = this._properties.get( renderTarget );
|
|
@@ -354,6 +372,18 @@ class WebGPURenderer {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ setAnimationLoop( callback ) {
|
|
|
+
|
|
|
+ if ( this._initialized === false ) this.init();
|
|
|
+
|
|
|
+ const animation = this._animation;
|
|
|
+
|
|
|
+ animation.setAnimationLoop( callback );
|
|
|
+
|
|
|
+ ( callback === null ) ? animation.stop() : animation.start();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
getContext() {
|
|
|
|
|
|
return this._context;
|
|
@@ -571,21 +601,20 @@ class WebGPURenderer {
|
|
|
this._renderStates.dispose();
|
|
|
this._textures.dispose();
|
|
|
|
|
|
+ this.setRenderTarget( null );
|
|
|
+ this.setAnimationLoop( null );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
setRenderTarget( renderTarget ) {
|
|
|
|
|
|
this._renderTarget = renderTarget;
|
|
|
|
|
|
- if ( renderTarget !== null ) {
|
|
|
-
|
|
|
- this._textures.initRenderTarget( renderTarget );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- compute( ...computeNodes ) {
|
|
|
+ async compute( ...computeNodes ) {
|
|
|
+
|
|
|
+ if ( this._initialized === false ) return await this.init();
|
|
|
|
|
|
const device = this._device;
|
|
|
const computePipelines = this._computePipelines;
|