@cornerstonejs/core
Version:
Cornerstone3D Core
23 lines (22 loc) • 921 B
JavaScript
import eventTarget from '../../eventTarget.js';
import { Events } from '../../enums/index.js';
import triggerEvent from '../../utilities/triggerEvent.js';
export function attachWebGLContextEvents(offscreenMultiRenderWindow, renderingEngineId, contextIndex = 0) {
const canvas = offscreenMultiRenderWindow.getOpenGLRenderWindow?.()?.getCanvas?.();
if (!canvas) {
return;
}
canvas.addEventListener('webglcontextlost', () => {
console.warn(`CornerstoneRender: WebGL context lost (renderingEngine=${renderingEngineId}, context=${contextIndex})`);
triggerEvent(eventTarget, Events.WEBGL_CONTEXT_LOST, {
renderingEngineId,
contextIndex,
});
});
canvas.addEventListener('webglcontextrestored', () => {
triggerEvent(eventTarget, Events.WEBGL_CONTEXT_RESTORED, {
renderingEngineId,
contextIndex,
});
});
}