Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #14967 from mrdoob/detector_refactor
Refactored Detector.js into WebGL.js
  • Loading branch information
mrdoob committed Sep 26, 2018
2 parents 042bd73 + d3f5a0b commit 63eca7a
Show file tree
Hide file tree
Showing 233 changed files with 1,595 additions and 796 deletions.
91 changes: 0 additions & 91 deletions examples/js/Detector.js

This file was deleted.

94 changes: 94 additions & 0 deletions examples/js/WebGL.js
@@ -0,0 +1,94 @@
/**
* @author alteredq / http://alteredqualia.com/
* @author mr.doob / http://mrdoob.com/
*/

var WEBGL = {

isWebGLAvailable: function () {

try {

var canvas = document.createElement( 'canvas' );
return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );

} catch ( e ) {

return false;

}

},

isWebGL2Available: function () {

try {

var canvas = document.createElement( 'canvas' );
return !! ( window.WebGL2RenderingContext && canvas.getContext( 'webgl2' ) );

} catch ( e ) {

return false;

}

},

getWebGLErrorMessage: function () {

return this.getErrorMessage( 1 );

},

getWebGL2ErrorMessage: function () {

return this.getErrorMessage( 2 );

},

getErrorMessage: function ( version ) {

var names = {
1: 'WebGL',
2: 'WebGL 2'
};

var contexts = {
1: window.WebGLRenderingContext,
2: window.WebGL2RenderingContext
};

var message = 'Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>';

var element = document.createElement( 'div' );
element.id = 'webglmessage';
element.style.fontFamily = 'monospace';
element.style.fontSize = '13px';
element.style.fontWeight = 'normal';
element.style.textAlign = 'center';
element.style.background = '#fff';
element.style.color = '#000';
element.style.padding = '1.5em';
element.style.width = '400px';
element.style.margin = '5em auto 0';

if ( contexts[ version ] ) {

message = message.replace( '$0', 'graphics card' );

} else {

message = message.replace( '$0', 'browser' );

}

message = message.replace( '$1', names[ version ] );

element.innerHTML = message;

return element;

}

};
8 changes: 6 additions & 2 deletions examples/misc_animation_groups.html
Expand Up @@ -35,12 +35,16 @@
</div>

<script src="../build/three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/stats.min.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var stats, clock;
var scene, camera, renderer, mixer;
Expand Down
8 changes: 6 additions & 2 deletions examples/misc_animation_keys.html
Expand Up @@ -35,12 +35,16 @@
</div>

<script src="../build/three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/stats.min.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var stats, clock;
var scene, camera, renderer, mixer;
Expand Down
8 changes: 6 additions & 2 deletions examples/misc_controls_fly.html
Expand Up @@ -46,7 +46,7 @@
<script src="js/postprocessing/RenderPass.js"></script>
<script src="js/postprocessing/FilmPass.js"></script>

<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/stats.min.js"></script>

</head>
Expand All @@ -59,7 +59,11 @@

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var radius = 6371;
var tilt = 0.41;
Expand Down
8 changes: 6 additions & 2 deletions examples/misc_controls_map.html
Expand Up @@ -38,13 +38,17 @@

<script src="../build/three.js"></script>
<script src="js/controls/MapControls.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>

<script src='js/libs/dat.gui.min.js'></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var camera, controls, scene, renderer;

Expand Down
8 changes: 6 additions & 2 deletions examples/misc_controls_orbit.html
Expand Up @@ -38,11 +38,15 @@

<script src="../build/three.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var camera, controls, scene, renderer;

Expand Down
8 changes: 6 additions & 2 deletions examples/misc_controls_trackball.html
Expand Up @@ -41,12 +41,16 @@

<script src="js/controls/TrackballControls.js"></script>

<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/stats.min.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var camera, controls, scene, renderer, stats;

Expand Down
8 changes: 6 additions & 2 deletions examples/misc_exporter_gltf.html
Expand Up @@ -40,7 +40,7 @@

<script src="../build/three.js"></script>

<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/loaders/OBJLoader.js"></script>
<script src="js/exporters/GLTFExporter.js"></script>

Expand Down Expand Up @@ -140,7 +140,11 @@

}

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var container;

Expand Down
8 changes: 6 additions & 2 deletions examples/misc_exporter_stl.html
Expand Up @@ -35,12 +35,16 @@
<script src="js/controls/OrbitControls.js"></script>
<script src="js/exporters/STLExporter.js"></script>

<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/dat.gui.min.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var scene, camera, renderer, exporter, mesh;

Expand Down
8 changes: 6 additions & 2 deletions examples/webaudio_orientation.html
Expand Up @@ -67,7 +67,7 @@
</style>

<script src="../build/three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/loaders/GLTFLoader.js"></script>

Expand All @@ -93,7 +93,11 @@

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var scene, camera, renderer;

Expand Down
8 changes: 6 additions & 2 deletions examples/webaudio_sandbox.html
Expand Up @@ -83,12 +83,16 @@
<script src="../build/three.js"></script>

<script src="js/controls/FirstPersonControls.js"></script>
<script src="js/Detector.js"></script>
<script src="js/WebGL.js"></script>
<script src="js/libs/dat.gui.min.js"></script>

<script>

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( WEBGL.isWebGLAvailable() === false ) {

document.body.appendChild( WEBGL.getWebGLErrorMessage() );

}

var camera, controls, scene, renderer;
var light, pointLight;
Expand Down

0 comments on commit 63eca7a

Please sign in to comment.