OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var webglCanvas = document.getElementById("webgl-canvas"); | 5 var webglCanvas = document.getElementById("webgl-canvas"); |
6 var glAttribs = { | 6 var glAttribs = { |
7 alpha: false, | 7 alpha: false, |
8 }; | 8 }; |
9 var gl = webglCanvas.getContext("webgl", glAttribs); | 9 var gl = webglCanvas.getContext("webgl", glAttribs); |
10 var vrDisplay = null; | 10 var vrDisplay = null; |
11 var frameData = null; | 11 var frameData = null; |
| 12 var onAnimationFrameCallback = null; |
12 | 13 |
13 function onResize() { | 14 function onResize() { |
14 if (vrDisplay && vrDisplay.isPresenting) { | 15 if (vrDisplay && vrDisplay.isPresenting) { |
15 var leftEye = vrDisplay.getEyeParameters("left"); | 16 var leftEye = vrDisplay.getEyeParameters("left"); |
16 var rightEye = vrDisplay.getEyeParameters("right"); | 17 var rightEye = vrDisplay.getEyeParameters("right"); |
17 | 18 |
18 webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2; | 19 webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2; |
19 webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight); | 20 webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight); |
20 } else { | 21 } else { |
21 webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio; | 22 webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio; |
(...skipping 11 matching lines...) Expand all Loading... |
33 | 34 |
34 function onAnimationFrame(t) { | 35 function onAnimationFrame(t) { |
35 if (vrDisplay == null) { | 36 if (vrDisplay == null) { |
36 window.requestAnimationFrame(onAnimationFrame); | 37 window.requestAnimationFrame(onAnimationFrame); |
37 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height); | 38 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height); |
38 return; | 39 return; |
39 } | 40 } |
40 vrDisplay.requestAnimationFrame(onAnimationFrame); | 41 vrDisplay.requestAnimationFrame(onAnimationFrame); |
41 // If presenting, set canvas to blue. Otherwise, red. | 42 // If presenting, set canvas to blue. Otherwise, red. |
42 if (vrDisplay.isPresenting) { | 43 if (vrDisplay.isPresenting) { |
| 44 if (onAnimationFrameCallback) onAnimationFrameCallback(); |
43 vrDisplay.getFrameData(frameData); | 45 vrDisplay.getFrameData(frameData); |
44 | 46 |
45 gl.clearColor(0.0, 0.0, 1.0, 1.0); | 47 gl.clearColor(0.0, 0.0, 1.0, 1.0); |
46 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | 48 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
47 | 49 |
48 gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height); | 50 gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height); |
49 gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5, | 51 gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5, |
50 webglCanvas.height); | 52 webglCanvas.height); |
51 | 53 |
52 vrDisplay.submitFrame(); | 54 vrDisplay.submitFrame(); |
(...skipping 20 matching lines...) Expand all Loading... |
73 | 75 |
74 gl.clearColor(1.0, 0.0, 0.0, 1.0); | 76 gl.clearColor(1.0, 0.0, 0.0, 1.0); |
75 gl.enable(gl.DEPTH_TEST); | 77 gl.enable(gl.DEPTH_TEST); |
76 gl.enable(gl.CULL_FACE); | 78 gl.enable(gl.CULL_FACE); |
77 window.addEventListener("resize", onResize, false); | 79 window.addEventListener("resize", onResize, false); |
78 window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false); | 80 window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false); |
79 window.addEventListener('vrdisplayactivate', onVrRequestPresent, false); | 81 window.addEventListener('vrdisplayactivate', onVrRequestPresent, false); |
80 window.requestAnimationFrame(onAnimationFrame); | 82 window.requestAnimationFrame(onAnimationFrame); |
81 webglCanvas.onclick = onVrRequestPresent; | 83 webglCanvas.onclick = onVrRequestPresent; |
82 onResize(); | 84 onResize(); |
OLD | NEW |