コード例 #1
0
ファイル: GoogleVrHmd.cs プロジェクト: Beefr/xenko-wd
        public override void Initialize(Entity cameraRoot, CameraComponent leftCamera, CameraComponent rightCamera, bool requireMirror = false)
        {
            var size = RenderFrameSize;

            if (!GoogleVr.Init(size.Width, size.Height))
            {
                throw new Exception("Failed to Init Google VR SDK");
            }

            RenderFrameProvider = new DirectRenderFrameProvider(RenderFrame.FromTexture(
                                                                    Texture.New2D(GraphicsDevice, size.Width, size.Height, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.RenderTarget | TextureFlags.ShaderResource)
                                                                    ));

            var compositor = (SceneGraphicsCompositorLayers)Game.SceneSystem.SceneInstance.RootScene.Settings.GraphicsCompositor;

            compositor.Master.Add(new SceneDelegateRenderer((x, y) =>
            {
                var frame = GoogleVr.GetNextFrame();
                GoogleVr.SubmitRenderTarget(x.GraphicsContext, RenderFrameProvider.RenderFrame.RenderTargets[0], frame, 0);
                if (!GoogleVr.SubmitFrame(GraphicsDevice, frame, ref headMatrix))
                {
                    throw new Exception("Failed to SubmitFrame to Google VR SDK");
                }
            }));

            leftCamera.UseCustomProjectionMatrix  = true;
            rightCamera.UseCustomProjectionMatrix = true;
            leftCamera.UseCustomViewMatrix        = true;
            rightCamera.UseCustomViewMatrix       = true;
            leftCamera.NearClipPlane  *= ViewScaling;
            rightCamera.NearClipPlane *= ViewScaling;

            if (requireMirror)
            {
                MirrorTexture = RenderFrameProvider.RenderFrame.RenderTargets[0]; //we don't really have a mirror in this case but avoid crashes
            }

            base.Initialize(cameraRoot, leftCamera, rightCamera, requireMirror);
        }