public HmdSwapTextureSet(IntPtr hmdPtr, Device device, int width, int height) { var cDesc = new _D3D11_TEXTURE2D_DESC() { Width = (uint)width, Height = (uint)height, MipLevels = (uint)1, ArraySize = (uint)1, Format = (uint)DrawSystem.GetRenderTargetFormat(), SampleDesc_Count = (uint)1, SampleDesc_Quality = (uint)0, Usage = (uint)ResourceUsage.Default, BindFlags = (uint)(BindFlags.RenderTarget | BindFlags.ShaderResource), CPUAccessFlags = (uint)CpuAccessFlags.None, MiscFlags = (uint)ResourceOptionFlags.None, }; unsafe { IntPtr textureSetPtr; int result = LibOVR.ovrHmd_CreateSwapTextureSetD3D11(hmdPtr, device.NativePointer, (IntPtr)(&cDesc), out textureSetPtr); if (result != 0) { MessageBox.Show("Failed to ovrHmd_CreateSwapTexturesetD3D11() code=" + result); return; } var textureSet = CRef <LibOVR.ovrSwapTextureSet> .FromPtr(textureSetPtr); if (textureSet == null) { return; } var textureList = new List <CRef <LibOVR.ovrTexture> >(); for (int texIndex = 0; texIndex < textureSet.Value.TextureCount; ++texIndex) { IntPtr texPtr = textureSet.Value.Textures + sizeof(LibOVR.ovrTexture) * texIndex; var tex = CRef <LibOVR.ovrTexture> .FromPtr(texPtr); textureList.Add(tex); } m_hmdPtr = hmdPtr; m_textureSet = textureSet; m_textures = textureList.ToArray(); } var csize = m_textures[0].Value.Header.TextureSize; m_resolution = new Size(csize.w, csize.h); // make SharpDx resource m_textureResList = m_textures.Select(t => new Texture2D(t.Value.Texture)).ToList(); // make and set texture views m_renderTargetViewList = m_textureResList.Select(t => new RenderTargetView(device, t)).ToList(); _SetTextureView(0, m_renderTargetViewList[0]); _SetTextureView(1, m_renderTargetViewList[1]); }
public HmdMirrorTexture(IntPtr hmdPtr, Device device, int width, int height) { var cDesc = new _D3D11_TEXTURE2D_DESC() { Width = (uint)width, Height = (uint)height, MipLevels = (uint)1, ArraySize = (uint)1, Format = (uint)DrawSystem.GetRenderTargetFormat(), SampleDesc_Count = (uint)1, SampleDesc_Quality = (uint)0, Usage = (uint)ResourceUsage.Default, BindFlags = (uint)BindFlags.None, CPUAccessFlags = (uint)CpuAccessFlags.None, MiscFlags = (uint)ResourceOptionFlags.None, }; unsafe { IntPtr mirrorTexturePtr; int result = LibOVR.ovrHmd_CreateMirrorTextureD3D11(hmdPtr, device.NativePointer, (IntPtr)(&cDesc), out mirrorTexturePtr); if (result != 0) { MessageBox.Show("Failed to ovrHmd_CreateMirrorTextureD3D11() code=" + result); return; } IntPtr nativeTexturePtr = ((LibOVR.ovrTexture *)mirrorTexturePtr)->Texture; var texture = new Texture2D(nativeTexturePtr); // succeeded all m_mirrorTexturePtr = mirrorTexturePtr; m_hmdPtr = hmdPtr; m_texture = texture; } }