Exemplo n.º 1
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize()
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }
            else
            {
                staticCollector = new DisposeCollector();
            }

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

            D3D = new Direct3D9.Direct3D();

            var adapters = new List <GraphicsAdapter>();

            for (int i = 0; i < D3D.AdapterCount; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapters.Add(adapter);
            }

            Default  = adapters[0];
            Adapters = adapters.ToArray();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
//			PrintAdapterInfo();

            RenderForm fm = new RenderForm();

            AutoCollector.Collect(fm);
            RenderformInput formInput = new RenderformInput(fm);                //TODO: refact to factory creation

            AutoCollector.Collect(formInput);
            LogicBasic    logicModule = new LogicBasic(formInput);
            RenderContext mainRC      = new RenderContext(fm, logicModule);

            AutoCollector.Collect(mainRC);

            RenderLoop.Run(fm, mainRC.RenderProc);

            AutoCollector.DisposeAndClear();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a disposable object to the list of the objects to dispose.
 /// </summary>
 /// <param name="toDisposeArg">To dispose.</param>
 protected internal T ToDispose <T>(T toDisposeArg)
 {
     if (!ReferenceEquals(toDisposeArg, null))
     {
         if (DisposeCollector == null)
         {
             DisposeCollector = new DisposeCollector();
         }
         return(DisposeCollector.Collect(toDisposeArg));
     }
     return(default(T));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            Factory = factory1;
            staticCollector.Collect(Factory);

            int countAdapters = Factory.GetAdapterCount1();
            var adapters = new List<GraphicsAdapter>();
            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapters.Add(adapter);
            }

            Default = adapters[0];
            Adapters = adapters.ToArray();
        }
Exemplo n.º 5
0
        private void InitDevice(Control window)
        {
            SwapChainDescription swcDesc = new SwapChainDescription
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription(window.ClientSize.Width, window.ClientSize.Height, new Rational(60, 1),
                                                      Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = window.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, swcDesc, out device, out swapChain);
            AutoCollector.Collect(device);
            AutoCollector.Collect(swapChain);
            dc = device.ImmediateContext;
            AutoCollector.Collect(dc);
            var factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);
            factory.Dispose();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            defaultFactory  = factory1;
            staticCollector.Collect(defaultFactory);

            int countAdapters = defaultFactory.GetAdapterCount1();
            var adapterList   = new List <GraphicsAdapter>();

            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapterList.Add(adapter);
            }

            defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null;
            adapters       = adapterList.ToArray();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            Factory         = factory1;
            staticCollector.Collect(Factory);

            int countAdapters = Factory.GetAdapterCount1();
            var adapters      = new List <GraphicsAdapter>();

            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapters.Add(adapter);
            }

            Default  = adapters[0];
            Adapters = adapters.ToArray();
        }
        // Adds an IDisposable object to the collection of disposable objects.
        protected internal T ToDispose <T>(T objectToDispose)
        {
            // If objectToDispose is not null, add it to the collection.
            if (!ReferenceEquals(objectToDispose, null))
            {
                // Create DisposeCollector if it doesn't already exist.
                if (DisposeCollector == null)
                {
                    DisposeCollector = new SharpDX.DisposeCollector();
                    IsDisposed       = false;
                }

                return(DisposeCollector.Collect(objectToDispose));
            }

            // Otherwise, return a default instance of type T.
            return(default(T));
        }
Exemplo n.º 9
0
        private Font GetFontForTextElement(TextElement element)
        {
            var fontKey = $"{element.Font.Name}{element.Font.Size}{element.Font.Style}";

            if (!_fontCache.TryGetValue(fontKey, out Font result))
            {
                result = DisposeCollector.Collect(new Font(Device, new FontDescription
                {
                    FaceName = element.Font.Name,
                    Italic   = (element.Font.Style & FontStyle.Italic) == FontStyle.Italic,
                    Quality  = (element.AntiAliased ? FontQuality.Antialiased : FontQuality.Default),
                    Weight   = ((element.Font.Style & FontStyle.Bold) == FontStyle.Bold)
                        ? FontWeight.Bold
                        : FontWeight.Normal,
                    Height = (int)element.Font.SizeInPoints
                }));
                _fontCache[fontKey] = result;
            }
            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Adds the <paramref name="control" /> to this ui manger.
        /// </summary>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="control"> The control to add. </param>
        /// <returns>The <paramref name="control"/></returns>
        public T Add <T>(T control) where T : Control
        {
            if (control.GetUiManager() != null || control._parent != null)
            {
                throw new InvalidOperationException(
                          $"The control can't be added to the {nameof(UiManager)} instance! It's already part of an other manager or container!");
            }

            control.SetUiManager(this);
            lock (_controls)
            {
                if (_controlCount >= _controls.Length)
                {
                    Array.Resize(ref _controls, _controls.Length * 2);
                }
                _controls[control._uiListIndex = _controlCount++] = control;
            }

            _isDirty = true;

            return(_collector.Collect(control));
        }
Exemplo n.º 11
0
 /// <summary>
 ///     Adds an <see cref="IDisposable" /> object to the dispose collector.
 /// </summary>
 /// <typeparam name="T"> The <see cref="IDisposable" /> object type. </typeparam>
 /// <param name="obj"> The object to add. </param>
 /// <returns>
 ///     The <paramref name="obj" />.
 /// </returns>
 protected T ToDispose <T>(T obj)
 {
     return(_collector.Collect(obj));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Adds an object to be disposed automatically when UnloadContent is called.
 /// Use this method for any content that is not loaded through the ContentManager.
 /// </summary>
 /// <typeparam name="T">Type of the object to dispose.</typeparam>
 /// <param name="disposable">The disposable object.</param>
 protected T ToDisposeContent <T>(T disposable) where T : IDisposable
 {
     return(contentCollector.Collect <T>(disposable));
 }
Exemplo n.º 13
0
 /// <summary>
 ///     Converts an obj to a dispose.
 /// </summary>
 /// <typeparam name="T"> Generic type parameter. </typeparam>
 /// <param name="obj"> The object. </param>
 /// <returns>
 ///     Obj as a T.
 /// </returns>
 protected T ToDispose <T>(T obj) where T : IDisposable
 {
     return(_collector.Collect(obj));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes all adapters with the specified factory.
        /// </summary>
        /// <param name="factory1">The factory1.</param>
        internal static void Initialize(Factory1 factory1)
        {
            if (staticCollector != null)
            {
                staticCollector.Dispose();
            }

            staticCollector = new DisposeCollector();
            defaultFactory = factory1;
            staticCollector.Collect(defaultFactory);

            int countAdapters = defaultFactory.GetAdapterCount1();
            var adapterList = new List<GraphicsAdapter>();
            for (int i = 0; i < countAdapters; i++)
            {
                var adapter = new GraphicsAdapter(i);
                staticCollector.Collect(adapter);
                adapterList.Add(adapter);
            }

            defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null;
            adapters = adapterList.ToArray();
        }