From f68492cadd1baff0800cac80ea6fdbed77d4e2ba Mon Sep 17 00:00:00 2001 From: Lucas Dower Date: Sun, 3 Sep 2023 17:30:22 +0100 Subject: [PATCH] Upgraded WebGL context, closes #141, closes #123 --- src/renderer.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index af1035e..cc15049 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -56,7 +56,7 @@ type InternalTextureMaterial = { }; export class Renderer { - public _gl: WebGLRenderingContext; + public _gl: WebGL2RenderingContext; private _backgroundColour: RGBA = { r: 0.125, g: 0.125, b: 0.125, a: 1.0 }; private _atlasTexture?: WebGLTexture; @@ -99,9 +99,15 @@ export class Renderer { } private constructor() { - this._gl = (document.getElementById('canvas')).getContext('webgl', { + const webgl2Context = (document.getElementById('canvas')).getContext('webgl2', { alpha: false, - })!; + }); + + if (webgl2Context === null) { + throw 'Could not get WebGL2'; + } + + this._gl = webgl2Context; twgl.addExtensionsToContext(this._gl); this._backgroundColour = AppConfig.Get.VIEWPORT_BACKGROUND_COLOUR;