Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EngineDevice"/> class.
        /// </summary>
        internal EngineDevice(GraphicsCore core, GraphicsCoreConfiguration coreConfiguration, DXGI.Adapter1 adapter, bool isSoftwareAdapter, bool debugEnabled)
        {
            m_core              = core;
            m_adapter1          = adapter;
            m_adapterDesc1      = m_adapter1.Description1;
            m_isSoftwareAdapter = isSoftwareAdapter;
            m_debugEnabled      = debugEnabled;
            m_configuration     = new GraphicsDeviceConfiguration(coreConfiguration);

            // Set default antialiasing configurations
            m_sampleDescWithAntialiasing = new DXGI.SampleDescription(1, 0);

            // Initialize all direct3D APIs
            try
            {
#if UNIVERSAL
                m_handlerD3D11 = new DeviceHandlerD3D11(adapter, debugEnabled);
                m_handlerDXGI  = new DeviceHandlerDXGI(adapter, m_handlerD3D11.Device1);
#endif
#if DESKTOP
                m_handlerD3D11 = new DeviceHandlerD3D11(adapter, debugEnabled);
                m_handlerDXGI  = new DeviceHandlerDXGI(adapter, m_handlerD3D11.Device1);
                m_handlerD3D9  = new DeviceHandlerD3D9(adapter, isSoftwareAdapter, debugEnabled);
#endif
            }
            catch (Exception ex)
            {
                m_initializationException = ex;

#if UNIVERSAL
                m_handlerD3D11 = null;
                m_handlerDXGI  = null;
#endif
#if DESKTOP
                m_handlerD3D11 = null;
                m_handlerDXGI  = null;
                m_handlerD3D9  = null;
#endif
            }

            // Set default configuration
            m_configuration.TextureQuality  = !isSoftwareAdapter && m_handlerD3D11.IsDirect3D10OrUpperHardware ? TextureQuality.Hight : TextureQuality.Low;
            m_configuration.GeometryQuality = !isSoftwareAdapter && m_handlerD3D11.IsDirect3D10OrUpperHardware ? GeometryQuality.Hight : GeometryQuality.Low;

            // Initialize handlers for feature support information
            if (m_initializationException == null)
            {
                m_isStandardAntialiasingSupported = CheckIsStandardAntialiasingPossible();
            }

            // Initialize direct2D handler finally
            if (m_handlerD3D11 != null)
            {
                m_handlerD2D            = new DeviceHandlerD2D(m_core, this);
                this.FakeRenderTarget2D = m_handlerD2D.RenderTarget;
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsCore"/> class.
        /// </summary>
        protected GraphicsCore(bool debugEnabled, bool force2DFallback)
        {
            try
            {
                // Upate RK.Common members
                m_debugEnabled                      = debugEnabled;
                m_force2DFallback                   = force2DFallback;
                m_devices                           = new List <EngineDevice>();
                m_performanceCalculator             = new PerformanceAnalyzer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(2.0));
                m_performanceCalculator.SyncContext = SynchronizationContext.Current; // <-- TODO
                m_performanceCalculator.RunAsync(CancellationToken.None)
                .FireAndForget();

                m_configuration = new GraphicsCoreConfiguration();
                m_configuration.DebugEnabled = debugEnabled;

                // Create container object for all input handlers
                m_inputHandlerFactory = new InputHandlerFactory();
                m_importExporters     = new ImporterExporterRepository();

                // Create the key generator for resource keys
                m_resourceKeyGenerator = new UniqueGenericKeyGenerator();

                // Try to initialize global api factories (mostly for 2D rendering / operations)
                try
                {
                    if (s_throwDeviceInitError)
                    {
                        throw new SeeingSharpException("Simulated device initialization exception");
                    }

                    m_factoryHandlerWIC     = new FactoryHandlerWIC();
                    m_factoryHandlerD2D     = new FactoryHandlerD2D(this);
                    m_factoryHandlerDWrite  = new FactoryHandlerDWrite(this);
                    m_factoryHandlerXAudio2 = new FactoryHandlerXAudio2();
                }
                catch (Exception ex)
                {
                    m_initException = ex;

                    m_devices.Clear();
                    m_factoryHandlerWIC     = null;
                    m_factoryHandlerD2D     = null;
                    m_factoryHandlerDWrite  = null;
                    m_factoryHandlerXAudio2 = null;
                    return;
                }
                this.FactoryD2D    = m_factoryHandlerD2D.Factory;
                this.FactoryD2D_2  = m_factoryHandlerD2D.Factory2;
                this.FactoryDWrite = m_factoryHandlerDWrite.Factory;
                this.FactoryWIC    = m_factoryHandlerWIC.Factory;
                this.XAudioDevice  = m_factoryHandlerXAudio2.Device;

                // Create the SoundManager
                m_soundManager = new SoundManager(m_factoryHandlerXAudio2);

                // Try to initialize Media Foundation interface
                // (This is a separated init step because MF may not be available on some systems, e. g. Servers)
                try
                {
                    m_factoryHandlerMF = new FactoryHandlerMF();
                }
                catch (Exception)
                {
                    m_factoryHandlerMF = null;
                }

                // Create the object containing all hardware information
                m_hardwareInfo = new EngineHardwareInfo();
                int actIndex = 0;
                foreach (var actAdapterInfo in m_hardwareInfo.Adapters)
                {
                    EngineDevice actEngineDevice = new EngineDevice(
                        this,
                        m_configuration,
                        actAdapterInfo.Adapter,
                        actAdapterInfo.IsSoftwareAdapter,
                        debugEnabled);
                    if (actEngineDevice.IsLoadedSuccessfully)
                    {
                        actEngineDevice.DeviceIndex = actIndex;
                        actIndex++;

                        m_devices.Add(actEngineDevice);
                    }
                }
                m_defaultDevice = m_devices.FirstOrDefault();

                // Start input gathering
                m_inputGatherer = new InputGathererThread();
                m_inputGatherer.Start();

                // Start main loop
                m_mainLoop = new EngineMainLoop(this);
                if (m_devices.Count > 0)
                {
                    m_mainLoopCancelTokenSource = new CancellationTokenSource();
                    m_mainLoopTask = m_mainLoop.Start(m_mainLoopCancelTokenSource.Token);
                }
            }
            catch (Exception ex2)
            {
                m_initException = ex2;

                m_hardwareInfo = null;
                m_devices.Clear();
                m_configuration        = null;
                m_resourceKeyGenerator = null;
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphicsDeviceConfiguration" /> class.
 /// </summary>
 /// <param name="coreConfig">The core configuration object.</param>
 public GraphicsDeviceConfiguration(GraphicsCoreConfiguration coreConfig)
 {
     m_coreConfig = coreConfig;
 }