1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
---
title: VRDisplay
slug: Web/API/VRDisplay
tags:
- API
- DOM
- Experimental
- Interface
- Media
- NeedsTranslation
- Reference
- TopicStub
- VR
- VRDisplay
- Virtual Reality
- WebVR
translation_of: Web/API/VRDisplay
---
<div>{{APIRef("WebVR API")}}{{SeeCompatTable}}</div>
<p>The <strong><code>VRDisplay</code></strong> interface of the <a href="/en-US/docs/Web/API/WebVR_API">WebVR API</a> represents any VR device supported by this API. It includes generic information such as device IDs and descriptions, as well as methods for starting to present a VR scene, retrieving eye parameters and display capabilities, and other important functionality.</p>
<p>An array of all connected VR Devices can be returned by invoking the {{domxref("Navigator.getVRDisplays()")}} method.</p>
<h2 id="Properties">Properties</h2>
<dl>
<dt>{{domxref("VRDisplay.capabilities")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("VRDisplayCapabilities")}} object that indicates the various capabilities of the <code>VRDisplay</code>.</dd>
<dt>{{domxref("VRDisplay.depthFar")}}</dt>
<dd>Gets and sets the z-depth defining the far plane of the <a href="https://en.wikipedia.org/wiki/Viewing_frustum">eye view frustum</a>, i.e. the furthest viewable boundary of the scene.</dd>
<dt>{{domxref("VRDisplay.depthNear")}}</dt>
<dd>Gets and sets the z-depth defining the near plane of the <a href="https://en.wikipedia.org/wiki/Viewing_frustum">eye view frustum</a>, i.e. the nearest viewable boundary of the scene.</dd>
<dt>{{domxref("VRDisplay.displayId")}} {{readonlyInline}}</dt>
<dd>Returns an identifier for this particular VRDisplay, which is also used as an association point in the <a href="/en-US/docs/Web/API/Gamepad_API">Gamepad API</a> (see {{domxref("Gamepad.displayId")}}).</dd>
<dt>{{domxref("VRDisplay.displayName")}} {{readonlyInline}}</dt>
<dd>Returns a human-readable name to identify the <code>VRDisplay</code>.</dd>
<dt>{{domxref("VRDisplay.isConnected")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("Boolean")}} indicating whether the <code>VRDisplay</code> is connected to the computer.</dd>
<dt>{{domxref("VRDisplay.isPresenting")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("Boolean")}} indicating whether the <code>VRDisplay</code> is currently having content presented through it.</dd>
<dt>{{domxref("VRDisplay.stageParameters")}} {{readonlyInline}}</dt>
<dd>Returns a {{domxref("VRStageParameters")}} object containing room-scale parameters, if the <code>VRDisplay</code> is capable of supporting room-scale experiences.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<dl>
<dt>{{domxref("VRDisplay.getEyeParameters()")}}</dt>
<dd>Returns the {{domxref("VREyeParameters")}} object containing the eye parameters for the specified eye.</dd>
<dt>{{domxref("VRDisplay.getFrameData()")}}</dt>
<dd>Accepts a {{domxref("VRFrameData")}} object and populates it with the information required to render the current frame.</dd>
<dt>{{domxref("VRDisplay.getLayers()")}}</dt>
<dd>Returns the layers currently being presented by the <code>VRDisplay</code>.</dd>
<dt>{{domxref("VRDisplay.resetPose()")}}</dt>
<dd>Resets the pose for this <code>VRDisplay</code>, treating its current {{domxref("VRPose.position")}} and {{domxref("VRPose.orientation")}} as the "origin/zero" values.</dd>
<dt>{{domxref("VRDisplay.cancelAnimationFrame()")}}</dt>
<dd>A special implementation of {{domxref("Window.cancelAnimationFrame")}} that allows callbacks registered with {{domxref("VRDisplay.requestAnimationFrame()")}} to be unregistered.</dd>
<dt>{{domxref("VRDisplay.requestAnimationFrame()")}}</dt>
<dd>A special implementation of {{domxref("Window.requestAnimationFrame")}} containing a callback function that will be called every time a new frame of the <code>VRDisplay</code> presentation is rendered.</dd>
<dt>{{domxref("VRDisplay.requestPresent()")}}</dt>
<dd>Starts the <code>VRDisplay</code> presenting a scene.</dd>
<dt>{{domxref("VRDisplay.exitPresent()")}}</dt>
<dd>Stops the <code>VRDisplay</code> presenting a scene.</dd>
<dt>{{domxref("VRDisplay.submitFrame()")}}</dt>
<dd>Captures the current state of the {{domxref("VRLayer")}} currently being presented and displays it on the <code>VRDisplay</code>.</dd>
</dl>
<h3 id="Deprecated_methods">Deprecated methods</h3>
<dl>
<dt>{{domxref("VRDisplay.getPose()")}} {{deprecated_inline}}</dt>
<dd>Returns a {{domxref("VRPose")}} object defining the future predicted pose of the <code>VRDisplay</code> as it will be when the current frame is actually presented. <strong>This method is deprecated — instead, you should use {{domxref("VRDisplay.getFrameData()")}}, which also provides a {{domxref("VRPose")}} object.</strong></dd>
</dl>
<h3 id="Obsolete_methods">Obsolete methods</h3>
<dl>
<dt>{{domxref("VRDisplay.getImmediatePose()")}} {{obsolete_inline}}</dt>
<dd>Returns a {{domxref("VRPose")}} object defining the current pose of the <code>VRDisplay</code>, with no prediction applied. This is no longer needed, and has been removed from the spec.</dd>
<dt>{{domxref("VRDisplay.hardwareUnitId")}} {{obsolete_inline}}</dt>
<dd>Returns a {{domxref("DOMString")}} defining the shared ID of the display, and any other devices that are part of that hardware set (e.g. controllers). This is no longer needed, and has been removed from the spec. Displays now use {{domxref("VRDisplay.displayId")}}, and corresponsing controllers will now return the same ID under {{domxref("Gamepad.displayId")}}.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush: js">if(navigator.getVRDisplays) {
console.log('WebVR 1.1 supported');
// Then get the displays attached to the computer
navigator.getVRDisplays().then(function(displays) {
// If a display is available, use it to present the scene
if(displays.length > 0) {
vrDisplay = displays[0];
// Now we have our VRDisplay object and can do what we want with it
}
});
}</pre>
<div class="note">
<p><strong>Note</strong>: You can see this complete code at <a href="https://github.com/mdn/webvr-tests/blob/master/raw-webgl-example/webgl-demo.js">raw-webgl-example</a>.</p>
</div>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('WebVR 1.1', '#interface-vrdisplay', 'VRDisplay')}}</td>
<td>{{Spec2('WebVR 1.1')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.VRDisplay")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/API/WebVR_API">WebVR API homepage</a></li>
<li><a href="http://mozvr.com/">MozVr.com</a> — demos, downloads, and other resources from the Mozilla VR team.</li>
</ul>
|