/// <summary>
        /// Present the contents of the swap chain to the screen.
        /// Locks the set of holographic camera resources until the function exits.
        /// </summary>
        public void Present(HolographicFrame frame)
        {
            var presentResult = frame.PresentUsingCurrentPrediction(
                HolographicFramePresentWaitBehavior.DoNotWaitForFrameToFinish
                );

            // The PresentUsingCurrentPrediction API will detect when the graphics device
            // changes or becomes invalid. When this happens, it is considered a Direct3D
            // device lost scenario.
            if (presentResult == HolographicFramePresentResult.DeviceRemoved)
            {
                // The Direct3D device, context, and resources should be recreated.
                HandleDeviceLost();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Present the contents of the swap chain to the screen.
        /// Locks the set of holographic camera resources until the function exits.
        /// </summary>
        public void Present(ref HolographicFrame frame)
        {
            // By default, this API waits for the frame to finish before it returns.
            // Holographic apps should wait for the previous frame to finish before
            // starting work on a new frame. This allows for better results from
            // holographic frame predictions.
            var presentResult = frame.PresentUsingCurrentPrediction(
                HolographicFramePresentWaitBehavior.WaitForFrameToFinish
                );

            // The PresentUsingCurrentPrediction API will detect when the graphics device
            // changes or becomes invalid. When this happens, it is considered a Direct3D
            // device lost scenario.
            if (presentResult == HolographicFramePresentResult.DeviceRemoved)
            {
                // The Direct3D device, context, and resources should be recreated.
                HandleDeviceLost();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Present the contents of the swap chain to the screen.
        /// Locks the set of holographic camera resources until the function exits.
        /// </summary>
        public void Present(ref HolographicFrame frame)
        {
            // By default, this API waits for the frame to finish before it returns.
            // Holographic apps should wait for the previous frame to finish before
            // starting work on a new frame. This allows for better results from
            // holographic frame predictions.
            var presentResult = frame.PresentUsingCurrentPrediction(
                HolographicFramePresentWaitBehavior.WaitForFrameToFinish
                );

            HolographicFramePrediction prediction = frame.CurrentPrediction;

            UseHolographicCameraResources((Dictionary <uint, CameraResources> cameraResourcesDictionary) =>
            {
                foreach (var cameraPose in prediction.CameraPoses)
                {
                    // This represents the device-based resources for a HolographicCamera.
                    CameraResources cameraResources = cameraResourcesDictionary[cameraPose.HolographicCamera.Id];

                    // Discard the contents of the render target.
                    // This is a valid operation only when the existing contents will be
                    // entirely overwritten. If dirty or scroll rects are used, this call
                    // should be removed.
                    d3dContext.DiscardView(cameraResources.BackBufferRenderTargetView);

                    // Discard the contents of the depth stencil.
                    d3dContext.DiscardView(cameraResources.DepthStencilView);
                }
            });

            // The PresentUsingCurrentPrediction API will detect when the graphics device
            // changes or becomes invalid. When this happens, it is considered a Direct3D
            // device lost scenario.
            if (presentResult == HolographicFramePresentResult.DeviceRemoved)
            {
                // The Direct3D device, context, and resources should be recreated.
                HandleDeviceLost();
            }
        }
 public override void Present()
 {
     GraphicsDevice.NativeDirect3D11Device.ImmediateContext.CopyResource(direct3D11RenderTarget, HolographicBackBuffer);
     HolographicFrame.PresentUsingCurrentPrediction();
 }
Ejemplo n.º 5
0
        public unsafe void Run()
        {
            ReferenceFrame = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation();
            CoreWindow.GetForCurrentThread().CustomProperties.Add("HolographicSpace", HolographicSpace);
            InitializeSpace();
            InteractionManager = SpatialInteractionManager.GetForCurrentView();
            InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction);

            while (!windowClosed)
            {
                if (!appInited)
                {
                    SpatialMappingManager = new SpatialMappingManager();
                    VoiceManager          = new VoiceManager();
                    appInited             = true;
                    Game = (HoloApplication)Activator.CreateInstance(holoAppType, assetsDirectory);
                    Game.Run();
                    Game.Engine.PostUpdate += e => currentFrame?.UpdateCurrentPrediction();
                    GesturesManager         = new GesturesManager(Game, ReferenceFrame);
                }

                if (windowVisible && (null != HolographicSpace))
                {
                    if (Game != null)
                    {
                        currentFrame = HolographicSpace.CreateNextFrame();

                        var prediction = currentFrame.CurrentPrediction;
                        if (prediction.CameraPoses.Count < 1)
                        {
                            continue;
                        }
                        var cameraPose = prediction.CameraPoses[0];

                        var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem);
                        if (viewBox != null)
                        {
                            Matrix4x4 leftViewMatrixDx  = viewBox.Value.Left;
                            Matrix4x4 rightViewMatrixDx = viewBox.Value.Right;
                            Matrix4x4 leftProjMatrixDx  = cameraPose.ProjectionTransform.Left;
                            Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right;

                            Matrix4 leftViewMatrixUrho  = *(Matrix4 *)(void *)&leftViewMatrixDx;
                            Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx;
                            Matrix4 leftProjMatrixUrho  = *(Matrix4 *)(void *)&leftProjMatrixDx;
                            Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx;
                            Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho);
                        }

                        var parameters = currentFrame.GetRenderingParameters(cameraPose);
                        if (Game.FocusWorldPoint != Vector3.Zero)
                        {
                            parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem,
                                                     new System.Numerics.Vector3(
                                                         Game.FocusWorldPoint.X,
                                                         Game.FocusWorldPoint.Y,
                                                         -Game.FocusWorldPoint.Z));                //LH->RH
                        }
                        Game.Engine.RunFrame();
                        currentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish);
                    }
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
                }
                else
                {
                    CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending);
                }
            }
        }
 public override void Present()
 {
     HolographicFrame.PresentUsingCurrentPrediction();
 }