/// <summary> /// Updates resources associated with a holographic camera's swap chain. /// The app does not access the swap chain directly, but it does create /// resource views for the back buffer. /// </summary> public void CreateResourcesForBackBuffer( DeviceResources deviceResources, HolographicCameraRenderingParameters cameraParameters) { var device = deviceResources.D3DDevice; // Get the WinRT object representing the holographic camera's back buffer. IDirect3DSurface surface = cameraParameters.Direct3D11BackBuffer; // Get a DXGI interface for the holographic camera's back buffer. // Holographic cameras do not provide the DXGI swap chain, which is owned // by the system. The Direct3D back buffer resource is provided using WinRT // interop APIs. InteropStatics.IDirect3DDxgiInterfaceAccess surfaceDxgiInterfaceAccess = surface as InteropStatics.IDirect3DDxgiInterfaceAccess; IntPtr pResource = surfaceDxgiInterfaceAccess.GetInterface(InteropStatics.ID3D11Resource); Resource resource = SharpDX.CppObject.FromPointer <Resource>(pResource); Marshal.Release(pResource); // Get a Direct3D interface for the holographic camera's back buffer. Texture2D cameraBackBuffer = resource.QueryInterface <Texture2D>(); // Determine if the back buffer has changed. If so, ensure that the render target view // is for the current back buffer. if ((this.d3dBackBuffer == null) || (this.d3dBackBuffer.NativePointer != cameraBackBuffer.NativePointer)) { // This can change every frame as the system moves to the next buffer in the // swap chain. This mode of operation will occur when certain rendering modes // are activated. this.d3dBackBuffer = cameraBackBuffer; // Get the DXGI format for the back buffer. // This information can be accessed by the app using CameraResources::GetBackBufferDXGIFormat(). Texture2DDescription backBufferDesc = this.BackBufferTexture2D.Description; // backBufferDesc.SampleDescription = new SharpDX.DXGI.SampleDescription(8, 8); this.dxgiFormat = backBufferDesc.Format; // Check for render target size changes. Size currentSize = this.holographicCamera.RenderTargetSize; if (this.d3dRenderTargetSize != currentSize) { // Set render target size. this.d3dRenderTargetSize = this.HolographicCamera.RenderTargetSize; } } // Create the constant buffer, if needed. if (this.viewProjectionConstantBuffer == null) { // Create a constant buffer to store view and projection matrices for the camera. ViewProjectionConstantBuffer viewProjectionConstantBufferData = new ViewProjectionConstantBuffer(); this.viewProjectionConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create( device, BindFlags.ConstantBuffer, ref viewProjectionConstantBufferData)); } }
/// <summary> /// Releases resources associated with a holographic display back buffer. /// </summary> /// <param name="deviceResources">The device resources</param> public void ReleaseResourcesForBackBuffer(DeviceResources deviceResources) { var context = deviceResources.D3DDeviceContext; this.RemoveAndDispose(ref this.d3dBackBuffer); const int D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT = 8; RenderTargetView[] nullViews = new RenderTargetView[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; // Ensure system references to the back buffer are released by clearing the render // target from the graphics pipeline state, and then flushing the Direct3D context. context.OutputMerger.SetRenderTargets(null, nullViews); context.Flush(); }
/// <summary> /// Releases all device resources. /// </summary> /// <param name="deviceResources">The device resources</param> public void ReleaseAllDeviceResources(DeviceResources deviceResources) { this.ReleaseResourcesForBackBuffer(deviceResources); this.RemoveAndDispose(ref this.viewProjectionConstantBuffer); }