/// <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(); }
/// <summary> /// Removes a disposable object to the list of the objects to dispose. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="toDisposeArg">To dispose.</param> protected internal void RemoveToDispose <T>(T toDisposeArg) { if (!ReferenceEquals(toDisposeArg, null) && DisposeCollector != null) { DisposeCollector.Remove(toDisposeArg); } }
/// <summary> /// Initializes a new instance of the <see cref="Game" /> class. /// </summary> /// <param name="title"> (Optional) title. </param> /// <param name="gcLatencyMode"> (Optional) GCLatencyMode. </param> protected Game(string title = "Exomia.Framework", GCLatencyMode gcLatencyMode = GCLatencyMode.SustainedLowLatency) { GCSettings.LatencyMode = gcLatencyMode; _gameComponents = new Dictionary <string, IComponent>(INITIAL_QUEUE_SIZE); _pendingInitializables = new List <IInitializable>(INITIAL_QUEUE_SIZE); _updateableComponent = new List <IUpdateable>(INITIAL_QUEUE_SIZE); _drawableComponent = new List <IDrawable>(INITIAL_QUEUE_SIZE); _contentableComponent = new List <IContentable>(INITIAL_QUEUE_SIZE); _currentlyUpdateableComponent = new List <IUpdateable>(INITIAL_QUEUE_SIZE); _currentlyDrawableComponent = new List <IDrawable>(INITIAL_QUEUE_SIZE); _currentlyContentableComponent = new List <IContentable>(INITIAL_QUEUE_SIZE); _collector = new DisposeCollector(); _serviceRegistry = new ServiceRegistry(); _serviceRegistry.AddService <IGraphicsDevice>(_graphicsDevice = new GraphicsDevice()); _serviceRegistry.AddService(_contentManager = new ContentManager(_serviceRegistry)); _platform = GamePlatform.Create(this, title); _serviceRegistry.AddService(_platform.MainWindow); // NOTE: The input device should be registered during the platform creation! _inputDevice = _serviceRegistry.GetService <IInputDevice>(); }
/// <summary> /// Dispose a disposable object and set the reference to null. Removes this object from the ToDispose list. /// </summary> /// <param name="objectToDispose">Object to dispose.</param> protected internal void RemoveAndDispose <T>(ref T objectToDispose) { if (!ReferenceEquals(objectToDispose, null) && DisposeCollector != null) { DisposeCollector.RemoveAndDispose(ref objectToDispose); } }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="UiManager" /> class. /// </summary> /// <param name="name"> The name. </param> public UiManager(string name) { Name = name ?? throw new ArgumentNullException(nameof(name)); _collector = new DisposeCollector(); _controls = new Control[INITIAL_LIST_SIZE]; _currentlyControls = new Control[INITIAL_LIST_SIZE]; }
// Removes an IDisposable object from the collection of disposable objects. Does not // dispose of the object before removing it. protected internal void RemoveToDispose <T>(T objectToRemove) { // If objectToRemove is not null, have the DisposeCollector forget about it. if (!ReferenceEquals(objectToRemove, null) && (DisposeCollector != null)) { DisposeCollector.Remove(objectToRemove); } }
// Disposes of an IDisposable object immediately and also removes the object from the // collection of disposable objects. protected internal void RemoveAndDispose <T>(ref T objectToDispose) { // If objectToDispose is not null, and if the DisposeCollector is available, have // the DisposeCollector get rid of objectToDispose. if (!ReferenceEquals(objectToDispose, null) && (DisposeCollector != null)) { DisposeCollector.RemoveAndDispose(ref objectToDispose); } }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var sc = c.SceneContext; DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); var shaderCache = Resolve <IShaderCache>(); _shaders = shaderCache.GetShaderPair(gd.ResourceFactory, VertexShaderName, FragmentShaderName, shaderCache.GetGlsl(VertexShaderName), shaderCache.GetGlsl(FragmentShaderName)); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend, BlendAttachmentDescription.OverrideBlend), gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, RasterizerStateDescription.Default, PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, _shaders, ShaderHelper.GetSpecializations(gd)), new[] { resourceLayout }, sc.DuplicatorFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _pipeline.Name = "P_ScreenDuplicator"; float[] verts = CoreUtil.GetFullScreenQuadVerts(gd.IsClipSpaceYInverted); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription((uint)QuadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, QuadIndices); }
/// <summary> /// Initializes a new instance of the <see cref="Game" /> class. /// </summary> public Game() { // Internals drawableGameSystems = new List <IDrawable>(); currentlyContentGameSystems = new List <IContentable>(); currentlyDrawingGameSystems = new List <IDrawable>(); pendingGameSystems = new List <IGameSystem>(); updateableGameSystems = new List <IUpdateable>(); currentlyUpdatingGameSystems = new List <IUpdateable>(); contentableGameSystems = new List <IContentable>(); contentCollector = new DisposeCollector(); gameTime = new GameTime(); totalGameTime = new TimeSpan(); timer = new TimerTick(); IsFixedTimeStep = false; maximumElapsedTime = TimeSpan.FromMilliseconds(500.0); TargetElapsedTime = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz lastUpdateCount = new int[4]; nextLastUpdateCountIndex = 0; // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 ) // Example for a moving average of 4: // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates) var maxLastCount = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length); updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length; // Externals Services = new GameServiceRegistry(); Content = new ContentManager(Services); LaunchParameters = new LaunchParameters(); GameSystems = new GameSystemCollection(); // Create Platform gamePlatform = GamePlatform.Create(this); gamePlatform.Activated += gamePlatform_Activated; gamePlatform.Deactivated += gamePlatform_Deactivated; gamePlatform.Exiting += gamePlatform_Exiting; gamePlatform.WindowCreated += GamePlatformOnWindowCreated; // By default, add a FileResolver for the ContentManager Content.Resolvers.Add(new FileSystemContentResolver(gamePlatform.DefaultAppDirectory)); // Setup registry Services.AddService(typeof(IServiceRegistry), Services); Services.AddService(typeof(IContentManager), Content); Services.AddService(typeof(IGamePlatform), gamePlatform); // Register events on GameSystems. GameSystems.ItemAdded += GameSystems_ItemAdded; GameSystems.ItemRemoved += GameSystems_ItemRemoved; IsActive = true; }
// Disposes all IDisposable object resources in the collection of disposable // objects. // // NOTE: Since this class exists to dispose of unmanaged resources, the // disposeManagedResources parameter is ignored. protected virtual void Dispose(bool disposeManagedResources) { // If the DisposeCollector exists, have it dispose of all COM objects. if (!IsDisposed && DisposeCollector != null) { DisposeCollector.Dispose(); } // The DisposeCollector is done, and can be discarded. DisposeCollector = null; }
/// <summary> /// Disposes of object resources. /// </summary> /// <param name="disposeManagedResources">If true, managed resources should be /// disposed of in addition to unmanaged resources.</param> protected virtual void Dispose(bool disposeManagedResources) { if (disposeManagedResources) { // Dispose all ComObjects if (DisposeCollector != null) { DisposeCollector.Dispose(); } DisposeCollector = null; } }
/// <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)); }
/// <summary> /// Initializes a new instance of the <see cref="SceneBase" /> class. /// </summary> /// <param name="key"> The key. </param> protected SceneBase(string key) { _key = key ?? throw new ArgumentNullException(nameof(key)); _sceneComponents = new Dictionary <string, IComponent>(INITIAL_QUEUE_SIZE); _pendingInitializables = new List <IInitializable>(INITIAL_QUEUE_SIZE); _updateableComponent = new List <IUpdateable>(INITIAL_QUEUE_SIZE); _drawableComponent = new List <IDrawable>(INITIAL_QUEUE_SIZE); _contentableComponent = new List <IContentable>(INITIAL_QUEUE_SIZE); _currentlyUpdateableComponent = new List <IUpdateable>(INITIAL_QUEUE_SIZE); _currentlyDrawableComponent = new List <IDrawable>(INITIAL_QUEUE_SIZE); _currentlyContentableComponent = new List <IContentable>(INITIAL_QUEUE_SIZE); _collector = new DisposeCollector(); }
protected internal T ToDispose <T>(T disposable) { if (!ReferenceEquals(disposable, null)) { if (DisposeCollector == null) { DisposeCollector = new DisposeCollector(); } return(DisposeCollector.Collect(disposable)); } return(default(T)); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc, ResourceScope scope) { if ((scope & ResourceScope.Global) == 0) { return; } DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); var shaderName = gd.IsUvOriginTopLeft ? "FinalPass_inverted" : "FinalPass"; (var vs, var fs) = sc.GlobalResourceCache.GetShaders(gd, gd.ResourceFactory, shaderName); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend), gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, RasterizerStateDescription.Default, PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { vs, fs, }), new ResourceLayout[] { resourceLayout }, gd.SwapchainFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); float[] verts = Util.GetFullScreenQuadVerts(gd); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription((uint)s_quadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_quadIndices); }
public void CreateDeviceObjects(IRendererContext context) { var c = (VeldridRendererContext)context; var cl = c.CommandList; var gd = c.GraphicsDevice; var factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; var layout = factory.CreateResourceLayout(new ResourceLayoutDescription( ResourceLayoutHelper.Texture("SourceTexture"), ResourceLayoutHelper.Sampler("SourceSampler"))); var shaderCache = Resolve <IShaderCache>(); _shaders = shaderCache.GetShaderPair(gd.ResourceFactory, VertexShaderName, FragmentShaderName, shaderCache.GetGlsl(VertexShaderName), shaderCache.GetGlsl(FragmentShaderName)); var rasterizerState = new RasterizerStateDescription( FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.Clockwise, true, false); var pd = new GraphicsPipelineDescription( new BlendStateDescription(RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend), DepthStencilStateDescription.Disabled, rasterizerState, PrimitiveTopology.TriangleList, new ShaderSetDescription(new[] { VertexLayoutHelper.Vertex2DTextured }, _shaders, ShaderHelper.GetSpecializations(gd)), new[] { layout }, gd.SwapchainFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _pipeline.Name = "P_FullScreenQuad"; float[] verts = CoreUtil.GetFullScreenQuadVerts(gd.IsClipSpaceYInverted); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer(new BufferDescription(QuadIndices.SizeInBytes(), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, QuadIndices); }
// 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)); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc) { DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); (Shader vs, Shader fs) = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "ScreenDuplicator"); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend, BlendAttachmentDescription.OverrideBlend), gd.IsDepthRangeZeroToOne ? DepthStencilStateDescription.DepthOnlyGreaterEqual : DepthStencilStateDescription.DepthOnlyLessEqual, RasterizerStateDescription.Default, PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { vs, fs, }, ShaderHelper.GetSpecializations(gd)), new ResourceLayout[] { resourceLayout }, sc.DuplicatorFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); float[] verts = Util.GetFullScreenQuadVerts(gd); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription((uint)s_quadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_quadIndices); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc) { DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend, BlendAttachmentDescription.OverrideBlend), DepthStencilStateDescription.DepthOnlyLessEqual, RasterizerStateDescription.Default, PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.Position, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { ShaderHelper.LoadShader(gd, factory, "ScreenDuplicator", ShaderStages.Vertex, "VS"), ShaderHelper.LoadShader(gd, factory, "ScreenDuplicator", ShaderStages.Fragment, "FS"), }), new ResourceLayout[] { resourceLayout }, sc.DuplicatorFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); _vb = factory.CreateBuffer(new BufferDescription((uint)s_quadVerts.Length * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, s_quadVerts); _ib = factory.CreateBuffer( new BufferDescription((uint)s_quadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_quadIndices); }
public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneContext sc) { DisposeCollectorResourceFactory factory = new(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); (Shader vs, Shader fs, SpecializationConstant[] specs) = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "FullScreenQuad"); GraphicsPipelineDescription pd = new( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend), DepthStencilStateDescription.Disabled, new RasterizerStateDescription(FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.Clockwise, true, false), PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { vs, fs }, specs), new ResourceLayout[] { resourceLayout }, gd.SwapchainFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); float[] verts = Util.GetFullScreenQuadVerts(gd); _vb = factory.CreateBuffer(new BufferDescription(verts.SizeInBytes() * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription(s_quadIndices.SizeInBytes(), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_quadIndices); }
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); }
public void CreateDeviceObjects(GraphicsDevice gd, CommandList cl) { DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); _disposeCollector = factory.DisposeCollector; //ResourceLayout resourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription()); (Shader vs, Shader fs) = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "FullScreenQuad"); GraphicsPipelineDescription pd = new GraphicsPipelineDescription( new BlendStateDescription( RgbaFloat.Black, BlendAttachmentDescription.OverrideBlend), new DepthStencilStateDescription(true, true, ComparisonKind.Always), new RasterizerStateDescription(FaceCullMode.Back, PolygonFillMode.Solid, FrontFace.Clockwise, true, false), PrimitiveTopology.TriangleList, new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("TexCoords", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { vs, fs }, ShaderHelper.GetSpecializations(gd)), new ResourceLayout[] { }, gd.SwapchainFramebuffer.OutputDescription); _pipeline = factory.CreateGraphicsPipeline(ref pd); float[] verts = Utils.GetFullScreenQuadVerts(gd); _vb = factory.CreateBuffer(new BufferDescription((uint)verts.Length * sizeof(float), BufferUsage.VertexBuffer)); cl.UpdateBuffer(_vb, 0, verts); _ib = factory.CreateBuffer( new BufferDescription((uint)s_quadIndices.Length * sizeof(ushort), BufferUsage.IndexBuffer)); cl.UpdateBuffer(_ib, 0, s_quadIndices); }
/// <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(); }
/// <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(); }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="Control" /> class. /// </summary> protected Control() { _collector = new DisposeCollector(); }
public DisposeCollectorResourceFactory(ResourceFactory factory, DisposeCollector disposeCollector) { Factory = factory; DisposeCollector = disposeCollector; }
/// <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(); }
public DisposingResourceFactoryFacade(ResourceFactory factory, DisposeCollector collector) : base(factory.Features) { _factory = factory; _collector = collector ?? throw new ArgumentNullException(nameof(collector)); }
/// <summary> /// Binds the specified effect data to this instance. /// </summary> /// <param name="effectDataArg">The effect data arg.</param> /// <param name="cloneFromEffect">The clone from effect.</param> /// <exception cref="System.InvalidOperationException">If no techniques found in this effect.</exception> /// <exception cref="System.ArgumentException">If unable to find effect [effectName] from the EffectPool.</exception> internal void InitializeFrom(EffectData.Effect effectDataArg, Effect cloneFromEffect) { RawEffectData = effectDataArg; // Clean any previously allocated resources if (DisposeCollector != null) { DisposeCollector.DisposeAndClear(); } ConstantBuffers.Clear(); Parameters.Clear(); Techniques.Clear(); ResourceLinker = ToDispose(new EffectResourceLinker()); if (effectConstantBuffersCache != null) { effectConstantBuffersCache.Clear(); } // Copy data IsSupportingDynamicCompilation = RawEffectData.Arguments != null; ShareConstantBuffers = RawEffectData.ShareConstantBuffers; // Create the local effect constant buffers cache if (!ShareConstantBuffers) { effectConstantBuffersCache = new Dictionary <EffectConstantBufferKey, EffectConstantBuffer>(); } var logger = new Logger(); int techniqueIndex = 0; int totalPassCount = 0; EffectPass parentPass = null; foreach (var techniqueRaw in RawEffectData.Techniques) { var name = techniqueRaw.Name; if (string.IsNullOrEmpty(name)) { name = string.Format("${0}", techniqueIndex++); } var technique = new EffectTechnique(this, name); Techniques.Add(technique); int passIndex = 0; foreach (var passRaw in techniqueRaw.Passes) { name = passRaw.Name; if (string.IsNullOrEmpty(name)) { name = string.Format("${0}", passIndex++); } var pass = new EffectPass(logger, this, technique, passRaw, name); pass.Initialize(logger); // If this is a subpass, add it to the parent pass if (passRaw.IsSubPass) { if (parentPass == null) { logger.Error("Pass [{0}] is declared as a subpass but has no parent."); } else { parentPass.SubPasses.Add(pass); } } else { technique.Passes.Add(pass); parentPass = pass; } } // Count the number of passes totalPassCount += technique.Passes.Count; } if (totalPassCount == 0) { throw new InvalidOperationException("No passes found in this effect."); } // Log all the exception in a single throw if (logger.HasErrors) { throw new InvalidOperationException(Utilities.Join("\n", logger.Messages)); } // Initialize the resource linker when we are done with all pass/parameters ResourceLinker.Initialize(); //// Sort all parameters by their resource types //// in order to achieve better local cache coherency in resource linker Parameters.Items.Sort((left, right) => { // First, order first all value types, then resource type var comparison = left.IsValueType != right.IsValueType ? left.IsValueType ? -1 : 1 : 0; // If same type if (comparison == 0) { // Order by resource type comparison = ((int)left.ResourceType).CompareTo((int)right.ResourceType); // If same, order by resource index if (comparison == 0) { comparison = left.Offset.CompareTo(right.Offset); } } return(comparison); }); // Prelink constant buffers int resourceIndex = 0; foreach (var parameter in Parameters) { // Recalculate parameter resource index if (!parameter.IsValueType) { parameter.Offset = resourceIndex; resourceIndex += parameter.ElementCount; } // Set the default values parameter.SetDefaultValue(); if (parameter.ResourceType == EffectResourceType.ConstantBuffer) { parameter.SetResource(ConstantBuffers[parameter.Name]); } } // Compute slot links foreach (var technique in Techniques) { foreach (var pass in technique.Passes) { foreach (var subPass in pass.SubPasses) { subPass.ComputeSlotLinks(); } pass.ComputeSlotLinks(); } } // Setup the first Current Technique. CurrentTechnique = this.Techniques[0]; // Initialize predefined parameters used by Model.Draw (to speedup things internally) DefaultParameters = new EffectDefaultParameters(this); // If this is a clone, we need to if (cloneFromEffect != null) { // Copy the content of the constant buffers to the new instance. for (int i = 0; i < ConstantBuffers.Count; i++) { cloneFromEffect.ConstantBuffers[i].CopyTo(ConstantBuffers[i]); } // Copy back all bound resources except constant buffers // that are already initialized with InitializeFrom method. for (int i = 0; i < cloneFromEffect.ResourceLinker.Count; i++) { if (cloneFromEffect.ResourceLinker.BoundResources[i] is EffectConstantBuffer) { continue; } ResourceLinker.BoundResources[i] = cloneFromEffect.ResourceLinker.BoundResources[i]; unsafe { ResourceLinker.Pointers[i] = cloneFromEffect.ResourceLinker.Pointers[i]; } } // If everything was fine, then we can register it into the pool Pool.AddEffect(this); } // Allow subclasses to complete initialization. Initialize(); OnInitialized(); }
/// <summary> /// Creates a new Scene. /// </summary> /// <param name="name">Unique scene name. If 'null', the name will be set to the class name.</param> public Scene(string name = null) { UnloadResources = true; contentCollector = new DisposeCollector(); Name = name == null?this.GetType().Name : name; }
/// <summary> /// Initializes a new instance of the <see cref="Renderer" /> class. /// </summary> /// <param name="name"> name. </param> protected Renderer(string name) { Name = name; _collector = new DisposeCollector(); }