UNPKG

three

Version:

JavaScript 3D library

99 lines (73 loc) 3.21 kB
import Renderer from '../common/Renderer.js'; import WebGLBackend from '../webgl-fallback/WebGLBackend.js'; import WebGPUBackend from './WebGPUBackend.js'; import StandardNodeLibrary from './nodes/StandardNodeLibrary.js'; /* const debugHandler = { get: function ( target, name ) { // Add |update if ( /^(create|destroy)/.test( name ) ) console.log( 'WebGPUBackend.' + name ); return target[ name ]; } }; */ /** * This renderer is the new alternative of `WebGLRenderer`. `WebGPURenderer` has the ability * to target different backends. By default, the renderer tries to use a WebGPU backend if the * browser supports WebGPU. If not, `WebGPURenderer` falls backs to a WebGL 2 backend. * * @augments Renderer */ class WebGPURenderer extends Renderer { /** * WebGPURenderer options. * * @typedef {Object} WebGPURenderer~Options * @property {boolean} [logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not. * @property {boolean} [alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque. * @property {boolean} [depth=true] - Whether the default framebuffer should have a depth buffer or not. * @property {boolean} [stencil=false] - Whether the default framebuffer should have a stencil buffer or not. * @property {boolean} [antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not. * @property {number} [samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default. * @property {boolean} [forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not. * @property {number} [outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead. * @property {number} [colorBufferType=HalfFloatType] - Defines the type of color buffers. The default `HalfFloatType` is recommend for best * quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though. */ /** * Constructs a new WebGPU renderer. * * @param {WebGPURenderer~Options} [parameters] - The configuration parameter. */ constructor( parameters = {} ) { let BackendClass; if ( parameters.forceWebGL ) { BackendClass = WebGLBackend; } else { BackendClass = WebGPUBackend; parameters.getFallback = () => { console.warn( 'THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' ); return new WebGLBackend( parameters ); }; } const backend = new BackendClass( parameters ); //super( new Proxy( backend, debugHandler ) ); super( backend, parameters ); /** * The generic default value is overwritten with the * standard node library for type mapping. * * @type {StandardNodeLibrary} */ this.library = new StandardNodeLibrary(); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isWebGPURenderer = true; } } export default WebGPURenderer;