public void InitializeUsingHolographicSpace() { // The holographic space might need to determine which adapter supports // holograms, in which case it will specify a non-zero PrimaryAdapterId. int shiftPos = sizeof(uint); ulong id = (ulong)holographicSpace.PrimaryAdapterId.LowPart | (((ulong)holographicSpace.PrimaryAdapterId.HighPart) << shiftPos); // When a primary adapter ID is given to the app, the app should find // the corresponding DXGI adapter and use it to create Direct3D devices // and device contexts. Otherwise, there is no restriction on the DXGI // adapter the app can use. if (id != 0) { // Create the DXGI factory. using (var dxgiFactory4 = new SharpDX.DXGI.Factory4()) { // Retrieve the adapter specified by the holographic space. IntPtr adapterPtr; dxgiFactory4.EnumAdapterByLuid((long)id, InteropStatics.IDXGIAdapter3, out adapterPtr); if (adapterPtr != IntPtr.Zero) { dxgiAdapter = new SharpDX.DXGI.Adapter3(adapterPtr); } } } else { this.RemoveAndDispose(ref dxgiAdapter); } CreateDeviceResources(); holographicSpace.SetDirect3D11Device(d3dInteropDevice); }
public WindowsMixedRealityGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { holographicSpace = HolographicSpace.CreateForCoreWindow(CoreWindow.GetForCurrentThread()); CoreWindow.GetForCurrentThread().Activate(); Device3 d3DDevice = device.NativeDevice.QueryInterface <Device3>(); IDirect3DDevice d3DInteropDevice = null; // Acquire the DXGI interface for the Direct3D device. using (var dxgiDevice = d3DDevice.QueryInterface <SharpDX.DXGI.Device3>()) { // Wrap the native device using a WinRT interop object. uint hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out IntPtr pUnknown); if (hr == 0) { d3DInteropDevice = Marshal.GetObjectForIUnknown(pUnknown) as IDirect3DDevice; Marshal.Release(pUnknown); } } holographicSpace.SetDirect3D11Device(d3DInteropDevice); BeginDraw(null); ResizeDepthStencilBuffer(backBuffer.Width, backBuffer.Height, 0); // Set a dummy back buffer as we use a seperate one for each eye. BackBuffer = Texture.New(GraphicsDevice, backBuffer.Description, null); }
public HolographicGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters, HolographicSpace holographicSpace) : base(device, presentationParameters) { if (GraphicsDevice.RenderTargetViewAllocator.DescriptorHeap.Description.DescriptorCount != BufferCount) { GraphicsDevice.RenderTargetViewAllocator.Dispose(); GraphicsDevice.RenderTargetViewAllocator = new DescriptorAllocator(GraphicsDevice, DescriptorHeapType.RenderTargetView, descriptorCount: BufferCount); } using (IDXGIDevice dxgiDevice = GraphicsDevice.NativeDirect3D11Device.QueryInterface <IDXGIDevice>()) { IDirect3DDevice direct3DInteropDevice = Direct3DInterop.CreateDirect3DDevice(dxgiDevice); HolographicSpace = holographicSpace; HolographicSpace.SetDirect3D11Device(direct3DInteropDevice); } HolographicDisplay = HolographicDisplay.GetDefault(); SpatialStationaryFrameOfReference = HolographicDisplay.SpatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation(); HolographicFrame = HolographicSpace.CreateNextFrame(); HolographicSurface = HolographicFrame.GetRenderingParameters(HolographicFrame.CurrentPrediction.CameraPoses[0]).Direct3D11BackBuffer; HolographicBackBuffer = GetHolographicBackBuffer(); renderTarget = CreateRenderTarget(); direct3D11RenderTarget = CreateDirect3D11RenderTarget(); }
private void InitializeHolographicSpace(CoreWindow targetWindow) { // Create the holographic space m_holoSpace = HolographicSpace.CreateForCoreWindow(targetWindow); // The holographic space might need to determine which adapter supports // holograms, in which case it will specify a non-zero PrimaryAdapterId. int shiftPos = sizeof(uint); ulong id = (ulong)m_holoSpace.PrimaryAdapterId.LowPart | (((ulong)m_holoSpace.PrimaryAdapterId.HighPart) << shiftPos); // Get the device with the luid or get the default device of the current system if (id != 0) { m_hostDevice = GraphicsCore.Current.TryGetDeviceByLuid((long)id); } if (m_hostDevice == null) { m_hostDevice = GraphicsCore.Current.DefaultDevice; } // Acquire the DXGI interface for the Direct3D device. D3D11.Device3 d3dDevice = m_hostDevice.Device3D11_3; using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device3>()) { // Wrap the native device using a WinRT interop object. IntPtr pUnknown; UInt32 hr = NativeMethods.CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice.NativePointer, out pUnknown); if (hr == 0) { m_d3dInteropDevice = (MS_D3D11.IDirect3DDevice)Marshal.GetObjectForIUnknown(pUnknown); Marshal.Release(pUnknown); } // Store a pointer to the DXGI adapter. // This is for the case of no preferred DXGI adapter, or fallback to WARP. m_dxgiAdapter = dxgiDevice.Adapter.QueryInterface <SharpDX.DXGI.Adapter3>(); } // Set the Direct3D device on the holographic space m_holoSpace.SetDirect3D11Device(m_d3dInteropDevice); }