diff --git a/src/mol-gl/renderable.ts b/src/mol-gl/renderable.ts index afceb5794264e520b290679d0f4427d4e7911fa7..bd436980ba0b8869aba530be51f272ad49c66bce 100644 --- a/src/mol-gl/renderable.ts +++ b/src/mol-gl/renderable.ts @@ -61,7 +61,7 @@ export interface ComputeRenderable<T extends RenderableValues> { readonly values: T render: () => void - getProgram: () => Program + use: () => void update: () => void dispose: () => void } @@ -72,7 +72,7 @@ export function createComputeRenderable<T extends Values<RenderableSchema>>(rend values, render: () => renderItem.render('draw'), - getProgram: () => renderItem.getProgram('draw'), + use: () => renderItem.getProgram('draw').use(), update: () => renderItem.update(), dispose: () => renderItem.destroy() } diff --git a/src/mol-gl/renderable/gaussian-density.ts b/src/mol-gl/renderable/gaussian-density.ts deleted file mode 100644 index 7a31f7678051155cc6031dfe2bdf57556356b10b..0000000000000000000000000000000000000000 --- a/src/mol-gl/renderable/gaussian-density.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. - * - * @author Alexander Rose <alexander.rose@weirdbyte.de> - */ - -import { Renderable, RenderableState, createRenderable } from '../renderable' -import { WebGLContext } from '../webgl/context'; -import { createRenderItem } from '../webgl/render-item'; -import { AttributeSpec, Values, UniformSpec, ValueSpec, DefineSpec, TextureSpec } from './schema'; -import { GaussianDensityShaderCode } from '../shader-code'; - -export const GaussianDensitySchema = { - drawCount: ValueSpec('number'), - instanceCount: ValueSpec('number'), - - aRadius: AttributeSpec('float32', 1, 0), - aPosition: AttributeSpec('float32', 3, 0), - aGroup: AttributeSpec('float32', 1, 0), - - uCurrentSlice: UniformSpec('f'), - uCurrentX: UniformSpec('f'), - uCurrentY: UniformSpec('f'), - uBboxMin: UniformSpec('v3'), - uBboxMax: UniformSpec('v3'), - uBboxSize: UniformSpec('v3'), - uGridDim: UniformSpec('v3'), - uGridTexDim: UniformSpec('v3'), - uAlpha: UniformSpec('f'), - tMinDistanceTex: TextureSpec('texture', 'rgba', 'ubyte', 'nearest'), - - dGridTexType: DefineSpec('string', ['2d', '3d']), - dCalcType: DefineSpec('string', ['density', 'minDistance', 'groupId']), -} -export type GaussianDensitySchema = typeof GaussianDensitySchema -export type GaussianDensityValues = Values<GaussianDensitySchema> - -export function GaussianDensityRenderable(ctx: WebGLContext, id: number, values: GaussianDensityValues, state: RenderableState): Renderable<GaussianDensityValues> { - const schema = { ...GaussianDensitySchema } - const shaderCode = GaussianDensityShaderCode - const renderItem = createRenderItem(ctx, 'points', shaderCode, schema, values, -1) - - return createRenderable(renderItem, values, state); -} \ No newline at end of file diff --git a/src/mol-math/geometry/gaussian-density.ts b/src/mol-math/geometry/gaussian-density.ts index 434ba158c1dbc59d5161c7e4d3fe07a12919c448..de185d45838c646b4a00cc9520fa59779eee7faf 100644 --- a/src/mol-math/geometry/gaussian-density.ts +++ b/src/mol-math/geometry/gaussian-density.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ @@ -10,11 +10,15 @@ import { RuntimeContext, Task } from 'mol-task'; import { PositionData, DensityData } from './common'; import { GaussianDensityCPU } from './gaussian-density/cpu'; import { WebGLContext } from 'mol-gl/webgl/context'; +import { Texture } from 'mol-gl/webgl/texture'; -// import { GaussianDensityGPU } from './gaussian-density/gpu'; +// import { GaussianDensityGPU, GaussianDensityTexture } from './gaussian-density/gpu'; const GaussianDensityGPU = typeof document !== 'undefined' ? (require('./gaussian-density/gpu') as typeof import('./gaussian-density/gpu')).GaussianDensityGPU : void 0; +const GaussianDensityTexture = typeof document !== 'undefined' + ? (require('./gaussian-density/gpu') as typeof import('./gaussian-density/gpu')).GaussianDensityTexture + : void 0; export const DefaultGaussianDensityGPUProps = { resolution: 1, @@ -37,9 +41,9 @@ export function getDelta(box: Box3D, resolution: number) { return delta } -export function computeGaussianDensity(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityProps) { +export function computeGaussianDensity(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityProps, webgl?: WebGLContext) { return Task.create('Gaussian Density', async ctx => { - return await GaussianDensity(ctx, position, box, radius, props) + return await GaussianDensity(ctx, position, box, radius, props, webgl) }); } @@ -51,4 +55,11 @@ export async function GaussianDensity(ctx: RuntimeContext, position: PositionDat } else { return await GaussianDensityCPU(ctx, position, box, radius, props) } +} + +export function computeGaussianDensityTexture(position: PositionData, box: Box3D, radius: (index: number) => number, props: GaussianDensityGPUProps, webgl: WebGLContext, texture?: Texture) { + if (!GaussianDensityTexture) throw 'GPU computation not supported on this platform'; + return Task.create('Gaussian Density', async ctx => { + return await GaussianDensityTexture(ctx, webgl, position, box, radius, props, texture); + }); } \ No newline at end of file diff --git a/src/mol-math/geometry/gaussian-density/gpu.ts b/src/mol-math/geometry/gaussian-density/gpu.ts index 312de7cf2e86e9da8ad406b10d75dae192622090..e8e53812e8cd1cb4df7a249e745c2a5a010d7c14 100644 --- a/src/mol-math/geometry/gaussian-density/gpu.ts +++ b/src/mol-math/geometry/gaussian-density/gpu.ts @@ -277,7 +277,7 @@ function setupMinDistanceRendering(webgl: WebGLContext, renderable: ComputeRende const { gl } = webgl ValueCell.update(renderable.values.dCalcType, 'minDistance') renderable.update() - renderable.getProgram().use() + renderable.use() gl.blendFunc(gl.ONE, gl.ONE) // the shader writes 1 - dist so we set blending to MAX gl.blendEquation(webgl.extensions.blendMinMax.MAX) @@ -287,7 +287,7 @@ function setupDensityRendering(webgl: WebGLContext, renderable: ComputeRenderabl const { gl } = webgl ValueCell.update(renderable.values.dCalcType, 'density') renderable.update() - renderable.getProgram().use() + renderable.use() gl.blendFunc(gl.ONE, gl.ONE) gl.blendEquation(gl.FUNC_ADD) } @@ -296,7 +296,7 @@ function setupGroupIdRendering(webgl: WebGLContext, renderable: ComputeRenderabl const { gl } = webgl ValueCell.update(renderable.values.dCalcType, 'groupId') renderable.update() - renderable.getProgram().use() + renderable.use() // overwrite color, don't change alpha gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ZERO, gl.ONE) gl.blendEquation(gl.FUNC_ADD)