Exemple #1
0
        public virtual DX11RenderContext GetRenderContext(DXGIScreen screen)
        {
            this.logger.Log(LogType.Message, "Creating DX11 Render Context");

            T key = this.GetDeviceKey(screen);

            if (!contexts.ContainsKey(key))
            {
                DX11RenderContext ctx;
                #if DEBUG
                try
                {
                    ctx = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags);
                }
                catch
                {
                    this.logger.Log(LogType.Warning, "Could not create debug device, if you want debug informations make sure DirectX SDK is installed");
                    this.logger.Log(LogType.Warning, "Creating default DirectX 11 device");
                    this.flags = DeviceCreationFlags.BgraSupport;
                    ctx        = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags);
                }
                #else
                ctx = new DX11RenderContext(this.displaymanager.Factory, screen, this.flags);
                #endif

                ctx.Initialize();

                contexts.Add(key, ctx);
                if (this.RenderContextCreated != null)
                {
                    this.RenderContextCreated(ctx);
                }
            }
            return(contexts[key]);
        }
Exemple #2
0
        public void Refresh()
        {
            foreach (DXGIScreen scr in this.screens)
            {
                scr.Adapter.Dispose();
                scr.Monitor.Dispose();
            }
            screens.Clear();

            for (int i = 0; i < this.Factory.GetAdapterCount1(); i++)
            {
                Adapter1 adapter = this.Factory.GetAdapter1(i);

                for (int j = 0; j < adapter.GetOutputCount(); j++)
                {
                    Output output = adapter.GetOutput(j);

                    DXGIScreen screen = new DXGIScreen();
                    screen.Adapter   = adapter;
                    screen.AdapterId = i;
                    screen.Monitor   = output;
                    screen.MonitorId = j;

                    screens.Add(screen);
                }
            }
        }
Exemple #3
0
 public DX11RenderContext(Factory1 factory, DXGIScreen screen, DeviceCreationFlags flags = DeviceCreationFlags.None)
 {
     this.Factory              = factory;
     this.Screen               = screen;
     this.Device               = new Device(screen.Adapter, flags, GetFeatureLevels());
     this.immediatecontext     = this.Device.ImmediateContext;
     this.CurrentDeviceContext = this.immediatecontext;
 }
Exemple #4
0
        /// <summary>
        /// Destroys a device from an adapter
        /// </summary>
        /// <param name="adapter">Adapter index</param>
        public virtual void DestroyContext(DXGIScreen screen)
        {
            T key = this.GetDeviceKey(screen);

            if (contexts.ContainsKey(key))
            {
                contexts[key].Dispose();
                contexts.Remove(key);
            }
        }
        public void Reallocate()
        {
            if (this.devicemanager.Reallocate)
            {
                //Refresh Display List
                //this.devicemanager.DisplayManager.Refresh();

                //TODO : Also kills device if monitor not here anymore

                //Get a list of all devices for renderwindows
                foreach (IDX11RenderWindow window in this.renderwindows)
                {
                    DXGIScreen screen = this.GetScreen(window);

                    //Assign primary window device
                    window.RenderContext = this.devicemanager.GetRenderContext(screen);
                }

                //Get List of existing devices
                List <DX11RenderContext> unused = new List <DX11RenderContext>();

                foreach (DX11RenderContext device in this.devicemanager.RenderContexts)
                {
                    bool found = false;
                    foreach (IDX11RenderWindow window in this.renderwindows)
                    {
                        if (device == window.RenderContext)
                        {
                            found = true;
                        }                                                     //Device in use
                    }

                    if (!found)
                    {
                        unused.Add(device);
                    }
                }

                //Kill unused devices
                foreach (DX11RenderContext device in unused)
                {
                    //Send event device gonna be disposed
                    this.OnDeviceDisposing(device);

                    this.devicemanager.DestroyContext(device.Screen);
                }
            }
            else
            {
                foreach (IDX11RenderWindow window in this.renderwindows)
                {
                    window.RenderContext = this.devicemanager.RenderContexts[0];
                }
            }
        }
Exemple #6
0
 protected abstract T GetDeviceKey(DXGIScreen screen);
Exemple #7
0
 protected override string GetDeviceKey(DXGIScreen screen)
 {
     return(screen.Monitor.Description.Name);
 }
Exemple #8
0
 public override void DestroyContext(DXGIScreen screen)
 {
     //Do nothing here
 }
Exemple #9
0
 public override DX11RenderContext GetRenderContext(DXGIScreen screen)
 {
     return(this.context);
 }
Exemple #10
0
 protected override int GetDeviceKey(DXGIScreen screen)
 {
     return(screen.AdapterId);
 }