Example #1
0
        void CreateAllObjects()
        {
            using (PerfTracker.InfrequentEvent("Create objects"))
            {
                _frameCommands      = GraphicsDevice.ResourceFactory.CreateCommandList();
                _frameCommands.Name = "Frame Commands List";

                CommandList initCL = GraphicsDevice.ResourceFactory.CreateCommandList();
                initCL.Name = "Recreation Initialization Command List";
                initCL.Begin();
                _sceneContext.CreateDeviceObjects(GraphicsDevice, initCL);

                foreach (var r in _renderers.Values)
                {
                    r.CreateDeviceObjects(GraphicsDevice, initCL, _sceneContext);
                }

                initCL.End();
                GraphicsDevice.SubmitCommands(initCL);
                GraphicsDevice.WaitForIdle();
                initCL.Dispose();
                GraphicsDevice.WaitForIdle();
                Resolve <IShaderCache>().CleanupOldFiles();
            }
        }
Example #2
0
 public Engine(GraphicsBackend backend, bool useRenderDoc) : base(Handlers)
 {
     _newBackend = backend;
     if (useRenderDoc)
     {
         using (PerfTracker.InfrequentEvent("Loading renderdoc"))
             RenderDoc.Load(out _renderDoc);
     }
 }
Example #3
0
        void DestroyAllObjects()
        {
            using (PerfTracker.InfrequentEvent("Destroying objects"))
            {
                GraphicsDevice.WaitForIdle();
                _frameCommands.Dispose();
                _sceneContext.DestroyDeviceObjects();
                foreach (var r in _renderers.Values)
                {
                    r.DestroyDeviceObjects();
                }

                Resolve <ITextureManager>()?.DestroyDeviceObjects();
                GraphicsDevice.WaitForIdle();
            }
        }
Example #4
0
        void ChangeBackend()
        {
            if (_newBackend == null)
            {
                return;
            }
            var backend = _newBackend.Value;

            _newBackend = null;

            using (PerfTracker.InfrequentEvent($"change backend to {backend}"))
            {
                if (GraphicsDevice != null)
                {
                    DestroyAllObjects();
                    if (GraphicsDevice.BackendType != backend)
                    {
                        Resolve <IShaderCache>().DestroyAllDeviceObjects();
                    }
                    GraphicsDevice.Dispose();
                }

                if (Window == null || _recreateWindow)
                {
                    _recreateWindow = false;
                    Window?.Close();

                    WindowCreateInfo windowInfo = new WindowCreateInfo
                    {
                        X                  = Window?.X ?? 648,
                        Y                  = Window?.Y ?? 431,
                        WindowWidth        = Window?.Width ?? DefaultWidth,
                        WindowHeight       = Window?.Height ?? DefaultHeight,
                        WindowInitialState = Window?.WindowState ?? WindowState.Normal,
                        WindowTitle        = "UAlbion"
                    };

                    _windowManager.Window = VeldridStartup.CreateWindow(ref windowInfo);
                    //Window.BorderVisible = false;
                    Window.CursorVisible = false;
                    Window.Resized      += () => _windowResized = true;
                }

                GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(
                    _renderDoc != null, PixelFormat.R32_Float, false,
                    ResourceBindingModel.Improved, true,
                    true, false)
                {
                    SyncToVerticalBlank = _vsync,
                };

                // Currently this field only exists in my local build of veldrid, so set it via reflection.
                var singleThreadedProperty = typeof(GraphicsDeviceOptions).GetField("SingleThreaded");
                if (singleThreadedProperty != null)
                {
                    singleThreadedProperty.SetValueDirect(__makeref(gdOptions), true);
                }

                GraphicsDevice = VeldridStartup.CreateGraphicsDevice(Window, gdOptions, backend);
                GraphicsDevice.WaitForIdle();
                Window.Title = GraphicsDevice.BackendType.ToString();

                Raise(new BackendChangedEvent(GraphicsDevice));
                CreateAllObjects();
            }
        }