Skip to content

Commit

Permalink
exposed webgl context state from animation loop (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta committed Feb 16, 2021
1 parent b753c3e commit 8731d4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/api-reference/engine/animation-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Returns returns a `Promise` that resolves to the data URL of the canvas once dra

`animationLoop.toDataURL()`

### isContextLost()

Returns the current state of the WebGL context used by the animation loop.

## Callback Parameters

The callbacks `onInitialize`, `onRender` and `onFinalize` that the app supplies to the `AnimationLoop`, will be called with an object containing named parameters:
Expand Down
1 change: 1 addition & 0 deletions modules/engine/src/lib/animation-loop.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default class AnimationLoop {
toDataURL(): Promise<string>;
setViewParameters(): AnimationLoop;
getHTMLControlValue(id: string, defaultValue?: number): number;
isContextLost(): boolean;

// Callbacks
onCreateContext(opts: CreateGLContextOptions): WebGLRenderingContext;
Expand Down
8 changes: 8 additions & 0 deletions modules/engine/src/lib/animation-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export default class AnimationLoop {

// Redraw now
redraw() {
if (this.isContextLost()) {
return this;
}

this._beginTimers();

this._setupFrame();
Expand Down Expand Up @@ -249,6 +253,10 @@ export default class AnimationLoop {
return this.gl.canvas.toDataURL();
}

isContextLost() {
return this.gl.isContextLost();
}

onCreateContext(...args) {
return this.props.onCreateContext(...args);
}
Expand Down
2 changes: 2 additions & 0 deletions modules/engine/test/lib/animation-loop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test('core#AnimationLoop start,stop', t => {
onRender: () => {
renderCalled++;

t.is(animationLoop.isContextLost(), false, 'isContextLost returns false');

animationLoop.stop();

t.is(initializeCalled, 1, 'onInitialize called');
Expand Down

0 comments on commit 8731d4c

Please sign in to comment.