diff --git a/examples/jsm/renderers/common/Backend.js b/examples/jsm/renderers/common/Backend.js index a5fb55962dc240..b9eba356382d11 100644 --- a/examples/jsm/renderers/common/Backend.js +++ b/examples/jsm/renderers/common/Backend.js @@ -1,9 +1,7 @@ -let vector2 = null; -let vector4 = null; let color4 = null; import Color4 from './Color4.js'; -import { Vector2, Vector4, REVISION, createCanvasElement } from 'three'; +import { REVISION, createCanvasElement } from 'three'; class Backend { @@ -86,8 +84,6 @@ class Backend { getContext() { } - updateSize() { } - // utils resolveTimestampAsync( renderContext, type ) { } @@ -104,14 +100,6 @@ class Backend { } - getScissor() { - - vector4 = vector4 || new Vector4(); - - return this.renderer.getScissor( vector4 ); - - } - setScissorTest( boolean ) { } getClearColor() { diff --git a/examples/jsm/renderers/common/CanvasRenderTarget.js b/examples/jsm/renderers/common/CanvasRenderTarget.js index f53066689a83ce..ddd4e87f4ae686 100644 --- a/examples/jsm/renderers/common/CanvasRenderTarget.js +++ b/examples/jsm/renderers/common/CanvasRenderTarget.js @@ -25,7 +25,6 @@ class CanvasRenderTarget extends EventDispatcher { } - this.samples = this.sampleCount; this.outputColorSpace = SRGBColorSpace; this.depth = true; @@ -39,6 +38,14 @@ class CanvasRenderTarget extends EventDispatcher { this.scissor = new Vector4( 0, 0, this._width, this._height ); this._scissorTest = false; + this.version = 0; + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + } get domElement() { @@ -60,6 +67,24 @@ class CanvasRenderTarget extends EventDispatcher { } + get samples() { + + return this.sampleCount; + + } + + get depthBuffer() { + + return this.depth; + + } + + get stencilBuffer() { + + return this.stencil; + + } + getPixelRatio() { return this.pixelRatio; @@ -98,7 +123,7 @@ class CanvasRenderTarget extends EventDispatcher { this.setViewport( 0, 0, width, height ); - //if ( this._initialized ) this.backend.updateSize(); + this.needsUpdate = true; } @@ -119,7 +144,7 @@ class CanvasRenderTarget extends EventDispatcher { this.setViewport( 0, 0, width, height ); - //if ( this._initialized ) this.backend.updateSize(); + this.needsUpdate = true; } diff --git a/examples/jsm/renderers/common/RenderContexts.js b/examples/jsm/renderers/common/RenderContexts.js index 3f556f214df5f2..3bde5b00e04afb 100644 --- a/examples/jsm/renderers/common/RenderContexts.js +++ b/examples/jsm/renderers/common/RenderContexts.js @@ -49,9 +49,11 @@ class RenderContexts { chainMap.set( chainKey, renderState ); - } + renderState.sampleCount = renderTarget.samples === 0 ? 1 : renderTarget.samples; + renderState.depth = renderTarget.depthBuffer; + renderState.stencil = renderTarget.stencilBuffer; - if ( ! renderTarget.isCanvasRenderTarget ) renderState.sampleCount = renderTarget.samples === 0 ? 1 : renderTarget.samples; + } return renderState; diff --git a/examples/jsm/renderers/common/Renderer.js b/examples/jsm/renderers/common/Renderer.js index df855dc3d2fc61..a96bc92dcce02f 100644 --- a/examples/jsm/renderers/common/Renderer.js +++ b/examples/jsm/renderers/common/Renderer.js @@ -402,9 +402,6 @@ class Renderer { renderContext.depthTexture = null; renderContext.width = renderTarget.domElement.width; renderContext.height = renderTarget.domElement.height; - renderContext.depth = renderTarget.depth; - renderContext.stencil = renderTarget.stencil; - renderContext.sampleCount = renderTarget.sampleCount; } else { @@ -416,8 +413,6 @@ class Renderer { renderContext.depthTexture = renderTargetData.depthTexture; renderContext.width = renderTargetData.width; renderContext.height = renderTargetData.height; - renderContext.depth = renderTarget.depthBuffer; - renderContext.stencil = renderTarget.stencilBuffer; } @@ -542,21 +537,13 @@ class Renderer { setDrawingBufferSize( width, height, pixelRatio ) { - const canvasRenderTarget = this._defaultCanvasRenderTarget; - - canvasRenderTarget.setDrawingBufferSize( width, height, pixelRatio ); - - if ( this._initialized ) this.backend.updateSize( canvasRenderTarget ); + this._defaultCanvasRenderTarget.setDrawingBufferSize( width, height, pixelRatio ); } setSize( width, height, updateStyle = true ) { - const canvasRenderTarget = this._defaultCanvasRenderTarget; - - canvasRenderTarget.setSize( width, height, updateStyle ); - - if ( this._initialized ) this.backend.updateSize( canvasRenderTarget ); + this._defaultCanvasRenderTarget.setSize( width, height, updateStyle ); } diff --git a/examples/jsm/renderers/webgl/WebGLBackend.js b/examples/jsm/renderers/webgl/WebGLBackend.js index ff348703fc49b9..33870619eceeb1 100644 --- a/examples/jsm/renderers/webgl/WebGLBackend.js +++ b/examples/jsm/renderers/webgl/WebGLBackend.js @@ -971,12 +971,6 @@ class WebGLBackend extends Backend { } - updateSize() { - - //console.warn( 'Abstract class.' ); - - } - async hasFeatureAsync( name ) { return this.hasFeature( name ); diff --git a/examples/jsm/renderers/webgpu/WebGPUBackend.js b/examples/jsm/renderers/webgpu/WebGPUBackend.js index eb0067198adbdf..c69dcc22b834c9 100644 --- a/examples/jsm/renderers/webgpu/WebGPUBackend.js +++ b/examples/jsm/renderers/webgpu/WebGPUBackend.js @@ -92,7 +92,6 @@ class WebGPUBackend extends Backend { _configureContext( canvasRenderTarget ) { - // FIXME const context = ( canvasRenderTarget.context !== undefined ) ? canvasRenderTarget.context : canvasRenderTarget.domElement.getContext( 'webgpu' ); const canvasRenderTargetData = this.get( canvasRenderTarget ); @@ -106,7 +105,6 @@ class WebGPUBackend extends Backend { } ); canvasRenderTargetData.contextGPU = context; - canvasRenderTargetData.descriptor = null; canvasRenderTargetData.ready = true; }; @@ -139,9 +137,7 @@ class WebGPUBackend extends Backend { let { contextGPU, descriptor } = canvasRenderTargetData; - if ( descriptor === null ) { - - const renderer = this.renderer; + if ( canvasRenderTarget.version !== canvasRenderTargetData.version ) { descriptor = { colorAttachments: [ { @@ -165,6 +161,7 @@ class WebGPUBackend extends Backend { } canvasRenderTargetData.descriptor = descriptor; + canvasRenderTargetData.version = canvasRenderTarget.version; } @@ -1199,16 +1196,6 @@ class WebGPUBackend extends Backend { } - // canvas - - updateSize( canvasRenderTarget ) { - - const canvasRenderTargetData = this.get( canvasRenderTarget ); - - canvasRenderTargetData.descriptor = null; - - } - // utils public getMaxAnisotropy() {