UNPKG

molstar

Version:

A comprehensive macromolecular library.

115 lines 5.77 kB
"use strict"; /** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.WboitPass = void 0; var tslib_1 = require("tslib"); var util_1 = require("../../mol-gl/compute/util"); var renderable_1 = require("../../mol-gl/renderable"); var schema_1 = require("../../mol-gl/renderable/schema"); var shader_code_1 = require("../../mol-gl/shader-code"); var render_item_1 = require("../../mol-gl/webgl/render-item"); var mol_util_1 = require("../../mol-util"); var quad_vert_1 = require("../../mol-gl/shader/quad.vert"); var evaluate_wboit_frag_1 = require("../../mol-gl/shader/evaluate-wboit.frag"); var linear_algebra_1 = require("../../mol-math/linear-algebra"); var debug_1 = require("../../mol-util/debug"); var EvaluateWboitSchema = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, util_1.QuadSchema), { tWboitA: (0, schema_1.TextureSpec)('texture', 'rgba', 'float', 'nearest'), tWboitB: (0, schema_1.TextureSpec)('texture', 'rgba', 'float', 'nearest'), uTexSize: (0, schema_1.UniformSpec)('v2') }); var EvaluateWboitShaderCode = (0, shader_code_1.ShaderCode)('evaluate-wboit', quad_vert_1.quad_vert, evaluate_wboit_frag_1.evaluateWboit_frag); function getEvaluateWboitRenderable(ctx, wboitATexture, wboitBTexture) { var values = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, util_1.QuadValues), { tWboitA: mol_util_1.ValueCell.create(wboitATexture), tWboitB: mol_util_1.ValueCell.create(wboitBTexture), uTexSize: mol_util_1.ValueCell.create(linear_algebra_1.Vec2.create(wboitATexture.getWidth(), wboitATexture.getHeight())) }); var schema = (0, tslib_1.__assign)({}, EvaluateWboitSchema); var renderItem = (0, render_item_1.createComputeRenderItem)(ctx, 'triangles', EvaluateWboitShaderCode, schema, values); return (0, renderable_1.createComputeRenderable)(renderItem, values); } // var WboitPass = /** @class */ (function () { function WboitPass(webgl, width, height) { this.webgl = webgl; this._supported = false; if (!WboitPass.isSupported(webgl)) return; var resources = webgl.resources; this.textureA = resources.texture('image-float32', 'rgba', 'float', 'nearest'); this.textureA.define(width, height); this.textureB = resources.texture('image-float32', 'rgba', 'float', 'nearest'); this.textureB.define(width, height); this.renderable = getEvaluateWboitRenderable(webgl, this.textureA, this.textureB); this.framebuffer = resources.framebuffer(); this._supported = true; this._init(); } Object.defineProperty(WboitPass.prototype, "supported", { get: function () { return this._supported; }, enumerable: false, configurable: true }); WboitPass.prototype.bind = function () { var _a = this.webgl, state = _a.state, gl = _a.gl; this.framebuffer.bind(); state.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); state.disable(gl.DEPTH_TEST); state.blendFuncSeparate(gl.ONE, gl.ONE, gl.ZERO, gl.ONE_MINUS_SRC_ALPHA); state.enable(gl.BLEND); }; WboitPass.prototype.render = function () { var _a = this.webgl, state = _a.state, gl = _a.gl; state.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); state.enable(gl.BLEND); this.renderable.update(); this.renderable.render(); }; WboitPass.prototype.setSize = function (width, height) { var _a = this.renderable.values.uTexSize.ref.value, w = _a[0], h = _a[1]; if (width !== w || height !== h) { this.textureA.define(width, height); this.textureB.define(width, height); mol_util_1.ValueCell.update(this.renderable.values.uTexSize, linear_algebra_1.Vec2.set(this.renderable.values.uTexSize.ref.value, width, height)); } }; WboitPass.prototype.reset = function () { if (this._supported) this._init(); }; WboitPass.prototype._init = function () { var drawBuffers = this.webgl.extensions.drawBuffers; this.framebuffer.bind(); drawBuffers.drawBuffers([ drawBuffers.COLOR_ATTACHMENT0, drawBuffers.COLOR_ATTACHMENT1, ]); this.textureA.attachFramebuffer(this.framebuffer, 'color0'); this.textureB.attachFramebuffer(this.framebuffer, 'color1'); }; WboitPass.isSupported = function (webgl) { var _a = webgl.extensions, drawBuffers = _a.drawBuffers, textureFloat = _a.textureFloat, colorBufferFloat = _a.colorBufferFloat, depthTexture = _a.depthTexture; if (!textureFloat || !colorBufferFloat || !depthTexture || !drawBuffers) { if (debug_1.isDebugMode) { var missing = []; if (!textureFloat) missing.push('textureFloat'); if (!colorBufferFloat) missing.push('colorBufferFloat'); if (!depthTexture) missing.push('depthTexture'); if (!drawBuffers) missing.push('drawBuffers'); console.log("Missing \"" + missing.join('", "') + "\" extensions required for \"wboit\""); } return false; } else { return true; } }; return WboitPass; }()); exports.WboitPass = WboitPass; //# sourceMappingURL=wboit.js.map