Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The numberslider now uses a temporary uniform to control the interact…

…ive value more fluidly.
  • Loading branch information...
commit cddd97bb3690866d89a9840eb6e9deac7d3d78fe 1 parent 7b61a87
Ed Mackey authored
Showing with 57 additions and 4 deletions.
  1. +9 −3 static/index.html
  2. +48 −1 static/js/numberslider.js
12 static/index.html
View
@@ -169,7 +169,8 @@
var code, canvas, gl, buffer, currentProgram, vertexPosition, panButton,
parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 },
surface = { centerX: 0, centerY: 0, width: 1, height: 1, isPanning: false, isZooming: false, lastX: 0, lastY: 0 },
- frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true;
+ frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true,
+ useSandboxInteractiveUniform = false, interactiveUniformCode = "", interactiveUniform = 0.0;
init();
if (gl) { animate(); }
@@ -497,7 +498,7 @@
}
var program = gl.createProgram();
- var fragment = code.getValue();
+ var fragment = interactiveUniformCode || code.getValue();
var vertex = document.getElementById( 'surfaceVertexShader' ).textContent;
var vs = createShader( vertex, gl.VERTEX_SHADER );
@@ -533,7 +534,10 @@
if ( currentProgram ) {
gl.deleteProgram( currentProgram );
- setURL( fragment );
+
+ if (!useSandboxInteractiveUniform) {
+ setURL( fragment );
+ }
}
@@ -553,6 +557,7 @@
cacheUniformLocation( program, 'resolution' );
cacheUniformLocation( program, 'backbuffer' );
cacheUniformLocation( program, 'surfaceSize' );
+ cacheUniformLocation( program, 'temp_sandbox_slider' );
// Load program into GPU
@@ -811,6 +816,7 @@
gl.uniform2f( currentProgram.uniformsCache[ 'resolution' ], parameters.screenWidth, parameters.screenHeight );
gl.uniform1i( currentProgram.uniformsCache[ 'backbuffer' ], 0 );
gl.uniform2f( currentProgram.uniformsCache[ 'surfaceSize' ], surface.width, surface.height );
+ gl.uniform1f( currentProgram.uniformsCache[ 'temp_sandbox_slider' ], interactiveUniform );
gl.bindBuffer( gl.ARRAY_BUFFER, surface.buffer );
gl.vertexAttribPointer( surface.positionAttribute, 2, gl.FLOAT, false, 0, 0 );
49 static/js/numberslider.js
View
@@ -83,6 +83,7 @@ function onMouseMove(e) {
var sign = (val > 0) ? 1 : -1;
var mag = Math.abs(val);
result = current - sign + sign * Math.pow(10.0, 0.015 * mag);
+ interactiveUniform = result;
result = result.toFixed(2);
} else {
result = current + Math.round(val);
@@ -131,7 +132,7 @@ function deactivateBalloon() {
selfDestructBalloon = 0;
}
bubble.className = 'hideBubble';
-
+ endInteractiveUniform();
}
function cancelBalloon() {
@@ -143,6 +144,47 @@ function cancelBalloon() {
deactivateBalloon();
}
+function startInteractiveUniform() {
+ if (!useSandboxInteractiveUniform) {
+ useSandboxInteractiveUniform = true;
+ compileOnChangeCode = false;
+ interactiveUniform = current;
+
+ var uniformName = 'temp_sandbox_slider';
+ var oldLength = endPos.ch - startPos.ch;
+ var newLength = uniformName.length;
+
+ code.replaceRange(uniformName, startPos, endPos);
+ endPos.ch += newLength - oldLength;
+
+ interactiveUniformCode = code.getValue();
+ var pos = interactiveUniformCode.indexOf('uniform');
+ if (pos < 0) {
+ pos = 0;
+ }
+ interactiveUniformCode = interactiveUniformCode.substring(0, pos) + "uniform " +
+ (isFloat ? "float " : "int ") + uniformName + ";" +
+ interactiveUniformCode.substring(pos);
+
+ oldLength = endPos.ch - startPos.ch;
+ newLength = currentString.length;
+
+ code.replaceRange(currentString, startPos, endPos);
+ endPos.ch += newLength - oldLength;
+
+ compile();
+ }
+}
+
+function endInteractiveUniform() {
+ if (useSandboxInteractiveUniform) {
+ useSandboxInteractiveUniform = false;
+ interactiveUniformCode = "";
+ compileOnChangeCode = true;
+ compile();
+ }
+}
+
function activateBalloon() {
isBalloonOpen = true;
@@ -170,6 +212,7 @@ function activateBalloon() {
} else {
current = parseInt(currentString, 0);
}
+ startInteractiveUniform();
}
function repositionBalloon() {
@@ -212,6 +255,10 @@ s.addEventListener('mousedown', function(e) {
});
function cursorUpdate() {
+ if (!compileOnChangeCode) {
+ return;
+ }
+
var oldToken = token;
cursor = code.getCursor();
Please sign in to comment.
Something went wrong with that request. Please try again.