Exemplo n.º 1
0
        //public RenderTarget2D SceneRenderTarget = null;

        public Viewport(string id, GraphicsDevice device, Scene.RenderScene scene, MsbEditor.ActionManager am, MsbEditor.Selection sel, int width, int height)
        {
            _vpid      = id;
            PrevWidth  = width;
            PrevHeight = height;
            Width      = width;
            Height     = height;
            _device    = device;
            float depth = device.IsDepthRangeZeroToOne ? 1 : 0;

            _renderViewport = new Veldrid.Viewport(0, 0, Width, Height, depth, 1.0f - depth);

            _renderScene = scene;
            _selection   = sel;

            _worldView    = new WorldView(new Veldrid.Rectangle(0, 0, Width, Height));
            _viewPipeline = new Scene.SceneRenderPipeline(scene, device, width, height);
            ViewportGrid  = new DebugPrimitives.DbgPrimWireGrid(Color.Green, Color.DarkGreen, 50, 5.0f);
            //ViewportGrid.CreateDeviceObjects(device, null, ViewPipeline);

            //RenderScene.AddObject(ViewportGrid);

            _projectionMat = Utils.CreatePerspective(device, false, 60.0f * (float)Math.PI / 180.0f, (float)width / (float)height, 0.1f, 2000.0f);
            _frustum       = new BoundingFrustum(_projectionMat);
            _actionManager = am;

            _viewPipeline.SetViewportSetupAction((d, cl) =>
            {
                cl.SetFramebuffer(device.SwapchainFramebuffer);
                cl.SetViewport(0, _renderViewport);
                if (_vpvisible)
                {
                    _clearQuad.Render(d, cl);
                }
                _vpvisible = false;
            });

            _viewPipeline.SetOverlayViewportSetupAction((d, cl) =>
            {
                cl.SetFramebuffer(device.SwapchainFramebuffer);
                cl.SetViewport(0, _renderViewport);
                cl.ClearDepthStencil(0);
            });

            // Create gizmos
            _gizmos = new MsbEditor.Gizmos(_actionManager, _selection, _renderScene.OverlayRenderables);
            Scene.Renderer.AddBackgroundUploadTask((d, cl) =>
            {
                _gizmos.CreateDeviceObjects(d, cl, _viewPipeline);
            });

            _clearQuad = new Scene.FullScreenQuad();
            Scene.Renderer.AddBackgroundUploadTask((gd, cl) =>
            {
                _clearQuad.CreateDeviceObjects(gd, cl);
            });
        }
Exemplo n.º 2
0
        public void ResizeViewport(GraphicsDevice device, Veldrid.Rectangle newvp)
        {
            PrevWidth  = Width;
            PrevHeight = Height;
            Width      = newvp.Width;
            Height     = newvp.Height;
            X          = newvp.X;
            Y          = newvp.Y;
            _worldView.UpdateBounds(newvp);
            float depth = device.IsDepthRangeZeroToOne ? 0 : 1;

            _renderViewport = new Veldrid.Viewport(newvp.X, newvp.Y, Width, Height, depth, 1.0f - depth);
        }