From f60ae06f5913f43150bbd783c7b48e872989b60a Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Tue, 22 Sep 2020 18:20:35 +0200 Subject: [PATCH] FIx bug and bump version --- package.json | 2 +- .../universal-rendering-context.ts | 33 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 504bd3c..9663410 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sdf-2d", - "version": "0.1.1-alpha", + "version": "0.1.2-alpha", "description": "Graphics framework for efficiently rendering 2D signed distance fields.", "keywords": [ "webgl", diff --git a/src/graphics/graphics-library/universal-rendering-context.ts b/src/graphics/graphics-library/universal-rendering-context.ts index 3b299eb..ace3e99 100644 --- a/src/graphics/graphics-library/universal-rendering-context.ts +++ b/src/graphics/graphics-library/universal-rendering-context.ts @@ -7,28 +7,27 @@ export const getUniversalRenderingContext = ( canvas: HTMLCanvasElement, ignoreWebGL2 = false ): UniversalRenderingContext => { - let context: WebGL2RenderingContext | WebGLRenderingContext | null = ignoreWebGL2 + const context: WebGL2RenderingContext | WebGLRenderingContext | null = ignoreWebGL2 ? null : canvas.getContext('webgl2'); - let webgl2Support = true; + let result = context as UniversalRenderingContext; - if (!context) { - context = canvas.getContext('webgl'); - webgl2Support = false; + if (context) { + if (!Object.prototype.hasOwnProperty.call(context, 'isWebGL2')) { + result.isWebGL2 = true; + } + } else { + result = (canvas.getContext('webgl') || + canvas.getContext('experimental-webgl')) as UniversalRenderingContext; + + if (!result) { + throw new Error('Neither WebGL or WebGL2 is supported'); + } + + result.isWebGL2 = false; } - if (!context) { - context = canvas.getContext('experimental-webgl') as WebGLRenderingContext; - } - - if (!context) { - throw new Error('Neither WebGL or WebGL2 is supported'); - } - - Insights.setValue('using WebGL2', webgl2Support); - - const result = context as UniversalRenderingContext; - result.isWebGL2 = webgl2Support; + Insights.setValue('using WebGL2', result.isWebGL2); return result; };