UNPKG

molstar

Version:

A comprehensive macromolecular library.

65 lines 2.33 kB
/** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { idFactory } from '../../mol-util/id-factory'; import { isWebGL2 } from './compat'; var getNextFramebufferId = idFactory(); function getFramebufferStatusDescription(gl, status) { switch (status) { case gl.FRAMEBUFFER_COMPLETE: return 'complete'; case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return 'incomplete attachment'; case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return 'incomplete missing attachment'; case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return 'incomplete dimensions'; case gl.FRAMEBUFFER_UNSUPPORTED: return 'unsupported'; } if (isWebGL2(gl)) { switch (status) { case gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return 'incomplete multisample'; case gl.RENDERBUFFER_SAMPLES: return 'renderbuffer samples'; } } return 'unknown error'; } export function checkFramebufferStatus(gl) { var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); if (status !== gl.FRAMEBUFFER_COMPLETE) { var description = getFramebufferStatusDescription(gl, status); throw new Error("Framebuffer status: " + description); } } function getFramebuffer(gl) { var framebuffer = gl.createFramebuffer(); if (framebuffer === null) { throw new Error('Could not create WebGL framebuffer'); } return framebuffer; } export function createFramebuffer(gl) { var _framebuffer = getFramebuffer(gl); var destroyed = false; return { id: getNextFramebufferId(), bind: function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, _framebuffer); }, reset: function () { _framebuffer = getFramebuffer(gl); }, destroy: function () { if (destroyed) return; gl.deleteFramebuffer(_framebuffer); destroyed = true; } }; } // export function createNullFramebuffer() { return { id: getNextFramebufferId(), bind: function () { }, reset: function () { }, destroy: function () { } }; } //# sourceMappingURL=framebuffer.js.map