UNPKG

@thi.ng/webgl

Version:

WebGL & GLSL abstraction layer

46 lines (45 loc) 986 B
import { error } from "./error.js"; class RBO { gl; buffer; format; width; height; constructor(gl, opts) { this.gl = gl; this.buffer = gl.createRenderbuffer() || error("error creating RBO"); this.configure(opts); } bind() { this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, this.buffer); return true; } unbind() { this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null); return true; } release() { this.gl.deleteRenderbuffer(this.buffer); delete this.buffer; return true; } configure(opts, unbind = true) { const gl = this.gl; this.bind(); this.format = opts.format || gl.DEPTH_COMPONENT16; this.width = opts.width; this.height = opts.height; gl.renderbufferStorage( gl.RENDERBUFFER, opts.format || gl.DEPTH_COMPONENT16, opts.width, opts.height ); return unbind ? this.unbind() : true; } } const defRBO = (gl, opts) => new RBO(gl, opts); export { RBO, defRBO };