private static (ovrTextureSwapChain, Texture[]) CreateSwapchainD3D11( ovrSession session, GraphicsDevice gd, ovrTextureSwapChainDesc desc) { ovrTextureSwapChain otsc; Texture[] textures; ovrResult result = ovr_CreateTextureSwapChainDX(session, gd.GetD3D11Info().Device, &desc, &otsc); if (result != ovrResult.Success) { throw new VeldridException($"Failed to call ovr_CreateTextureSwapChainDX: {result}"); } int textureCount = 0; ovr_GetTextureSwapChainLength(session, otsc, &textureCount); textures = new Texture[textureCount]; for (int i = 0; i < textureCount; ++i) { IntPtr nativeTexture; ovr_GetTextureSwapChainBufferDX(session, otsc, i, s_d3d11Tex2DGuid, &nativeTexture); textures[i] = gd.ResourceFactory.CreateTexture( (ulong)nativeTexture, OculusUtil.GetVeldridTextureDescription(desc)); } return(otsc, textures); }
public static TextureDescription GetVeldridTextureDescription(ovrTextureSwapChainDesc desc) { return(TextureDescription.Texture2D( (uint)desc.Width, (uint)desc.Height, (uint)desc.MipLevels, (uint)desc.ArraySize, GetVeldridPixelFormat(desc.Format), GetVeldridTextureUsage(desc.BindFlags), GetSampleCount(desc.SampleCount))); }
public OculusSwapchain(GraphicsDevice gd, ovrSession session, int sizeW, int sizeH, int sampleCount, bool createDepth) { _session = session; Texture[] colorTextures; Texture[] depthTextures = null; ovrTextureSwapChainDesc colorDesc = new ovrTextureSwapChainDesc(); colorDesc.Type = ovrTextureType.Texture2D; colorDesc.ArraySize = 1; colorDesc.Width = sizeW; colorDesc.Height = sizeH; colorDesc.MipLevels = 1; colorDesc.SampleCount = sampleCount; colorDesc.Format = ovrTextureFormat.R8G8B8A8_UNORM_SRGB; colorDesc.MiscFlags = ovrTextureMiscFlags.DX_Typeless | ovrTextureMiscFlags.AllowGenerateMips; colorDesc.BindFlags = ovrTextureBindFlags.DX_RenderTarget; colorDesc.StaticImage = false; (ColorChain, colorTextures) = CreateSwapchain(session, gd, colorDesc); // if requested, then create depth swap chain if (createDepth) { ovrTextureSwapChainDesc depthDesc = new ovrTextureSwapChainDesc(); depthDesc.Type = ovrTextureType.Texture2D; depthDesc.ArraySize = 1; depthDesc.Width = sizeW; depthDesc.Height = sizeH; depthDesc.MipLevels = 1; depthDesc.SampleCount = sampleCount; depthDesc.Format = ovrTextureFormat.D32_FLOAT; depthDesc.MiscFlags = ovrTextureMiscFlags.None; depthDesc.BindFlags = ovrTextureBindFlags.DX_DepthStencil; depthDesc.StaticImage = false; (DepthChain, depthTextures) = CreateSwapchain(session, gd, depthDesc); } Framebuffers = new Framebuffer[colorTextures.Length]; for (int i = 0; i < Framebuffers.Length; i++) { Framebuffers[i] = gd.ResourceFactory.CreateFramebuffer(new FramebufferDescription( depthTextures?[i], colorTextures[i])); } CommandList = gd.ResourceFactory.CreateCommandList(); }
private static (ovrTextureSwapChain, Texture[]) CreateSwapchainGL( ovrSession session, GraphicsDevice gd, ovrTextureSwapChainDesc desc) { ovrTextureSwapChain otsc = default; Texture[] textures = default; ovrResult result = ovrResult.Success; gd.GetOpenGLInfo().ExecuteOnGLThread(() => { ovrTextureSwapChainDesc localDesc = desc; localDesc.MiscFlags = localDesc.MiscFlags & ~(ovrTextureMiscFlags.DX_Typeless | ovrTextureMiscFlags.AllowGenerateMips); localDesc.BindFlags = ovrTextureBindFlags.None; ovrTextureSwapChain sc; result = ovr_CreateTextureSwapChainGL(session, &localDesc, &sc); if (result != ovrResult.Success) { return; } otsc = sc; }); if (otsc.IsNull) { throw new VeldridException($"Failed to call ovr_CreateTextureSwapChainGL: {result}"); } int textureCount = 0; ovr_GetTextureSwapChainLength(session, otsc, &textureCount); textures = new Texture[textureCount]; for (int i = 0; i < textureCount; ++i) { uint glID; ovr_GetTextureSwapChainBufferGL(session, otsc, i, &glID); textures[i] = gd.ResourceFactory.CreateTexture( glID, OculusUtil.GetVeldridTextureDescription(desc)); } return(otsc, textures); }
private (ovrTextureSwapChain, Texture[]) CreateSwapchain( ovrSession session, GraphicsDevice gd, ovrTextureSwapChainDesc desc) { switch (gd.BackendType) { case GraphicsBackend.Direct3D11: return(CreateSwapchainD3D11(session, gd, desc)); case GraphicsBackend.OpenGL: case GraphicsBackend.OpenGLES: return(CreateSwapchainGL(session, gd, desc)); case GraphicsBackend.Vulkan: return(CreateSwapchainVk(session, gd, desc)); case GraphicsBackend.Metal: throw new PlatformNotSupportedException("Using Oculus with the Metal backend is not supported."); default: throw new NotImplementedException(); } }