Spaces:
Sleeping
Sleeping
File size: 1,278 Bytes
9a14526 | 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 | // @flow
import {ColorAttachment, DepthAttachment} from './value';
import assert from 'assert';
import type Context from './context';
class Framebuffer {
context: Context;
width: number;
height: number;
framebuffer: WebGLFramebuffer;
colorAttachment: ColorAttachment;
depthAttachment: DepthAttachment;
constructor(context: Context, width: number, height: number, hasDepth: boolean) {
this.context = context;
this.width = width;
this.height = height;
const gl = context.gl;
const fbo = this.framebuffer = gl.createFramebuffer();
this.colorAttachment = new ColorAttachment(context, fbo);
if (hasDepth) {
this.depthAttachment = new DepthAttachment(context, fbo);
}
assert(gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
}
destroy() {
const gl = this.context.gl;
const texture = this.colorAttachment.get();
if (texture) gl.deleteTexture(texture);
if (this.depthAttachment) {
const renderbuffer = this.depthAttachment.get();
if (renderbuffer) gl.deleteRenderbuffer(renderbuffer);
}
gl.deleteFramebuffer(this.framebuffer);
}
}
export default Framebuffer;
|