molstar
Version:
A comprehensive macromolecular library.
58 lines • 2.48 kB
JavaScript
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.printTexture = exports.readTexture = exports.QuadValues = exports.QuadSchema = exports.QuadPositions = void 0;
var util_1 = require("../../mol-gl/renderable/util");
var mol_util_1 = require("../../mol-util");
var schema_1 = require("../../mol-gl/renderable/schema");
var linear_algebra_1 = require("../../mol-math/linear-algebra");
var image_1 = require("../../mol-util/image");
exports.QuadPositions = new Float32Array([
1.0, 1.0, -1.0, 1.0, -1.0, -1.0,
-1.0, -1.0, 1.0, -1.0, 1.0, 1.0 // Second triangle
]);
exports.QuadSchema = {
drawCount: (0, schema_1.ValueSpec)('number'),
instanceCount: (0, schema_1.ValueSpec)('number'),
aPosition: (0, schema_1.AttributeSpec)('float32', 2, 0),
uQuadScale: (0, schema_1.UniformSpec)('v2'),
};
exports.QuadValues = {
drawCount: mol_util_1.ValueCell.create(6),
instanceCount: mol_util_1.ValueCell.create(1),
aPosition: mol_util_1.ValueCell.create(exports.QuadPositions),
uQuadScale: mol_util_1.ValueCell.create(linear_algebra_1.Vec2.create(1, 1)),
};
//
function getArrayForTexture(gl, texture, size) {
switch (texture.type) {
case gl.UNSIGNED_BYTE: return new Uint8Array(size);
case gl.FLOAT: return new Float32Array(size);
}
throw new Error('unknown/unsupported texture type');
}
function readTexture(ctx, texture, width, height) {
var gl = ctx.gl, resources = ctx.resources;
width = (0, mol_util_1.defaults)(width, texture.getWidth());
height = (0, mol_util_1.defaults)(height, texture.getHeight());
var size = width * height * 4;
var framebuffer = resources.framebuffer();
var array = getArrayForTexture(gl, texture, size);
framebuffer.bind();
texture.attachFramebuffer(framebuffer, 0);
ctx.readPixels(0, 0, width, height, array);
return { array: array, width: width, height: height };
}
exports.readTexture = readTexture;
function printTexture(ctx, texture, options) {
if (options === void 0) { options = {}; }
var pixelData = readTexture(ctx, texture);
image_1.PixelData.flipY(pixelData);
(0, util_1.printTextureImage)(pixelData, options);
}
exports.printTexture = printTexture;
//# sourceMappingURL=util.js.map
;