From bde2fb9aa52589574b9173a025812b9ee0a89e68 Mon Sep 17 00:00:00 2001
From: liying3
diff --git a/js/frag_globe.js b/js/frag_globe.js index 125a6d3..70fc491 100644 --- a/js/frag_globe.js +++ b/js/frag_globe.js @@ -56,6 +56,17 @@ var u_BumpLocation; var u_timeLocation; + //stas.js + var statsInitShader = new Stats(); + statsInitShader.setMode(1); // 0: fps, 1: ms + statsInitShader.domElement.style.position = 'absolute'; + statsInitShader.domElement.style.right = '0px'; + statsInitShader.domElement.style.top = '0'; + document.body.appendChild(statsInitShader.domElement ); + var initS = document.createElement('div'); + initS.innerHTML = 'init shader'; + statsInitShader.domElement.appendChild(initS); + statsInitShader.begin(); (function initializeShader() { var vs = getShaderSource(document.getElementById("vs")); var fs = getShaderSource(document.getElementById("fs")); @@ -79,6 +90,7 @@ gl.useProgram(program); })(); + statsInitShader.end(); var dayTex = gl.createTexture(); var bumpTex = gl.createTexture(); @@ -87,6 +99,17 @@ var lightTex = gl.createTexture(); var specTex = gl.createTexture(); + //stas.js + var statsInitTexture = new Stats(); + statsInitTexture.setMode(1); // 0: fps, 1: ms + statsInitTexture.domElement.style.position = 'absolute'; + statsInitTexture.domElement.style.right = '0px'; + statsInitTexture.domElement.style.top = '80px'; + document.body.appendChild( statsInitTexture.domElement ); + var initT = document.createElement('div'); + initT.innerHTML = 'init texture'; + statsInitTexture.domElement.appendChild(initT); + statsInitTexture.begin(); function initLoadedTexture(texture){ gl.bindTexture(gl.TEXTURE_2D, texture); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); @@ -97,9 +120,22 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); gl.bindTexture(gl.TEXTURE_2D, null); } + statsInitTexture.end(); var numberOfIndices; - + + //stas.js + var statsInitSphere = new Stats(); + statsInitSphere.setMode(1); // 0: fps, 1: ms + statsInitSphere.domElement.style.position = 'absolute'; + statsInitSphere.domElement.style.right = '0px'; + statsInitSphere.domElement.style.top = '160px'; + document.body.appendChild( statsInitSphere.domElement ); + var initSphere = document.createElement('div'); + initSphere.innerHTML = 'init sphere'; + statsInitSphere.domElement.appendChild(initSphere); + statsInitSphere.begin(); + (function initializeSphere() { function uploadMesh(positions, texCoords, indices) { // Positions @@ -174,6 +210,7 @@ uploadMesh(positions, texCoords, indices); numberOfIndices = indicesIndex; })(); + statsInitSphere.end(); var time = 0; var mouseLeftDown = false; @@ -233,10 +270,21 @@ document.onmouseup = handleMouseUp; document.onmousemove = handleMouseMove; - + //stas.js + var statsAnimate = new Stats(); + statsAnimate.setMode(1); // 0: fps, 1: ms + statsAnimate.domElement.style.position = 'absolute'; + statsAnimate.domElement.style.right = '0'; + statsAnimate.domElement.style.top = '240px'; + document.body.appendChild( statsAnimate.domElement ); + var anim = document.createElement('div'); + anim.innerHTML = 'animate'; + statsAnimate.domElement.appendChild(anim); + function animate() { /////////////////////////////////////////////////////////////////////////// // Update + statsAnimate.begin(); var model = mat4.create(); mat4.identity(model); @@ -290,6 +338,9 @@ time += 0.001; gl.uniform1f(u_timeLocation, time); + + statsAnimate.end(); + window.requestAnimFrame(animate); } diff --git a/js/lib/stats.js b/js/lib/stats.js new file mode 100644 index 0000000..90b2a27 --- /dev/null +++ b/js/lib/stats.js @@ -0,0 +1,149 @@ +/** + * @author mrdoob / http://mrdoob.com/ + */ + +var Stats = function () { + + var startTime = Date.now(), prevTime = startTime; + var ms = 0, msMin = Infinity, msMax = 0; + var fps = 0, fpsMin = Infinity, fpsMax = 0; + var frames = 0, mode = 0; + + var container = document.createElement( 'div' ); + container.id = 'stats'; + container.addEventListener( 'mousedown', function ( event ) { event.preventDefault(); setMode( ++ mode % 2 ) }, false ); + container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer'; + + var fpsDiv = document.createElement( 'div' ); + fpsDiv.id = 'fps'; + fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002'; + container.appendChild( fpsDiv ); + + var fpsText = document.createElement( 'div' ); + fpsText.id = 'fpsText'; + fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; + fpsText.innerHTML = 'FPS'; + fpsDiv.appendChild( fpsText ); + + var fpsGraph = document.createElement( 'div' ); + fpsGraph.id = 'fpsGraph'; + fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff'; + fpsDiv.appendChild( fpsGraph ); + + while ( fpsGraph.children.length < 74 ) { + + var bar = document.createElement( 'span' ); + bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113'; + fpsGraph.appendChild( bar ); + + } + + var msDiv = document.createElement( 'div' ); + msDiv.id = 'ms'; + msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none'; + container.appendChild( msDiv ); + + var msText = document.createElement( 'div' ); + msText.id = 'msText'; + msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; + msText.innerHTML = 'MS'; + msDiv.appendChild( msText ); + + var msGraph = document.createElement( 'div' ); + msGraph.id = 'msGraph'; + msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0'; + msDiv.appendChild( msGraph ); + + while ( msGraph.children.length < 74 ) { + + var bar = document.createElement( 'span' ); + bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131'; + msGraph.appendChild( bar ); + + } + + var setMode = function ( value ) { + + mode = value; + + switch ( mode ) { + + case 0: + fpsDiv.style.display = 'block'; + msDiv.style.display = 'none'; + break; + case 1: + fpsDiv.style.display = 'none'; + msDiv.style.display = 'block'; + break; + } + + }; + + var updateGraph = function ( dom, value ) { + + var child = dom.appendChild( dom.firstChild ); + child.style.height = value + 'px'; + + }; + + return { + + REVISION: 12, + + domElement: container, + + setMode: setMode, + + begin: function () { + + startTime = Date.now(); + + }, + + end: function () { + + var time = Date.now(); + + ms = time - startTime; + msMin = Math.min( msMin, ms ); + msMax = Math.max( msMax, ms ); + + msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')'; + updateGraph( msGraph, Math.min( 30, 30 - ( ms / 200 ) * 30 ) ); + + frames ++; + + if ( time > prevTime + 1000 ) { + + fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) ); + fpsMin = Math.min( fpsMin, fps ); + fpsMax = Math.max( fpsMax, fps ); + + fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')'; + updateGraph( fpsGraph, Math.min( 30, 30 - ( fps / 100 ) * 30 ) ); + + prevTime = time; + frames = 0; + + } + + return time; + + }, + + update: function () { + + startTime = this.end(); + + } + + } + +}; + +if ( typeof module === 'object' ) { + + module.exports = Stats; + +} \ No newline at end of file diff --git a/js/webGLUtility.js b/js/webGLUtility.js index 134a93e..311dbdd 100644 --- a/js/webGLUtility.js +++ b/js/webGLUtility.js @@ -5,6 +5,7 @@ // University of Pennsylvania (c) 2014 (function(exports) { + "use strict"; exports = exports || window; diff --git a/vert_wave - Copy.html b/vert_wave - Copy.html new file mode 100644 index 0000000..677a07f --- /dev/null +++ b/vert_wave - Copy.html @@ -0,0 +1,255 @@ + + +
+
+ + + + +
+ +