diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1af7997c7adb668c82012dec8cbece7eb37c92..0e53bb972707e1d8dfb53eeef07a3deaff632b63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf ## [Unreleased] +- Support for ``powerPreference`` webgl attribute. Add ``PluginConfig.General.PowerPreference`` and ``power-preference`` Viewer GET param. + ## [v3.25.1] - 2022-11-20 - Fix edge-case in `Structure.eachUnitPair` with single-element units diff --git a/src/apps/viewer/app.ts b/src/apps/viewer/app.ts index 93920c9d94511f926731d070b237c4ca0012c379..3d488ae366147da4cb8ae7c88d1716c322e41da5 100644 --- a/src/apps/viewer/app.ts +++ b/src/apps/viewer/app.ts @@ -91,6 +91,7 @@ const DefaultViewerOptions = { enableDpoit: PluginConfig.General.EnableDpoit.defaultValue, preferWebgl1: PluginConfig.General.PreferWebGl1.defaultValue, allowMajorPerformanceCaveat: PluginConfig.General.AllowMajorPerformanceCaveat.defaultValue, + powerPreference: PluginConfig.General.PowerPreference.defaultValue, viewportShowExpand: PluginConfig.Viewport.ShowExpand.defaultValue, viewportShowControls: PluginConfig.Viewport.ShowControls.defaultValue, @@ -163,6 +164,7 @@ export class Viewer { [PluginConfig.General.EnableDpoit, o.enableDpoit], [PluginConfig.General.PreferWebGl1, o.preferWebgl1], [PluginConfig.General.AllowMajorPerformanceCaveat, o.allowMajorPerformanceCaveat], + [PluginConfig.General.PowerPreference, o.powerPreference], [PluginConfig.Viewport.ShowExpand, o.viewportShowExpand], [PluginConfig.Viewport.ShowControls, o.viewportShowControls], [PluginConfig.Viewport.ShowSettings, o.viewportShowSettings], diff --git a/src/apps/viewer/index.html b/src/apps/viewer/index.html index 71d41ff6787f13b3ac4a0f40a3d57a1a0fd25cad..9918dd47d8ca700c3e4b2c4d2c9f454eb8e5a53a 100644 --- a/src/apps/viewer/index.html +++ b/src/apps/viewer/index.html @@ -63,6 +63,7 @@ var enableDpoit = getParam('enable-dpoit', '[^&]+').trim() === '1'; var preferWebgl1 = getParam('prefer-webgl1', '[^&]+').trim() === '1' || void 0; var allowMajorPerformanceCaveat = getParam('allow-major-performance-caveat', '[^&]+').trim() === '1'; + var powerPreference = getParam('power-preference', '[^&]+').trim().toLowerCase(); molstar.Viewer.create('app', { layoutShowControls: !hideControls, @@ -80,6 +81,7 @@ enableDpoit: enableDpoit ? true : void 0, preferWebgl1: preferWebgl1, allowMajorPerformanceCaveat: allowMajorPerformanceCaveat, + powerPreference: powerPreference || 'high-performance', }).then(viewer => { var snapshotId = getParam('snapshot-id', '[^&]+').trim(); if (snapshotId) viewer.setRemoteSnapshot(snapshotId); diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index ed05d3a357ba32df5d8d88e57981a2b654d5c205..b65f42eb74df809aabf86620e4d5cbd07f911673 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -120,6 +120,7 @@ interface Canvas3DContext { namespace Canvas3DContext { export const DefaultAttribs = { + powerPreference: 'high-performance' as WebGLContextAttributes['powerPreference'], failIfMajorPerformanceCaveat: false, /** true by default to avoid issues with Safari (Jan 2021) */ antialias: true, @@ -140,8 +141,9 @@ namespace Canvas3DContext { if (a.enableWboit && a.enableDpoit) throw new Error('Multiple transparency methods not allowed.'); - const { failIfMajorPerformanceCaveat, antialias, preserveDrawingBuffer, pixelScale, preferWebGl1 } = a; + const { powerPreference, failIfMajorPerformanceCaveat, antialias, preserveDrawingBuffer, pixelScale, preferWebGl1 } = a; const gl = getGLContext(canvas, { + powerPreference, failIfMajorPerformanceCaveat, antialias, preserveDrawingBuffer, diff --git a/src/mol-plugin/config.ts b/src/mol-plugin/config.ts index 8d097a20047244701bc05f203d6764ecc7ef274c..11ccf25798e2e9c5fe07f8a93a249ae6d530db10 100644 --- a/src/mol-plugin/config.ts +++ b/src/mol-plugin/config.ts @@ -37,6 +37,7 @@ export const PluginConfig = { // TODO: check back in a few weeks to see if it was fixed PreferWebGl1: item('plugin-config.prefer-webgl1', PluginFeatureDetection.preferWebGl1), AllowMajorPerformanceCaveat: item('plugin-config.allow-major-performance-caveat', false), + PowerPreference: item<WebGLContextAttributes['powerPreference']>('plugin-config.power-preference', 'high-performance'), }, 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 fd315a57e306cd784e6d3286fafd8fcf2e26a1a6..92fd7bfaa2724b7ecdbeeb0c88274b3d3727e6b9 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -267,7 +267,8 @@ export class PluginContext { const enableDpoit = this.config.get(PluginConfig.General.EnableDpoit) || false; const preferWebGl1 = this.config.get(PluginConfig.General.PreferWebGl1) || false; const failIfMajorPerformanceCaveat = !(this.config.get(PluginConfig.General.AllowMajorPerformanceCaveat) ?? false); - (this.canvas3dContext as Canvas3DContext) = Canvas3DContext.fromCanvas(canvas, this.managers.asset, { antialias, preserveDrawingBuffer, pixelScale, pickScale, pickPadding, enableWboit, enableDpoit, preferWebGl1, failIfMajorPerformanceCaveat }); + const powerPreference = this.config.get(PluginConfig.General.PowerPreference) || 'high-performance'; + (this.canvas3dContext as Canvas3DContext) = Canvas3DContext.fromCanvas(canvas, this.managers.asset, { antialias, preserveDrawingBuffer, pixelScale, pickScale, pickPadding, enableWboit, enableDpoit, preferWebGl1, failIfMajorPerformanceCaveat, powerPreference }); } (this.canvas3d as Canvas3D) = Canvas3D.create(this.canvas3dContext!); this.canvas3dInit.next(true);