-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGPUCurtainsRenderer.ts
62 lines (57 loc) · 1.82 KB
/
GPUCurtainsRenderer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { GPUCameraRenderer, GPUCameraRendererParams } from '../../core/renderers/GPUCameraRenderer'
import { DOMProjectedMesh } from '../../core/renderers/GPURenderer'
/**
* This renderer just extends the {@link GPUCameraRenderer} by keeping track of all the created {@link curtains/meshes/DOMMesh.DOMMesh | DOM Meshes}
*
* @example
* ```javascript
* // first, we need a WebGPU device, that's what GPUDeviceManager is for
* const gpuDeviceManager = new GPUDeviceManager({
* label: 'Custom device manager',
* })
*
* // we need to wait for the WebGPU device to be created
* await gpuDeviceManager.init()
*
* // then we can create a curtains renderer
* const gpuCurtainsRenderer = new GPUCurtainsRenderer({
* deviceManager: gpuDeviceManager, // we need the WebGPU device to create the renderer context
* container: document.querySelector('#canvas'),
* })
* ```
*/
export class GPUCurtainsRenderer extends GPUCameraRenderer {
/** All created {@link curtains/meshes/DOMMesh.DOMMesh | DOM Meshes} and {@link curtains/meshes/Plane.Plane | planes} */
domMeshes: DOMProjectedMesh[]
/**
* GPUCurtainsRenderer constructor
* @param parameters - {@link GPUCameraRendererParams | parameters} used to create this {@link GPUCurtainsRenderer}
*/
constructor({
deviceManager,
container,
pixelRatio = 1,
preferredFormat,
alphaMode = 'premultiplied',
renderPass,
camera,
}: GPUCameraRendererParams) {
super({
deviceManager,
container,
pixelRatio,
preferredFormat,
alphaMode,
renderPass,
camera,
} as GPUCameraRendererParams)
this.type = 'GPUCurtainsRenderer'
}
/**
* Add the {@link GPUCurtainsRenderer#domMeshes | domMeshes} to our tracked elements
*/
setRendererObjects() {
super.setRendererObjects()
this.domMeshes = []
}
}