|
@@ -184,7 +184,21 @@ function WebGLRenderer( parameters ) {
|
|
|
|
|
|
// initialize
|
|
// initialize
|
|
|
|
|
|
- let _gl;
|
|
|
|
|
|
+ let _gl = _context;
|
|
|
|
+
|
|
|
|
+ function getContext( contextNames, contextAttributes ) {
|
|
|
|
+
|
|
|
|
+ for ( let i = 0; i < contextNames.length; i ++ ) {
|
|
|
|
+
|
|
|
|
+ const contextName = contextNames[ i ];
|
|
|
|
+ const context = _canvas.getContext( contextName, contextAttributes );
|
|
|
|
+ if ( context !== null ) return context;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
@@ -204,25 +218,29 @@ function WebGLRenderer( parameters ) {
|
|
_canvas.addEventListener( 'webglcontextlost', onContextLost, false );
|
|
_canvas.addEventListener( 'webglcontextlost', onContextLost, false );
|
|
_canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
|
|
_canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
|
|
|
|
|
|
- if ( this.isWebGL1Renderer === true ) {
|
|
|
|
|
|
+ if ( _gl === null ) {
|
|
|
|
+
|
|
|
|
+ const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
|
|
|
|
|
|
- _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
|
|
|
|
|
|
+ if ( _this.isWebGL1Renderer === true ) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ contextNames.shift();
|
|
|
|
|
|
- _gl = _context || _canvas.getContext( 'webgl2', contextAttributes ) || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ _gl = getContext( contextNames, contextAttributes );
|
|
|
|
|
|
- if ( _gl === null ) {
|
|
|
|
|
|
+ if ( _gl === null ) {
|
|
|
|
|
|
- if ( _canvas.getContext( 'webgl2' ) || _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' ) ) {
|
|
|
|
|
|
+ if ( getContext( contextNames ) ) {
|
|
|
|
|
|
- throw new Error( 'Error creating WebGL context with your selected attributes.' );
|
|
|
|
|
|
+ throw new Error( 'Error creating WebGL context with your selected attributes.' );
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- throw new Error( 'Error creating WebGL context.' );
|
|
|
|
|
|
+ throw new Error( 'Error creating WebGL context.' );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|