-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support multiple screen canvas targets
- Loading branch information
aardgoose
committed
May 24, 2024
1 parent
0bc990f
commit 712d073
Showing
17 changed files
with
723 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
import { EventDispatcher, Vector4, REVISION, createCanvasElement, SRGBColorSpace } from 'three'; | ||
|
||
class CanvasRenderTarget extends EventDispatcher { | ||
|
||
constructor( parameters ) { | ||
|
||
super(); | ||
|
||
this.isCanvasRenderTarget = true; | ||
|
||
this.canvas = parameters.canvas; | ||
this.context = parameters.context; | ||
this._domElement = parameters.domElement; | ||
this.alpha = ( parameters.alpha === undefined ) ? true : parameters.alpha; | ||
|
||
this.antialias = ( parameters.antialias === true ); | ||
|
||
if ( this.antialias === true ) { | ||
|
||
this.sampleCount = ( parameters.sampleCount === undefined ) ? 4 : parameters.sampleCount; | ||
|
||
} else { | ||
|
||
this.sampleCount = 1; | ||
|
||
} | ||
|
||
this.outputColorSpace = SRGBColorSpace; | ||
|
||
this.depth = true; | ||
this.stencil = false; | ||
|
||
this._width = 0; | ||
this._height = 0; | ||
this.pixelRatio = 1; | ||
|
||
this.viewport = new Vector4( 0, 0, this._width, this._height ); | ||
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() { | ||
|
||
let domElement = this._domElement; | ||
|
||
if ( ! domElement ) { | ||
|
||
domElement = ( this.canvas !== undefined ) ? this.canvas : createCanvasElement(); | ||
|
||
// OffscreenCanvas does not have setAttribute, see #22811 | ||
if ( 'setAttribute' in domElement ) domElement.setAttribute( 'data-engine', `three.js r${REVISION} webgpu` ); | ||
|
||
this._domElement = domElement; | ||
|
||
} | ||
|
||
return domElement; | ||
|
||
} | ||
|
||
get samples() { | ||
|
||
return this.sampleCount; | ||
|
||
} | ||
|
||
get depthBuffer() { | ||
|
||
return this.depth; | ||
|
||
} | ||
|
||
get stencilBuffer() { | ||
|
||
return this.stencil; | ||
|
||
} | ||
|
||
getPixelRatio() { | ||
|
||
return this.pixelRatio; | ||
|
||
} | ||
|
||
getDrawingBufferSize( target ) { | ||
|
||
return target.set( this._width * this.pixelRatio, this._height * this.pixelRatio ).floor(); | ||
|
||
} | ||
|
||
getSize( target ) { | ||
|
||
return target.set( this._width, this._height ); | ||
|
||
} | ||
|
||
setPixelRatio( value = 1 ) { | ||
|
||
this.pixelRatio = value; | ||
|
||
this.setSize( this._width, this._height, false ); | ||
|
||
} | ||
|
||
setDrawingBufferSize( width, height, pixelRatio ) { | ||
|
||
this._width = width; | ||
this._height = height; | ||
|
||
this.pixelRatio = pixelRatio; | ||
|
||
this.domElement.width = Math.floor( width * pixelRatio ); | ||
this.domElement.height = Math.floor( height * pixelRatio ); | ||
|
||
this.setViewport( 0, 0, width, height ); | ||
|
||
this.needsUpdate = true; | ||
|
||
} | ||
|
||
setSize( width, height, updateStyle = true ) { | ||
|
||
this._width = width; | ||
this._height = height; | ||
|
||
this.domElement.width = Math.floor( width * this.pixelRatio ); | ||
this.domElement.height = Math.floor( height * this.pixelRatio ); | ||
|
||
if ( updateStyle === true ) { | ||
|
||
this.domElement.style.width = width + 'px'; | ||
this.domElement.style.height = height + 'px'; | ||
|
||
} | ||
|
||
this.setViewport( 0, 0, width, height ); | ||
|
||
this.needsUpdate = true; | ||
|
||
} | ||
|
||
getScissor( target ) { | ||
|
||
const scissor = this.scissor; | ||
|
||
target.x = scissor.x; | ||
target.y = scissor.y; | ||
target.width = scissor.width; | ||
target.height = scissor.height; | ||
|
||
return target; | ||
|
||
} | ||
|
||
setScissor( x, y, width, height ) { | ||
|
||
const scissor = this.scissor; | ||
|
||
if ( x.isVector4 ) { | ||
|
||
scissor.copy( x ); | ||
|
||
} else { | ||
|
||
scissor.set( x, y, width, height ); | ||
|
||
} | ||
|
||
} | ||
|
||
getScissorTest() { | ||
|
||
return this._scissorTest; | ||
|
||
} | ||
|
||
getViewport( target ) { | ||
|
||
return target.copy( this.viewport ); | ||
|
||
} | ||
|
||
setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) { | ||
|
||
const viewport = this.viewport; | ||
|
||
if ( x.isVector4 ) { | ||
|
||
viewport.copy( x ); | ||
|
||
} else { | ||
|
||
viewport.set( x, y, width, height ); | ||
|
||
} | ||
|
||
viewport.minDepth = minDepth; | ||
viewport.maxDepth = maxDepth; | ||
|
||
} | ||
|
||
dispose() { | ||
|
||
this.dispatchEvent( { type: 'dispose' } ); | ||
|
||
} | ||
|
||
} | ||
|
||
export default CanvasRenderTarget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.