| 167 | } |
| 168 | |
| 169 | ovrResult CompositorBase::EndFrame(ovrSession session, long long frameIndex, const ovrViewScaleDesc* viewScaleDesc, ovrLayerHeader const * const * layerPtrList, unsigned int layerCount) |
| 170 | { |
| 171 | MICROPROFILE_SCOPE(EndFrame); |
| 172 | |
| 173 | if (layerCount == 0 || !layerPtrList) |
| 174 | return ovrError_InvalidParameter; |
| 175 | |
| 176 | const ovrLayerHeader* baseLayer = nullptr; |
| 177 | std::vector<vr::VROverlayHandle_t> activeOverlays; |
| 178 | for (uint32_t i = 0; i < layerCount; i++) |
| 179 | { |
| 180 | if (!layerPtrList[i]) |
| 181 | continue; |
| 182 | |
| 183 | // TODO: Support ovrLayerType_Cylinder and ovrLayerType_Cube |
| 184 | if (layerPtrList[i]->Type == ovrLayerType_Quad) |
| 185 | { |
| 186 | const ovrLayerQuad& layer = ToUnion(layerPtrList[i]).Quad; |
| 187 | ovrTextureSwapChain chain = layer.ColorTexture; |
| 188 | |
| 189 | // Every overlay is associated with a swapchain. |
| 190 | // This is necessary because the position of the layer may change in the array, |
| 191 | // which would otherwise cause flickering between overlays. |
| 192 | // TODO: Support multiple overlays using the same texture. |
| 193 | if (chain->Overlay == vr::k_ulOverlayHandleInvalid) |
| 194 | { |
| 195 | chain->Overlay = CreateOverlay(); |
| 196 | |
| 197 | // Submit for the first time |
| 198 | vr::Texture_t texture; |
| 199 | chain->Submit()->ToVRTexture(texture); |
| 200 | vr::VROverlay()->SetOverlayTexture(chain->Overlay, &texture); |
| 201 | } |
| 202 | activeOverlays.push_back(chain->Overlay); |
| 203 | |
| 204 | // Set the layer rendering order and apply a bias between the layers. |
| 205 | vr::VROverlay()->SetOverlaySortOrder(chain->Overlay, i); |
| 206 | OVR::Posef pose = layer.QuadPoseCenter; |
| 207 | pose.Translation += pose.Rotate(OVR::Vector3f(0.0f, 0.0f, (float)i * REV_LAYER_BIAS)); |
| 208 | |
| 209 | // Transform the overlay. |
| 210 | vr::HmdMatrix34_t transform = REV::Matrix4f(pose); |
| 211 | vr::VROverlay()->SetOverlayWidthInMeters(chain->Overlay, layer.QuadSize.x); |
| 212 | if (layerPtrList[i]->Flags & ovrLayerFlag_HeadLocked) |
| 213 | vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative(chain->Overlay, vr::k_unTrackedDeviceIndex_Hmd, &transform); |
| 214 | else |
| 215 | vr::VROverlay()->SetOverlayTransformAbsolute(chain->Overlay, vr::VRCompositor()->GetTrackingSpace(), &transform); |
| 216 | |
| 217 | // Set the texture and show the overlay. |
| 218 | vr::VRTextureBounds_t bounds = ViewportToTextureBounds(layer.Viewport, layer.ColorTexture, layerPtrList[i]->Flags); |
| 219 | vr::VROverlay()->SetOverlayTextureBounds(chain->Overlay, &bounds); |
| 220 | |
| 221 | // Show the overlay, unfortunately we have no control over the order in which |
| 222 | // overlays are drawn. |
| 223 | // TODO: Support ovrLayerFlag_HighQuality for overlays with anisotropic sampling. |
| 224 | // TODO: Handle overlay errors. |
| 225 | vr::VROverlay()->ShowOverlay(chain->Overlay); |
| 226 | } |
no test coverage detected