UNPKG

molstar

Version:

A comprehensive macromolecular library.

53 lines 2.1 kB
/** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { printTextureImage } from '../../mol-gl/renderable/util'; import { defaults, ValueCell } from '../../mol-util'; import { ValueSpec, AttributeSpec, UniformSpec } from '../../mol-gl/renderable/schema'; import { Vec2 } from '../../mol-math/linear-algebra'; import { PixelData } from '../../mol-util/image'; export var 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 ]); export var QuadSchema = { drawCount: ValueSpec('number'), instanceCount: ValueSpec('number'), aPosition: AttributeSpec('float32', 2, 0), uQuadScale: UniformSpec('v2'), }; export var QuadValues = { drawCount: ValueCell.create(6), instanceCount: ValueCell.create(1), aPosition: ValueCell.create(QuadPositions), uQuadScale: ValueCell.create(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'); } export function readTexture(ctx, texture, width, height) { var gl = ctx.gl, resources = ctx.resources; width = defaults(width, texture.getWidth()); height = 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 }; } export function printTexture(ctx, texture, options) { if (options === void 0) { options = {}; } var pixelData = readTexture(ctx, texture); PixelData.flipY(pixelData); printTextureImage(pixelData, options); } //# sourceMappingURL=util.js.map