|
| 1 | +import * as THREE from 'three' |
| 2 | + |
| 3 | +const version = /* @__PURE__ */ (() => parseInt(THREE.REVISION.replace(/\D+/g, '')))() |
| 4 | + |
| 5 | +// NOTE: WebGLMultipleRenderTargets is removed since r172, so we implement it ourselves. |
| 6 | +// https://github.com/mrdoob/three.js/pull/26427 |
| 7 | +export const WebGLMultipleRenderTargets = |
| 8 | + version >= 162 |
| 9 | + ? class extends THREE.WebGLRenderTarget { |
| 10 | + constructor(width = 1, height = 1, count = 1, options = {}) { |
| 11 | + super(width, height, { ...options, count }) |
| 12 | + |
| 13 | + this.isWebGLMultipleRenderTargets = true |
| 14 | + } |
| 15 | + |
| 16 | + get texture() { |
| 17 | + return this.textures |
| 18 | + } |
| 19 | + } |
| 20 | + : class extends THREE.WebGLRenderTarget { |
| 21 | + constructor(width = 1, height = 1, count = 1, options = {}) { |
| 22 | + super(width, height, options) |
| 23 | + |
| 24 | + this.isWebGLMultipleRenderTargets = true |
| 25 | + |
| 26 | + const texture = this.texture |
| 27 | + |
| 28 | + this.texture = [] |
| 29 | + |
| 30 | + for (let i = 0; i < count; i++) { |
| 31 | + this.texture[i] = texture.clone() |
| 32 | + this.texture[i].isRenderTargetTexture = true |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + setSize(width, height, depth = 1) { |
| 37 | + if (this.width !== width || this.height !== height || this.depth !== depth) { |
| 38 | + this.width = width |
| 39 | + this.height = height |
| 40 | + this.depth = depth |
| 41 | + |
| 42 | + for (let i = 0, il = this.texture.length; i < il; i++) { |
| 43 | + this.texture[i].image.width = width |
| 44 | + this.texture[i].image.height = height |
| 45 | + this.texture[i].image.depth = depth |
| 46 | + } |
| 47 | + |
| 48 | + this.dispose() |
| 49 | + } |
| 50 | + |
| 51 | + this.viewport.set(0, 0, width, height) |
| 52 | + this.scissor.set(0, 0, width, height) |
| 53 | + } |
| 54 | + |
| 55 | + copy(source) { |
| 56 | + this.dispose() |
| 57 | + |
| 58 | + this.width = source.width |
| 59 | + this.height = source.height |
| 60 | + this.depth = source.depth |
| 61 | + |
| 62 | + this.scissor.copy(source.scissor) |
| 63 | + this.scissorTest = source.scissorTest |
| 64 | + |
| 65 | + this.viewport.copy(source.viewport) |
| 66 | + |
| 67 | + this.depthBuffer = source.depthBuffer |
| 68 | + this.stencilBuffer = source.stencilBuffer |
| 69 | + |
| 70 | + if (source.depthTexture !== null) this.depthTexture = source.depthTexture.clone() |
| 71 | + |
| 72 | + this.texture.length = 0 |
| 73 | + |
| 74 | + for (let i = 0, il = source.texture.length; i < il; i++) { |
| 75 | + this.texture[i] = source.texture[i].clone() |
| 76 | + this.texture[i].isRenderTargetTexture = true |
| 77 | + } |
| 78 | + |
| 79 | + return this |
| 80 | + } |
| 81 | + } |
0 commit comments