渲染设置概要
Oculus公司 SDK使用分层组件服务传送帧和处理失真。
针对 Rift,要将场景渲染成一个或两个的渲染纹理,并将这些纹理传递给API。Oculus运行库处理失真渲染,GPU同步,帧定时,和HMD框架展示。
以下是SDK的渲染步骤
- 初始化
a) 初始化Oculus公司SDK,如前所述,为头戴式视图器创建一个ovrSession 对象。
b) 根据ovrHmdDesc数据计算所需要的FOV和纹理大小。
c) 分配ovrSwapTextureSet 对象,该对象用于表示眼睛的缓冲区,使用特定的API的方法:在Direct3D中调用ovr_CreateSwapTextureSetD3D11 或则在OpenGL中调用ovr_CreateSwapTextureSetGL。 - 设置帧处理
a) 使用ovr_gettrackingstate和ovr_calceyeposes计算基于帧定时信息视图渲染需要的眼睛位置。
b) 用特定的引擎方式为每只眼睛执行渲染,使用纹理集渲染当前的纹理。当前的纹理是由ovrSwapTextureSet::CurrentIndex 变量标识。
c) 调用 ovr_SubmitFrame,使用ovrLayerEyeFov构造函数传递上一步提供的纹理集合。虽然需要一个单独的图层来提交一个帧,但你可以使用多个图层和图层类型进行高级渲染。ovr_SubmitFrame 把图层纹理呈现在头戴式视图器前,会先传递给分层组件服务,处理失真、时延和GPU同步。
d) 在每个使用纹理集内,CurrentIndex为下一个帧提前设置下一个连续纹理缓冲。 - 关闭
a) 调用 ovr_DestroySwapTextureSet 销毁互换的纹理缓冲区,调用ovr_DestroyMirrorTexture 销毁镜像纹理,调用ovr_Destroy销毁ovrSession 对象。
原文如下
Rendering Setup Outline
The Oculus SDK makes use of a compositor process to present frames and handle distortion.
To target the Rift, you render the scene into one or two render textures, passing these textures into the API. The Oculus runtime handles distortion rendering, GPU synchronization, frame timing, and frame presentation to the HMD.
The following are the steps for SDK rendering:
- Initialize:
a. Initialize Oculus SDK and create an ovrSession object for the headset as was described earlier.
b. Compute the desired FOV and texture sizes based on ovrHmdDesc data.
c. Allocate ovrSwapTextureSet objects, used to represent eye buffers, in an API-specific way: call ovr_CreateSwapTextureSetD3D11 for Direct3D or ovr_CreateSwapTextureSetGL for OpenGL. - Set up frame handling:
a. Use ovr_GetTrackingState and ovr_CalcEyePoses to compute eye poses needed for view rendering based on frame timing information.
b. Perform rendering for each eye in an engine-specific way, rendering into the current texture within the texture set. Current texture is identified by the ovrSwapTextureSet::CurrentIndex variable.
c. Call ovr_SubmitFrame, passing swap texture set(s) from the previous step within a ovrLayerEyeFov structure. Although a single layer is required to submit a frame, you can use multiple layers and layer types for advanced rendering. ovr_SubmitFrame passes layer textures to the compositor which handles distortion, timewarp, and GPU synchronization before presenting it to the headset.
d. Advance CurrentIndex within each used texture set to target the next consecutive texture buffer for the following frame. - Shutdown:
a. Call ovr_DestroySwapTextureSet to destroy swap texture buffers. Call ovr_DestroyMirrorTexture to destroy a mirror texture. To destroy the ovrSession object, call ovr_Destroy.