Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }