@@ -363,6 +363,27 @@ function parseQueryString(s) {
363
363
return q ;
364
364
}
365
365
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
+
366
387
function ValidateNoneOfTheArgsAreUndefined ( functionName , args ) {
367
388
for ( var ii = 0 ; ii < args . length ; ++ ii ) {
368
389
if ( args [ ii ] === undefined ) {
@@ -1095,54 +1116,6 @@ function initialize() {
1095
1116
eyeClock = now ;
1096
1117
}
1097
1118
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
-
1146
1119
if ( g . globals . width && g . globals . height ) {
1147
1120
setCanvasSize ( canvas , g . globals . width , g . globals . height ) ;
1148
1121
}
@@ -1199,22 +1172,6 @@ function initialize() {
1199
1172
if ( ! g . options . reflection . enabled ) { g . options . reflection . toggle ( ) ; }
1200
1173
}
1201
1174
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
-
1218
1175
if ( g . globals . fitWindow ) {
1219
1176
setCanvasSize ( canvas , canvas . clientWidth , canvas . clientHeight ) ;
1220
1177
}
@@ -2066,13 +2023,11 @@ var VR = (function() {
2066
2023
var leftEye = g_vrDisplay . getEyeParameters ( "left" ) ;
2067
2024
var rightEye = g_vrDisplay . getEyeParameters ( "right" ) ;
2068
2025
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 ) ) ;
2071
2027
} else {
2072
2028
// When we're not presenting, we want to change the size of the canvas
2073
2029
// 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 ) ;
2076
2031
}
2077
2032
}
2078
2033
@@ -2106,6 +2061,8 @@ var VR = (function() {
2106
2061
} else {
2107
2062
console . log ( "Your browser does not support WebVR. See webvr.info for assistance" ) ;
2108
2063
}
2064
+
2065
+ onResize ( ) ;
2109
2066
}
2110
2067
2111
2068
window . addEventListener ( 'DOMContentLoaded' , init , false ) ;
0 commit comments