Skip to content

Commit 572740a

Browse files
Olli Etuahophemavax
authored andcommitted
Display correct canvas size in Aquarium VR
Also set canvas size to window size at init, not just when the window is resized.
1 parent 9be02ca commit 572740a

File tree

1 file changed

+25
-68
lines changed

1 file changed

+25
-68
lines changed

aquarium-vr/aquarium-vr.js

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,27 @@ function parseQueryString(s) {
363363
return q;
364364
}
365365

366+
function setCanvasSize(canvas, newWidth, newHeight) {
367+
var changed = false;
368+
if (newWidth != canvas.width) {
369+
canvas.width = newWidth;
370+
changed = true;
371+
tdl.log("new canvas width:", newWidth);
372+
}
373+
if (newHeight != canvas.height) {
374+
canvas.height = newHeight;
375+
changed = true;
376+
tdl.log("new canvas height:", newHeight);
377+
}
378+
if (changed) {
379+
var widthElem = document.getElementById("canvasWidth");
380+
widthElem.innerHTML = canvas.width;
381+
var heightElem = document.getElementById("canvasHeight");
382+
heightElem.innerHTML = canvas.height;
383+
}
384+
return changed;
385+
}
386+
366387
function ValidateNoneOfTheArgsAreUndefined(functionName, args) {
367388
for (var ii = 0; ii < args.length; ++ii) {
368389
if (args[ii] === undefined) {
@@ -1095,54 +1116,6 @@ function initialize() {
10951116
eyeClock = now;
10961117
}
10971118

1098-
function setCanvasSize(canvas, newWidth, newHeight) {
1099-
var changed = false;
1100-
var ratio = (g.win.useDevicePixelRation && window.devicePixelRatio) ? window.devicePixelRatio : 1;
1101-
newWidth *= ratio;
1102-
newHeight *= ratio;
1103-
if (newWidth != canvas.width) {
1104-
canvas.width = newWidth;
1105-
changed = true;
1106-
tdl.log("new canvas width:", newWidth);
1107-
}
1108-
if (newHeight != canvas.height) {
1109-
canvas.height = newHeight;
1110-
changed = true;
1111-
tdl.log("new canvas height:", newHeight);
1112-
}
1113-
if (changed) {
1114-
var widthElem = document.getElementById("canvasWidth");
1115-
widthElem.innerHTML = canvas.width;
1116-
var heightElem = document.getElementById("canvasHeight");
1117-
heightElem.innerHTML = canvas.height;
1118-
1119-
//tdl.log("drawingBufferDimensions:" + gl.drawingBufferWidth + ", " + gl.drawingBufferHeight);
1120-
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
1121-
}
1122-
return changed;
1123-
}
1124-
1125-
function increaseCanvasSize(canvas) {
1126-
//tdl.log(canvas.width, canvas.clientWidth, canvas.width / canvas.clientWidth);
1127-
//tdl.log(canvas.height, canvas.clientHeight, canvas.height / canvas.clientHeight);
1128-
var newWidth = Math.min(maxViewportDims[0],
1129-
canvas.width * ((canvas.clientWidth / canvas.width > 1.2) ? 2 : 1));
1130-
var newHeight = Math.min(maxViewportDims[1],
1131-
canvas.height * ((canvas.clientHeight / canvas.height > 1.2) ? 2 : 1));
1132-
return setCanvasSize(canvas, newWidth, newHeight);
1133-
}
1134-
1135-
function decreaseCanvasSize(canvas) {
1136-
var newWidth = Math.max(512,
1137-
canvas.width * ((canvas.clientWidth / canvas.width < 0.5) ? 0.5 : 1));
1138-
var newHeight = Math.max(512,
1139-
canvas.height * ((canvas.clientHeight / canvas.height < 0.5) ? 0.5 :
1140-
1));
1141-
return setCanvasSize(canvas, newWidth, newHeight);
1142-
}
1143-
1144-
var checkResTimer = 2;
1145-
11461119
if (g.globals.width && g.globals.height) {
11471120
setCanvasSize(canvas, g.globals.width, g.globals.height);
11481121
}
@@ -1199,22 +1172,6 @@ function initialize() {
11991172
if (!g.options.reflection.enabled) { g.options.reflection.toggle(); }
12001173
}
12011174

1202-
// See if we should increase/decrease the rendering resolution
1203-
checkResTimer -= elapsedTime;
1204-
if (checkResTimer < 0) {
1205-
if (g.win && g.win.adjustRes) {
1206-
if (g_fpsTimer.averageFPS > 35) {
1207-
if (increaseCanvasSize(canvas)) {
1208-
checkResTimer = 2;
1209-
}
1210-
} else if (g_fpsTimer.averageFPS < 15) {
1211-
if (decreaseCanvasSize(canvas)) {
1212-
checkResTimer = 2;
1213-
}
1214-
}
1215-
}
1216-
}
1217-
12181175
if (g.globals.fitWindow) {
12191176
setCanvasSize(canvas, canvas.clientWidth, canvas.clientHeight);
12201177
}
@@ -2066,13 +2023,11 @@ var VR = (function() {
20662023
var leftEye = g_vrDisplay.getEyeParameters("left");
20672024
var rightEye = g_vrDisplay.getEyeParameters("right");
20682025

2069-
canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
2070-
canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
2026+
setCanvasSize(canvas, Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2, Math.max(leftEye.renderHeight, rightEye.renderHeight));
20712027
} else {
20722028
// When we're not presenting, we want to change the size of the canvas
20732029
// to match the window dimensions.
2074-
canvas.width = canvas.offsetWidth * window.devicePixelRatio;
2075-
canvas.height = canvas.offsetHeight * window.devicePixelRatio;
2030+
setCanvasSize(canvas, canvas.offsetWidth * window.devicePixelRatio, canvas.offsetHeight * window.devicePixelRatio);
20762031
}
20772032
}
20782033

@@ -2106,6 +2061,8 @@ var VR = (function() {
21062061
} else {
21072062
console.log("Your browser does not support WebVR. See webvr.info for assistance");
21082063
}
2064+
2065+
onResize();
21092066
}
21102067

21112068
window.addEventListener('DOMContentLoaded', init, false);

0 commit comments

Comments
 (0)