(renderer, settings = {})
| 57 | |
| 58 | class Framebuffer { |
| 59 | constructor(renderer, settings = {}) { |
| 60 | this.renderer = renderer; |
| 61 | this.renderer.framebuffers.add(this); |
| 62 | |
| 63 | this._isClipApplied = false; |
| 64 | this._useCanvasFormat = settings._useCanvasFormat || false; |
| 65 | |
| 66 | this.dirty = { colorTexture: false, depthTexture: false }; |
| 67 | |
| 68 | this.pixels = []; |
| 69 | |
| 70 | this.format = settings.format || constants.UNSIGNED_BYTE; |
| 71 | this.channels = settings.channels || ( |
| 72 | this.renderer.defaultFramebufferAlpha() |
| 73 | ? RGBA |
| 74 | : RGB |
| 75 | ); |
| 76 | this.useDepth = settings.depth === undefined ? true : settings.depth; |
| 77 | this.depthFormat = settings.depthFormat || constants.FLOAT; |
| 78 | this.textureFiltering = settings.textureFiltering || constants.LINEAR; |
| 79 | if (settings.antialias === undefined) { |
| 80 | this.antialiasSamples = this.renderer.defaultFramebufferAntialias() |
| 81 | ? 2 |
| 82 | : 0; |
| 83 | } else if (typeof settings.antialias === 'number') { |
| 84 | this.antialiasSamples = settings.antialias; |
| 85 | } else { |
| 86 | this.antialiasSamples = settings.antialias ? 2 : 0; |
| 87 | } |
| 88 | this.antialias = this.antialiasSamples > 0; |
| 89 | if (this.antialias && !this.renderer.supportsFramebufferAntialias()) { |
| 90 | console.warn('Framebuffer antialiasing is unsupported in this context'); |
| 91 | this.antialias = false; |
| 92 | } |
| 93 | this.density = settings.density || this.renderer._pixelDensity; |
| 94 | if (settings.width && settings.height) { |
| 95 | const dimensions = |
| 96 | this.renderer._adjustDimensions(settings.width, settings.height); |
| 97 | this.width = dimensions.adjustedWidth; |
| 98 | this.height = dimensions.adjustedHeight; |
| 99 | this._autoSized = false; |
| 100 | } else { |
| 101 | if ((settings.width === undefined) !== (settings.height === undefined)) { |
| 102 | console.warn( |
| 103 | 'Please supply both width and height for a framebuffer to give it a ' + |
| 104 | 'size. Only one was given, so the framebuffer will match the size ' + |
| 105 | 'of its canvas.' |
| 106 | ); |
| 107 | } |
| 108 | this.width = this.renderer.width; |
| 109 | this.height = this.renderer.height; |
| 110 | this._autoSized = true; |
| 111 | } |
| 112 | // Let renderer validate and adjust formats for this context |
| 113 | this.renderer.validateFramebufferFormats(this); |
| 114 | |
| 115 | if (settings.stencil && !this.useDepth) { |
| 116 | console.warn('A stencil buffer can only be used if also using depth. Since the framebuffer has no depth buffer, the stencil buffer will be ignored.'); |
nothing calls this directly
no test coverage detected