Skip to content

Commit a4bfad1

Browse files
cabaniertoji
authored andcommitted
Add support for forceMonoPresentation to layers samples
1 parent 9e1b8f5 commit a4bfad1

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

layers-samples/cyld-layer.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
let cyldTextureWidth = 0;
9494
let cyldTextureHeight = 0;
9595

96+
function buttonPressedThisFrame(gamepad, index) {
97+
return (index < gamepad.buttons.length &&
98+
gamepad.buttons[index].pressed);
99+
}
100+
96101
function initXR() {
97102
xrButton = new WebXRButton({
98103
onRequestSession: onRequestSession,
@@ -213,6 +218,12 @@
213218
gl.bindTexture(gl.TEXTURE_2D, null);
214219
}
215220

221+
let force_mono = false;
222+
for (let source of xrSession.inputSources) {
223+
force_mono |= buttonPressedThisFrame(source.gamepad, 0);
224+
}
225+
cyldLayer.forceMonoPresentation = force_mono;
226+
216227
if (pose) {
217228
gl.bindFramebuffer(gl.FRAMEBUFFER, xrFramebuffer);
218229
scene.updateInputSources(frame, xrRefSpace);

layers-samples/eqrt-video.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
<details open>
4343
<summary>Equirect Video</summary>
4444
<p>
45-
This sample shows how to show 180/360 video via an equirect layer, with
46-
the addition of media control bar that enables fast forward/rewind,
47-
pause/play and exit. It can be used for rendering static backgrounds like cube
48-
layers, as demonstrated in the Equirect Layer example, but the real edge
45+
This sample shows how to show 180/360 video via an equirect layer, with
46+
the addition of media control bar that enables fast forward/rewind,
47+
pause/play and exit. It can be used for rendering static backgrounds like cube
48+
layers, as demonstrated in the Equirect Layer example, but the real edge
4949
of using equirect layers over cube layers is to show immersive video.
5050
</p>
5151
<p>
52-
NOTE: Depending on your internet connection, the fast forward and rewind
52+
NOTE: Depending on your internet connection, the fast forward and rewind
5353
buttons may not immediately take effect.
5454
</p>
5555
<a class="back" href="./index.html">Back</a>
@@ -222,6 +222,11 @@
222222
gl = null;
223223
}
224224

225+
function buttonPressedThisFrame(gamepad, index) {
226+
return (index < gamepad.buttons.length &&
227+
gamepad.buttons[index].pressed);
228+
}
229+
225230
function onXRFrame(time, frame) {
226231
let pose = frame.getViewerPose(xrRefSpace);
227232
xrSession.requestAnimationFrame(onXRFrame);
@@ -238,6 +243,12 @@
238243
gl.bindTexture(gl.TEXTURE_2D, null);
239244
}
240245

246+
let force_mono = false;
247+
for (let source of xrSession.inputSources) {
248+
force_mono |= buttonPressedThisFrame(source.gamepad, 4);
249+
}
250+
eqrtLayer.forceMonoPresentation = force_mono;
251+
241252
if (pose) {
242253
gl.bindFramebuffer(gl.FRAMEBUFFER, xrFramebuffer);
243254
// We need to invalidate the color (and depth, just in case) here to avoid
@@ -267,4 +278,4 @@
267278
</script>
268279
</body>
269280

270-
</html>
281+
</html>

layers-samples/media-layer-sample.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
// Inform the session that we're ready for the next frame.
180180
session.requestAnimationFrame(onXRFrame);
181181

182+
let force_mono = false;
182183
for (let source of session.inputSources) {
183184
if (source.gamepad) {
184185
// Toggle Play/Pause on primary button press
@@ -191,8 +192,10 @@
191192
else
192193
video.pause();
193194
}
195+
force_mono |= buttonPressedThisFrame(source.gamepad, 4);
194196
}
195197
}
198+
xrSession.renderState.layers[0].forceMonoPresentation = force_mono;
196199
}
197200

198201
// Start the XR application.

0 commit comments

Comments
 (0)