From b8d60cea9b0ba87cdd8bac882217183469fd4262 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sat, 16 Jan 2021 13:09:49 -0800 Subject: [PATCH] Canvas3d.fromCanvas attribs - simplified antialias handling - expose preserveDrawingBuffer --- src/mol-canvas3d/canvas3d.ts | 32 +++++++++++++++++--------------- src/mol-plugin/config.ts | 4 ++-- src/mol-plugin/context.ts | 6 +++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index 4dff0919b..9176c5338 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -150,14 +150,24 @@ namespace Canvas3D { export interface DragEvent { current: Representation.Loci, buttons: ButtonsType, button: ButtonsType.Flag, modifiers: ModifiersKeys, pageStart: Vec2, pageEnd: Vec2 } export interface ClickEvent { current: Representation.Loci, buttons: ButtonsType, button: ButtonsType.Flag, modifiers: ModifiersKeys, page?: Vec2, position?: Vec3 } - export function fromCanvas(canvas: HTMLCanvasElement, props: Partial<Canvas3DProps> = {}, attribs: Partial<{ antialias: boolean, forceAntialias: boolean, pixelScale: number, pickScale: number, enableWboit: boolean }> = {}) { - const antialias = !!attribs.forceAntialias || ((attribs.antialias ?? true) && !attribs.enableWboit); + + type Attribs = { + /** true by default to avoid issues with Safari (Jan 2021) */ + antialias: boolean, + /** true to support multiple viewports with a single context */ + preserveDrawingBuffer: boolean, + pixelScale: number, + pickScale: number, + enableWboit: boolean + } + + export function fromCanvas(canvas: HTMLCanvasElement, props: Partial<Canvas3DProps> = {}, attribs: Partial<Attribs> = {}) { const gl = getGLContext(canvas, { - alpha: true, - antialias, - depth: true, - preserveDrawingBuffer: true, - premultipliedAlpha: true, + antialias: attribs.antialias ?? true, + preserveDrawingBuffer: attribs.preserveDrawingBuffer ?? true, + alpha: true, // the renderer requires an alpha channel + depth: true, // the renderer requires a depth buffer + premultipliedAlpha: true, // the renderer outputs PMA }); if (gl === null) throw new Error('Could not create a WebGL rendering context'); @@ -199,14 +209,6 @@ namespace Canvas3D { if (isDebugMode) console.log('context restored'); }, false); - // disable postprocessing anti-aliasing if canvas anti-aliasing is enabled - if (antialias && !props.postprocessing?.antialiasing) { - props.postprocessing = { - ...DefaultCanvas3DParams.postprocessing, - antialiasing: { name: 'off', params: {} } - }; - } - return create(webgl, input, passes, props, { pixelScale }); } diff --git a/src/mol-plugin/config.ts b/src/mol-plugin/config.ts index 77be4292f..459d4c04d 100644 --- a/src/mol-plugin/config.ts +++ b/src/mol-plugin/config.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2020-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> @@ -24,10 +24,10 @@ export const PluginConfig = { General: { IsBusyTimeoutMs: item('plugin-config.is-busy-timeout', 750), DisableAntialiasing: item('plugin-config.disable-antialiasing', false), + DisablePreserveDrawingBuffer: item('plugin-config.disable-preserve-drawing-buffer', false), PixelScale: item('plugin-config.pixel-scale', 1), PickScale: item('plugin-config.pick-scale', 0.25), EnableWboit: item('plugin-config.enable-wboit', false), - ForceWboitAntialiasing: item('plugin-config.force-wboit-antialiasing', false), }, State: { DefaultServer: item('plugin-state.server', 'https://webchem.ncbr.muni.cz/molstar-state'), diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index 5fc19a7ad..cc94a312f 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> @@ -189,11 +189,11 @@ export class PluginContext { if (this.spec.layout && this.spec.layout.initial) this.layout.setProps(this.spec.layout.initial); const antialias = !(this.config.get(PluginConfig.General.DisableAntialiasing) ?? false); + const preserveDrawingBuffer = !(this.config.get(PluginConfig.General.DisablePreserveDrawingBuffer) ?? false); const pixelScale = this.config.get(PluginConfig.General.PixelScale) || 1; const pickScale = this.config.get(PluginConfig.General.PickScale) || 0.25; const enableWboit = this.config.get(PluginConfig.General.EnableWboit) || false; - const forceWboitAntialias = !(this.config.get(PluginConfig.General.ForceWboitAntialiasing) ?? false); - (this.canvas3d as Canvas3D) = Canvas3D.fromCanvas(canvas, {}, { antialias, forceAntialias: forceWboitAntialias, pixelScale, enableWboit, pickScale }); + (this.canvas3d as Canvas3D) = Canvas3D.fromCanvas(canvas, {}, { antialias, preserveDrawingBuffer, pixelScale, enableWboit, pickScale }); this.canvas3dInit.next(true); let props = this.spec.components?.viewport?.canvas3d; -- GitLab