diff --git a/src/graphics/graphics-library/helper/enable-extension.ts b/src/graphics/graphics-library/helper/enable-extension.ts index 16f6e32..8766093 100644 --- a/src/graphics/graphics-library/helper/enable-extension.ts +++ b/src/graphics/graphics-library/helper/enable-extension.ts @@ -1,9 +1,8 @@ import { Insights } from '../../rendering/insights'; -import { UniversalRenderingContext } from '../universal-rendering-context'; /** @internal */ export const tryEnableExtension = ( - gl: UniversalRenderingContext, + gl: WebGL2RenderingContext | WebGLRenderingContext, name: string ): any | null => { let extension = null; @@ -17,7 +16,10 @@ export const tryEnableExtension = ( }; /** @internal */ -export const enableExtension = (gl: UniversalRenderingContext, name: string): any => { +export const enableExtension = ( + gl: WebGL2RenderingContext | WebGLRenderingContext, + name: string +): any => { const extension = tryEnableExtension(gl, name); if (extension === null) { diff --git a/src/graphics/graphics-library/helper/stopwatch.ts b/src/graphics/graphics-library/helper/stopwatch.ts index 9b73e19..ff2a45b 100644 --- a/src/graphics/graphics-library/helper/stopwatch.ts +++ b/src/graphics/graphics-library/helper/stopwatch.ts @@ -1,4 +1,3 @@ -import { UniversalRenderingContext } from '../universal-rendering-context'; import { enableExtension } from './enable-extension'; /** @internal */ @@ -16,7 +15,7 @@ export class WebGlStopwatch { private timerExtension: any; private timerQuery?: WebGLQuery; - constructor(private readonly gl: UniversalRenderingContext) { + constructor(private readonly gl: WebGL2RenderingContext) { this.timerExtension = enableExtension(gl, 'EXT_disjoint_timer_query_webgl2'); } diff --git a/src/graphics/graphics-library/program/fragment-shader-only-program.ts b/src/graphics/graphics-library/program/fragment-shader-only-program.ts index dd3705d..18c53e0 100644 --- a/src/graphics/graphics-library/program/fragment-shader-only-program.ts +++ b/src/graphics/graphics-library/program/fragment-shader-only-program.ts @@ -63,7 +63,6 @@ export class FragmentShaderOnlyProgram extends Program { ); if (this.gl.isWebGL2) { - // can only return null on lost context this.vao = this.gl.createVertexArray()!; this.gl.bindVertexArray(this.vao!); } else { diff --git a/src/graphics/graphics-library/universal-rendering-context.ts b/src/graphics/graphics-library/universal-rendering-context.ts index 12d06e9..4799fcc 100644 --- a/src/graphics/graphics-library/universal-rendering-context.ts +++ b/src/graphics/graphics-library/universal-rendering-context.ts @@ -1,8 +1,9 @@ import { Insights } from '../rendering/insights'; /** @internal */ -export type UniversalRenderingContext = WebGL2RenderingContext & - WebGLRenderingContext & { isWebGL2: boolean }; +export type UniversalRenderingContext = + | (WebGL2RenderingContext & { isWebGL2: true }) + | (WebGLRenderingContext & { isWebGL2: false }); /** @internal */ export const getUniversalRenderingContext = ( @@ -43,14 +44,14 @@ export const getUniversalRenderingContext = ( const contextLostHandler = { get: function (target: UniversalRenderingContext, prop: string) { - if (isDestroyed || target.isContextLost()) { - isDestroyed = true; - throw new Error('Context lost'); - } - const value = (target as any)[prop]; if (typeof value === 'function') { + if (isDestroyed || target.isContextLost()) { + isDestroyed = true; + throw new Error('Context lost'); + } + return value.bind(target); }