Parcourir la source

WebGLRenderer: Try to initialise 'webgl' context too. WebGLRenderer3: Check if gl is null.

Mr.doob il y a 12 ans
Parent
commit
f668128084
2 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 6 0
      examples/js/renderers/WebGLRenderer3.js
  2. 11 1
      src/renderers/WebGLRenderer.js

+ 6 - 0
examples/js/renderers/WebGLRenderer3.js

@@ -39,6 +39,12 @@ THREE.WebGLRenderer3 = function ( parameters ) {
 
 
 		gl = canvas.getContext( 'webgl', attributes ) || canvas.getContext( 'experimental-webgl', attributes );
 		gl = canvas.getContext( 'webgl', attributes ) || canvas.getContext( 'experimental-webgl', attributes );
 
 
+		if ( gl === null ) {
+
+			throw 'Error creating WebGL context.';
+
+		}
+
 	} catch ( exception ) {
 	} catch ( exception ) {
 
 
 		console.error( exception );
 		console.error( exception );

+ 11 - 1
src/renderers/WebGLRenderer.js

@@ -6692,7 +6692,17 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		try {
 		try {
 
 
-			if ( ! ( _gl = _canvas.getContext( 'experimental-webgl', { alpha: _alpha, premultipliedAlpha: _premultipliedAlpha, antialias: _antialias, stencil: _stencil, preserveDrawingBuffer: _preserveDrawingBuffer } ) ) ) {
+			var attributes = {
+				alpha: _alpha,
+				premultipliedAlpha: _premultipliedAlpha,
+				antialias: _antialias,
+				stencil: _stencil,
+				preserveDrawingBuffer: _preserveDrawingBuffer
+			};
+
+			_gl = _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
+
+			if ( _gl === null ) {
 
 
 				throw 'Error creating WebGL context.';
 				throw 'Error creating WebGL context.';