Skip to content

Commit

Permalink
rework size updating and renderContext property init.
Browse files Browse the repository at this point in the history
  • Loading branch information
aardgoose committed Jan 31, 2024
1 parent 9a1de1e commit 535a07c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 54 deletions.
14 changes: 1 addition & 13 deletions examples/jsm/renderers/common/Backend.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -86,8 +84,6 @@ class Backend {

getContext() { }

updateSize() { }

// utils

resolveTimestampAsync( renderContext, type ) { }
Expand All @@ -104,14 +100,6 @@ class Backend {

}

getScissor() {

vector4 = vector4 || new Vector4();

return this.renderer.getScissor( vector4 );

}

setScissorTest( boolean ) { }

getClearColor() {
Expand Down
31 changes: 28 additions & 3 deletions examples/jsm/renderers/common/CanvasRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class CanvasRenderTarget extends EventDispatcher {

}

this.samples = this.sampleCount;
this.outputColorSpace = SRGBColorSpace;

this.depth = true;
Expand All @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -98,7 +123,7 @@ class CanvasRenderTarget extends EventDispatcher {

this.setViewport( 0, 0, width, height );

//if ( this._initialized ) this.backend.updateSize();
this.needsUpdate = true;

}

Expand All @@ -119,7 +144,7 @@ class CanvasRenderTarget extends EventDispatcher {

this.setViewport( 0, 0, width, height );

//if ( this._initialized ) this.backend.updateSize();
this.needsUpdate = true;

}

Expand Down
6 changes: 4 additions & 2 deletions examples/jsm/renderers/common/RenderContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 2 additions & 15 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;

}

Expand Down Expand Up @@ -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 );

}

Expand Down
6 changes: 0 additions & 6 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,12 +971,6 @@ class WebGLBackend extends Backend {

}

updateSize() {

//console.warn( 'Abstract class.' );

}

async hasFeatureAsync( name ) {

return this.hasFeature( name );
Expand Down
17 changes: 2 additions & 15 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -106,7 +105,6 @@ class WebGPUBackend extends Backend {
} );

canvasRenderTargetData.contextGPU = context;
canvasRenderTargetData.descriptor = null;
canvasRenderTargetData.ready = true;

};
Expand Down Expand Up @@ -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: [ {
Expand All @@ -165,6 +161,7 @@ class WebGPUBackend extends Backend {
}

canvasRenderTargetData.descriptor = descriptor;
canvasRenderTargetData.version = canvasRenderTarget.version;

}

Expand Down Expand Up @@ -1199,16 +1196,6 @@ class WebGPUBackend extends Backend {

}

// canvas

updateSize( canvasRenderTarget ) {

const canvasRenderTargetData = this.get( canvasRenderTarget );

canvasRenderTargetData.descriptor = null;

}

// utils public

getMaxAnisotropy() {
Expand Down

0 comments on commit 535a07c

Please sign in to comment.