@@ -10,6 +10,8 @@ self.WebGL2RenderingContext = undefined; */
10
10
11
11
const { /*WebGLRenderingContext, WebGL2RenderingContext,*/ CanvasRenderingContext2D} = self ;
12
12
13
+ const hasWebGL2 = ! ! window . WebGL2RenderingContext ;
14
+
13
15
const _makeState = ( ) => {
14
16
const gl = GlobalContext . proxyContext ;
15
17
@@ -93,7 +95,7 @@ const _makeState = () => {
93
95
} ;
94
96
HTMLCanvasElement . prototype . getContext = ( oldGetContext => function getContext ( type , init = { } ) {
95
97
const match = type . match ( / ^ (?: e x p e r i m e n t a l - ) ? ( w e b g l 2 ? ) $ / ) ;
96
- if ( match ) {
98
+ if ( match && ( hasWebGL2 || match [ 1 ] !== 'webgl2' ) ) {
97
99
window [ symbols . ensureProxyContext ] ( ) ;
98
100
99
101
const canvas = this ;
@@ -136,7 +138,11 @@ HTMLCanvasElement.prototype.getBoundingClientRect = function getBoundingClientRe
136
138
return new DOMRect ( canvasViewport [ 0 ] , canvasViewport [ 1 ] , canvasViewport [ 2 ] , canvasViewport [ 3 ] ) ;
137
139
} ;
138
140
139
- const [ WebGLRenderingContext , WebGL2RenderingContext ] = [ self . WebGLRenderingContext , self . WebGL2RenderingContext ] . map ( WebGLRenderingContext => {
141
+ const [ WebGLRenderingContext , WebGL2RenderingContext ] = [ window . WebGLRenderingContext , window . WebGL2RenderingContext ] . map ( WebGLRenderingContext => {
142
+
143
+ if ( ! WebGLRenderingContext ) {
144
+ return WebGLRenderingContext ;
145
+ }
140
146
141
147
function ProxiedWebGLRenderingContext ( canvas ) {
142
148
Object . defineProperty ( this , 'canvas' , { // Object.defineProperty to avoid proxying
@@ -151,13 +157,15 @@ function ProxiedWebGLRenderingContext(canvas) {
151
157
clear : true ,
152
158
} ;
153
159
154
- if ( this . createVertexArray ) {
155
- const vao = this . createVertexArray ( ) ;
156
- this . bindVertexArray ( vao ) ;
157
- } else {
158
- const extension = this . getExtension ( 'OES_vertex_array_object' ) ;
159
- const vao = extension . createVertexArrayOES ( ) ;
160
- extension . bindVertexArrayOES ( vao ) ;
160
+ if ( hasWebGL2 ) {
161
+ if ( this . createVertexArray ) {
162
+ const vao = this . createVertexArray ( ) ;
163
+ this . bindVertexArray ( vao ) ;
164
+ } else {
165
+ const extension = this . getExtension ( 'OES_vertex_array_object' ) ;
166
+ const vao = extension . createVertexArrayOES ( ) ;
167
+ extension . bindVertexArrayOES ( vao ) ;
168
+ }
161
169
}
162
170
163
171
GlobalContext . contexts . push ( this ) ;
@@ -228,7 +236,11 @@ class OES_vertex_array_object {
228
236
}
229
237
ProxiedWebGLRenderingContext . prototype . getExtension = ( _getExtension => function getExtension ( name ) {
230
238
if ( name === 'OES_vertex_array_object' ) {
231
- return new OES_vertex_array_object ( this ) ;
239
+ if ( hasWebGL2 ) {
240
+ return new OES_vertex_array_object ( this ) ;
241
+ } else {
242
+ return GlobalContext . proxyContext . getExtension ( name ) ;
243
+ }
232
244
} else if ( [
233
245
'EXT_texture_filter_anisotropic' ,
234
246
'WEBGL_debug_renderer_info' ,
@@ -259,7 +271,9 @@ ProxiedWebGLRenderingContext.prototype.setProxyState = function setProxyState()
259
271
const { state} = this ;
260
272
const gl = GlobalContext . proxyContext ;
261
273
262
- gl . bindVertexArray ( state . vao ) ;
274
+ if ( hasWebGL2 ) {
275
+ gl . bindVertexArray ( state . vao ) ;
276
+ }
263
277
264
278
gl . bindBuffer ( gl . ARRAY_BUFFER , state . arrayBuffer ) ;
265
279
for ( const k in state . renderbuffer ) {
@@ -570,7 +584,7 @@ ProxiedWebGLRenderingContext.prototype.deleteTexture = (_deleteTexture => functi
570
584
} ) ( ProxiedWebGLRenderingContext . prototype . deleteTexture ) ;
571
585
572
586
// WebGL1 -> WebGL2 translations
573
- if ( WebGLRenderingContext . name === 'WebGLRenderingContext' ) {
587
+ if ( hasWebGL2 && WebGLRenderingContext . name === 'WebGLRenderingContext' ) {
574
588
const glslVersion = '300 es' ;
575
589
ProxiedWebGLRenderingContext . prototype . createShader = ( _createShader => function createShader ( type ) {
576
590
const result = _createShader . call ( this , type ) ;
0 commit comments