Browse Source

Canvas3d.fromCanvas attribs

- simplified antialias handling
- expose preserveDrawingBuffer
Alexander Rose 4 years ago
parent
commit
b8d60cea9b
3 changed files with 22 additions and 20 deletions
  1. 17 15
      src/mol-canvas3d/canvas3d.ts
  2. 2 2
      src/mol-plugin/config.ts
  3. 3 3
      src/mol-plugin/context.ts

+ 17 - 15
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 });
     }
 

+ 2 - 2
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'),

+ 3 - 3
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;