public StereoDrawContext(DrawSystem.D3DData d3d, DrawResourceRepository repository, HmdDevice hmd, DrawContext context) { m_d3d = d3d; m_repository = repository; m_context = context; m_hmd = hmd; // Create render targets for each HMD eye m_textureSets = new HmdSwapTextureSet[2]; var eyeResolution = hmd.EyeResolution; var resNames = new string[] { "OVRLeftEye", "OVRRightEye" }; for (int index = 0; index < 2; ++index) { var textureSet = m_hmd.CreateSwapTextureSet(d3d.Device, eyeResolution.Width, eyeResolution.Height); m_textureSets[index] = textureSet; var renderTargetList = RenderTarget.FromSwapTextureSet(m_d3d, resNames[index], textureSet); foreach (var renderTarget in renderTargetList) { m_repository.AddResource(renderTarget); } } // Create temporaly render target var tmpRt = RenderTarget.CreateRenderTarget(d3d, "Temp", eyeResolution.Width, eyeResolution.Height); m_repository.AddResource(tmpRt); // Create texture for Mirroring Size defaultRenderTargetSize = m_repository.GetDefaultRenderTarget().Resolution; m_mirrorTexture = m_hmd.CreateMirrorTexture(m_d3d.Device, defaultRenderTargetSize.Width, defaultRenderTargetSize.Height); m_commandListTable = new List <CommandList>(); }
public void EndScene(HmdSwapTextureSet leftEyeSwapTextureSet, HmdSwapTextureSet rightEyeSwapTextureSet) { LibOVR.ovrLayerEyeFov layer = new LibOVR.ovrLayerEyeFov(); layer.Header.Type = LibOVR.ovrLayerType.EyeFov; layer.Header.Flags = (uint)LibOVR.ovrLayerFlags.HighQuality; layer.ColorTexture_Left = leftEyeSwapTextureSet.Ptr; layer.ColorTexture_Right = rightEyeSwapTextureSet.Ptr; layer.Viewport_Left = ToOvrRecti(leftEyeSwapTextureSet.Resolution); layer.Viewport_Right = ToOvrRecti(rightEyeSwapTextureSet.Resolution); layer.Fov_Left = m_handle.Value.DefaultEyeFov[0]; layer.Fov_Right = m_handle.Value.DefaultEyeFov[1]; layer.RnderPose_Left = m_tmpEyePoses[0]; layer.RnderPose_Right = m_tmpEyePoses[1]; unsafe { void *layerList = &layer; int result = LibOVR.ovrHmd_SubmitFrame(m_handle.Ptr, 0, IntPtr.Zero, (IntPtr)(&layerList), 1); if (result != 0) { // is invisible next frame @todo } } }
public static RenderTarget[] FromSwapTextureSet(DrawSystem.D3DData d3d, String name, HmdSwapTextureSet swapTextureSet) { int width = swapTextureSet.Resolution.Width; int height = swapTextureSet.Resolution.Height; var depthBuffer = _CreateDepthBuffer(d3d, width, height); var depthStencilView = _CreateDepthStencilView(d3d, depthBuffer); var resultList = new List <RenderTarget>(); int texCount = swapTextureSet.Textures.Count(); for (int texIndex = 0; texIndex < texCount; ++texIndex) { var texture = swapTextureSet.Textures[texIndex]; var res = new RenderTarget(name + texIndex); res.ShaderResourceView = new ShaderResourceView(d3d.Device, texture); res.TargetTexture = texture; res.TargetView = swapTextureSet.RenderTargetView[texIndex]; res.DepthStencilView = depthStencilView; res._AddDisposable(res.ShaderResourceView); if (texIndex == 0) { // depth buffer and view are shared by each render targets res._AddDisposable(depthBuffer); res._AddDisposable(res.DepthStencilView); } resultList.Add(res); } return(resultList.ToArray()); }