Пример #1
0
        private static void ResetD3D()
        {
            if (ActiveClients == 0)
            {
                return;
            }

            var presentParams = GetPresentParameters();

            D3DDevice.ResetEx(ref presentParams);
        }
Пример #2
0
        /// <summary>
        /// Resets the DirectX device. This will release all screens, other UI resources and our back buffer, reset the DX device and realloc
        /// all resources.
        /// </summary>
        public static bool Reset()
        {
            ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: Resetting DX device...");
            _screenManager.ExecuteWithTempReleasedResources(() => ExecuteInMainThread(() =>
            {
                // Note that the thread which created the device must call this (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb174344%28v=vs.85%29.aspx ).
                // Note also that only the thread which handles window messages is allowed to call CreateDevice and Reset
                // (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb147224%28v=vs.85%29.aspx )
                ServiceRegistration.Get <ILogger>().Debug("GraphicsDevice: Reset DirectX");
                UIResourcesHelper.ReleaseUIResources();

                if (ContentManager.Instance.TotalAllocationSize != 0)
                {
                    ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: ContentManager.TotalAllocationSize = {0}, should be 0!", ContentManager.Instance.TotalAllocationSize / (1024 * 1024));
                }

                if (_backBuffer != null)
                {
                    _backBuffer.Dispose();
                }
                _backBuffer = null;

                _setup.BuildPresentParamsFromSettings();
                PresentParameters parameters = _setup.PresentParameters;
                _device.ResetEx(ref parameters);
                _setup.PresentParameters = parameters;

                SetupRenderStrategies();
                SetupRenderPipelines();

                Capabilities deviceCapabilities = _device.Capabilities;
                int ordinal = deviceCapabilities.AdapterOrdinal;
                AdapterInformation adapterInfo = MPDirect3D.Direct3D.Adapters[ordinal];
                DisplayMode currentMode        = adapterInfo.CurrentDisplayMode;
                AdaptTargetFrameRateToDisplayMode(currentMode);
                ServiceRegistration.Get <ILogger>().Debug("GraphicsDevice: DirectX reset {0}x{1} format: {2} {3} Hz", Width, Height,
                                                          currentMode.Format, TargetFrameRate);
                _backBuffer = _device.GetRenderTarget(0);
                _device.MaximumFrameLatency = _setup.PresentParameters.BackBufferCount; // Enables the device to queue as many frames as we have backbuffers defined
                _dxCapabilities             = DxCapabilities.RequestCapabilities(deviceCapabilities, currentMode);

                ScreenRefreshWorkaround();

                UIResourcesHelper.ReallocUIResources();
            }));
            ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: Device successfully reset");
            return(true);
        }
Пример #3
0
        private int ResetExHook(IntPtr deviceptr, ref PresentParameters presentparameters, DisplayModeEx displayModeEx)
        {
            try
            {
                DeviceEx device = (DeviceEx)deviceptr;
                if (hooksStarted)
                {
                    ClearD3D9Data();
                }

                device.ResetEx(ref presentparameters, displayModeEx);

                if (hooksStarted)
                {
                    if (currentDevice == null && !targetAcquired)
                    {
                        currentDevice  = device;
                        targetAcquired = true;
                        hasD3D9Ex      = true;
                    }

                    if (currentDevice == device)
                    {
                        SetupD3D9(device);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugMessage(ex.ToString());
            }
            finally
            {
            }
            return(Result.Ok.Code);
        }