Esempio n. 1
0
        /// <summary>
        /// Creates or re-creates the DirectX device and the backbuffer. This is necessary in the initialization phase
        /// of the SkinEngine and after a parameter was changed which affects the DX device creation.
        /// </summary>
        internal static void DoReCreateDevice_MainThread()
        {
            try
            {
                // Note 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: Initializing DirectX");
                MPDirect3D.Load();

                // Cleanup-part: Only necessary during re-initialization
                UIResourcesHelper.ReleaseUIResources();
                if (_backBuffer != null)
                {
                    _backBuffer.Dispose();
                }
                if (_device != null)
                {
                    _device.Dispose();
                }
                _device = _setup.SetupDirectX();
                // End cleanup part

                SetupRenderStrategies();
                SetupRenderPipelines();

                Capabilities deviceCapabilities = _device.Capabilities;
                _backBuffer = _device.GetRenderTarget(0);
                _device.MaximumFrameLatency = _setup.PresentParameters.BackBufferCount; // Enables the device to queue as many frames as we have backbuffers defined
                int ordinal = deviceCapabilities.AdapterOrdinal;
                AdapterInformation adapterInfo = MPDirect3D.Direct3D.Adapters[ordinal];
                DisplayMode        currentMode = adapterInfo.CurrentDisplayMode;
                AdaptTargetFrameRateToDisplayMode(currentMode);
                LogScreenMode(currentMode);
                bool firstTimeInitialization = _dxCapabilities == null;
                _dxCapabilities = DxCapabilities.RequestCapabilities(deviceCapabilities, currentMode);
                if (firstTimeInitialization)
                {
                    if (!_dxCapabilities.SupportsShaders)
                    {
                        string text = String.Format("MediaPortal 2 needs a graphics card wich supports shader model 2.0\nYour card does NOT support this.\nMediaportal 2 will continue but migh run slow");
                        MessageBox.Show(text, "GraphicAdapter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                SetRenderState();
                UIResourcesHelper.ReallocUIResources();
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Critical("GraphicsDevice: Failed to setup DirectX", ex);
                Environment.Exit(0);
            }
        }
Esempio n. 2
0
        internal static void Dispose()
        {
            if (_backBuffer != null)
            {
                _backBuffer.Dispose();
            }
            _backBuffer = null;

            if (_device != null)
            {
                _device.Dispose();
            }
            _device = null;
            MPDirect3D.Unload();
            _renderAndResourceAccessLock.Dispose();
        }