Esempio n. 1
0
        private void RecreateResources(IVisualContainerElement root, out RenderContext context)
        {
            _dxgiFactory?.Dispose();
            _swapChain?.Dispose();
            _direct3DDevice?.Dispose();
            _directWriteFactory?.Dispose();

            CreateSwapChainAndDevice(out _swapChainDescription, out _swapChain, out _direct3DDevice);
            _dxgiDevice  = _direct3DDevice.QueryInterface <SharpDX.DXGI.Device>();
            _dxgiFactory = _swapChain.GetParent <Factory>();

            // Video (EVR) initialization.
            var multithread = _direct3DDevice.QueryInterface <DeviceMultithread>();

            multithread.SetMultithreadProtected(true);
            if (_dxgiDeviceManager == null)
            {
                try {
                    _dxgiDeviceManager = new DXGIDeviceManager();
                } catch (System.EntryPointNotFoundException) {
                    // Windows 7
                }
            }
            _dxgiDeviceManager?.ResetDevice(_direct3DDevice);

            _directWriteFactory = new SharpDX.DirectWrite.Factory();

            context        = new RenderContext(this, new Size(_swapChainDescription.ModeDescription.Width, _swapChainDescription.ModeDescription.Height));
            _renderContext = context;

            root.OnLayout();

            root.OnGotContext(context);

            _isSizeChanged = false;

            ++_controlResizeCounter;
            if (_controlResizeCounter == StartupControlResizeCount)
            {
                // WTF...
                // Look into MediaEngine and DXGIDeviceManager?
                Game.Window.Invoke(new Action(() => Game.Window.RaiseStageReady(EventArgs.Empty)));

                root.OnStageReady(context);
            }
        }
Esempio n. 2
0
        internal void Draw(IVisualContainerElement root, GameTime gameTime)
        {
            var context = _renderContext;

            using (_sizeLock.NewReadLock()) {
                if (_isSizeChanged)
                {
                    root.OnLostContext(context);

                    context?.Dispose();

                    RecreateResources(root, out context);
                    _renderContext = context;
                }
            }

            context.ClearAll();

            root.Draw(gameTime, context);

            context.Present();
        }