The C APIs in vr.h provide basic interfaces for interacting with WebVR from Emscripten.
Table of Contents
emscripten_vr_init
(em_vr_arg_callback_func callback, void* userData)¶Initialize the emscripten VR API. This will navigator.getVRDisplays()
and when completed, set the return of emscripten_vr_ready()
to be true.
参数: |
|
---|---|
返回: | 1 on success, 0 if the browsers WebVR support is insufficient. |
返回类型: | int |
小技巧
This call succeeding is not sufficient for use of the rest of the API. Please make sure to wait until the callback is executed.
emscripten_vr_ready
()¶Check whether the VR API has finished initializing VR displays.
See also emscripten_vr_init()
.
This function may return 1 event if WebVR is not supported in the running browser.
返回: | 1 if ready, 0 otherwise. |
---|
emscripten_vr_deinit
()¶Deinitialize the emscripten VR API. This will free all memory allocated for display name strings.
返回: | 1 on success. |
---|---|
返回类型: | int |
All of the following functions require emscripten_vr_init()
to have been
called but do not require VR displays and can therefore be called before the return
value of emscripten_vr_ready()
is true.
emscripten_vr_version_minor
()¶Minor version of the WebVR API currently supported by the browser.
返回: | minor version of WebVR, or -1 if not supported or API not initialized. |
---|---|
返回类型: | int |
emscripten_vr_version_major
()¶Major version of the WebVR API currently supported by the browser.
返回: | major version of WebVR, or -1 if not supported or API not initialized. |
---|---|
返回类型: | int |
All of the following functions require emscripten_vr_init()
to have been
called the return value of emscripten_vr_ready()
to be true.
emscripten_vr_count_displays
()¶返回: | Number of displays connected. |
---|---|
返回类型: | int |
emscripten_vr_get_display_handle
(int displayIndex)¶参数: |
|
---|---|
返回: | handle for a VR display. |
返回类型: | VRDisplayHandle |
emscripten_vr_get_display_name
(VRDisplayHandle handle)¶Get a user-readable name which identifies the VR display. The memory for the
returned string is managed by the API and will be freed on
emscripten_vr_deinit()
.
参数: |
|
---|---|
返回: | name of the VR display or 0 (NULL) if the handle is invalid. |
返回类型: | char* |
emscripten_vr_display_connected
(VRDisplayHandle handle)¶参数: |
|
---|---|
返回: | true if the display is connected, false otherwise or when the handle is invalid. |
返回类型: | bool |
emscripten_vr_display_presenting
(VRDisplayHandle handle)¶See also emscripten_vr_request_present()
.
参数: |
|
---|---|
返回: | true if the display is currently presenting, false otherwise or when the handle is invalid. |
返回类型: | bool |
emscripten_vr_get_display_capabilities
(VRDisplayHandle handle, VRDisplayCapabilities* displayCaps)¶参数: |
|
---|---|
返回: | 1 on success, 0 if handle was invalid. |
返回类型: | bool |
emscripten_vr_get_eye_parameters
(VRDisplayHandle handle, VREye whichEye, VREyeParameters* eyeParams)¶参数: |
|
---|---|
返回: | 1 on success, 0 if handle was invalid. |
返回类型: | bool |
In contrast to the usual emscripten main loop (see Browser Execution Environment),
VR displays require their own rendering loop which is independent from the main loop. The rendering
loop can be set per display and will act like a main loop with timing mode EM_TIMING_RAF
until the
display is requested to present, as of which it will run at the VR display’s refresh rate.
emscripten_vr_set_display_render_loop
(VRDisplayHandle handle, em_vr_callback_func callback)¶Set a C function as the per frame rendering callback of a VR display.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
小技巧
There can be only one render loop function per VR display. To change the render loop function, first cancel
the current loop, and then call this function to set another.
emscripten_vr_set_display_render_loop_arg
(VRDisplayHandle handle, em_vr_callback_func callback, void* arg)¶Set a C function as the per frame rendering callback of a VR display.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
emscripten_vr_cancel_display_render_loop
(VRDisplayHandle handle: |display-handle-parameter-doc|)¶Cancels the render loop of a VR display should there be one running for it.
See also emscripten_vr_set_display_render_loop()
and emscripten_vr_set_display_render_loop_arg()
for information about setting and using the render loop.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
emscripten_vr_get_frame_data
(VRDisplayHandle handle, VRFrameData* frameData)¶Get view matrix, projection matrix, timestamp and head pose for current frame. Only valid when called from within a render loop callback.
See also emscripten_vr_set_display_render_loop()
and emscripten_vr_set_display_render_loop_arg()
for information about setting and using the render loop.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
emscripten_vr_submit_frame
(VRDisplayHandle handle)¶Submit the current state of canvases passed via VRLayerInit to
emscripten_vr_request_present()
to be rendered to the VR display.
Only valid when called from within a render loop callback.
See also emscripten_vr_set_display_render_loop()
and emscripten_vr_set_display_render_loop_arg()
for information about setting and using the render loop.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
emscripten_vr_request_present
(VRDisplayHandle handle, VRLayerInit* layerInit, int layerCount, em_vr_arg_callback_func callback, void* userData)¶Request present for the VR display using canvases specified in the layerInit array. If the request is successful callback will be called with userData and the render loop will continue rendering at the refresh rate of the VR display.
Must be called from a user callback (see HTML5 API).
See the specification of VRDisplay.requestPresent for detailed information.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
emscripten_vr_exit_present
(VRDisplayHandle handle)¶Request present exit.
参数: |
|
---|---|
返回类型: | 1 on success, 0 if handle was invalid. |
VR_EYE_LEFT
¶VR_EYE_RIGHT
¶Eye values for use with emscripten_vr_get_eye_parameters()
.
VR_POSE_POSITION
¶VR_POSE_LINEAR_VELOCITY
¶VR_POSE_LINEAR_ACCELERATION
¶VR_POSE_ORIENTATION
¶VR_POSE_ANGULAR_VELOCITY
¶VR_POSE_ANGULAR_ACCELERATION
¶Flags which describe which properties of a VRPose
are valid.
VR_LAYER_DEFAULT_LEFT_BOUNDS
¶VR_LAYER_DEFAULT_RIGHT_BOUNDS
¶Default values to pass to VRLayerInit
.
VRDisplayCapabilities
¶Structure passed to emscripten_vr_get_display_capabilities()
, maps to the WebVR VRDisplayCapabilities interface.
hasPosition
¶hasExternalDisplay
¶canPresent
¶maxLayers
¶VRLayerInit
¶Structure passed to emscripten_vr_request_present()
, maps to the WebVR VRLayerInit interface.
source
¶Id of the source canvas which will be used to present to the VR display.
0 (NULL) is used to refer to Module.canvas
.
leftBounds
¶Texture bounds of the left eye on the target canvas. Initialize with VR_LAYER_DEFAULT_LEFT_BOUNDS
for default.
rightBounds
¶Texture bounds of the right eye on the target canvas. Initialize with VR_LAYER_DEFAULT_RIGHT_BOUNDS
for default.
VRPose
¶Substructure of VRFrameData
, maps to the WebVR
VRPose interface.
VR Displays do not necessarily report all of the pose values (mobile VR devices usually
only report orientation, but not position for example). To check which values are valid,
the poseFlags
member provides a bitmask of
VR_POSE_* which has a bit set for every valid value.
linearAcceleration
¶Linear acceleration, valid only if poseFlags & VR_POSE_LINEAR_ACCELERATION != 0
.
orientation
¶Orientation quaternion, valid only if poseFlags & VR_POSE_ORIENTATION != 0
.
angularVelocity
¶Angular velocity, valid only if poseFlags & VR_POSE_ANGULAR_VELOCITY != 0
.
VRFrameData
¶Structure passed to emscripten_vr_get_frame_data()
, maps to the WebVR
VRFrameData interface.
timestamp
¶leftProjectionMatrix
¶leftViewMatrix
¶rightProjectionMatrix
¶rightViewMatrix
¶VREyeParameters
¶Structure passed to emscripten_vr_get_eye_parameters()
, maps to the WebVR
VREyeParameters interface.
renderWidth
¶renderHeight
¶