Skip to content

Commit

Permalink
Pixi layers: fallback to WebGL1, if WebGL2 isn't available
Browse files Browse the repository at this point in the history
The PixiImageBlockLayer will now throw an error if it is initialized
without WebGl2 being available.

Fixes #1837
  • Loading branch information
tomka committed Jan 29, 2019
1 parent 2fbd1aa commit 2e400f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
constructor(...args) {
super(...args);

// This layer needs WebGL2, raise error if unavailable.
if (this._context.webglVersion < 2) {
throw new CATMAID.PreConditionError("PixiImageBlockLayer needs WebGL2, but it isn't available.");
}

this._blockCache = CATMAID.ImageBlock.GlobalCacheManager.get(this.tileSource);
this._blockCache.on(
CATMAID.ImageBlock.Cache.EVENT_BLOCK_CHANGED,
Expand Down
8 changes: 8 additions & 0 deletions django/applications/catmaid/static/js/layers/pixi-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
antialias: true,
stencil: true};
let view = document.createElement('canvas');

// Try to get WebGL 2 context, if WebGL 2 is unavailable fall back to WebGl 1.
let rawContext = view.getContext('webgl2', options);
if (rawContext) {
this.webglVersion = 2;
} else {
this.webglVersion = 1;
rawContext = view.getContext('webgl', options);
}

options.context = rawContext;
options.view = view;
Expand Down

0 comments on commit 2e400f5

Please sign in to comment.