-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35e529a
commit 440a541
Showing
14 changed files
with
1,333 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Patchwork.Framework.Rendering/Platform/Rendering/NRenderResourceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Shin.Framework; | ||
using Shin.Framework.Collections.Concurrent; | ||
using Shin.Framework.IoC.DependencyInjection; | ||
|
||
namespace Patchwork.Framework.Platform.Rendering | ||
{ | ||
public abstract class NRenderResourceFactory : Initializable, INResourceFactory | ||
{ | ||
protected IContainer m_iocContainer; | ||
protected ConcurrentList<Type> m_supportedResources; | ||
|
||
public NRenderResourceFactory(IContainer iocContainer) | ||
{ | ||
m_iocContainer = iocContainer.CreateChildContainer(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public event EventHandler OnCreate; | ||
|
||
/// <inheritdoc /> | ||
public event EventHandler OnDestroy; | ||
|
||
/// <inheritdoc /> | ||
public IEnumerable<Type> SupportedResources | ||
{ | ||
get { return m_supportedResources; } | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void InitializeResources() | ||
{ | ||
base.InitializeResources(); | ||
|
||
m_supportedResources = new ConcurrentList<Type>(); | ||
RegisterResources(); | ||
foreach (var resource in m_supportedResources) | ||
m_iocContainer.Register(resource); | ||
} | ||
|
||
protected abstract void RegisterResources(); | ||
|
||
/// <inheritdoc /> | ||
public virtual T Create<T>(params object[] parameters) where T : INResource | ||
{ | ||
Throw.If(!m_supportedResources.Contains(typeof(T))).InvalidOperationException(); | ||
var r = m_iocContainer.Resolve<T>(null, parameters); | ||
if (m_isInitialized) | ||
r.Create(); | ||
|
||
return r; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public virtual void Destroy<T>(T instance) where T : INResource | ||
{ | ||
Throw.If(!m_supportedResources.Contains(typeof(T))).InvalidOperationException(); | ||
instance.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Platform/Patchwork.Framework.DirectX/Platform/Rendering/D2D1Device.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Patchwork.Framework.Platform.Windowing; | ||
using Shin.Framework.IoC.DependencyInjection; | ||
|
||
namespace Patchwork.Framework.Platform.Rendering | ||
{ | ||
public class D2D1Device : NRenderDevice<D2D1Adapter> | ||
{ | ||
/// <inheritdoc /> | ||
protected override void RegisterRenderers() | ||
{ | ||
m_iocContainer.Register<INRenderDevice>(this); | ||
m_iocContainer.Register<INRenderAdapter, D2D1Adapter>(); | ||
m_iocContainer.Register<INResourceFactory, D2D1ResourceFactory>(); | ||
m_iocContainer.Register<INWindowRenderer, D2D1WindowRenderer>(false); | ||
m_supportedRenderers.Add(typeof(D2D1WindowRenderer)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void PlatformSetFrameBuffer(NFrameBuffer buffer) | ||
{ | ||
return; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void PlatformGetDpi(INWindow window) | ||
{ | ||
return; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public D2D1Device(IContainer iocContainer) : base(iocContainer) { } | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
src/Platform/Patchwork.Framework.DirectX/Platform/Rendering/D2D1RenderDevice.cs
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/Platform/Patchwork.Framework.DirectX/Platform/Rendering/D2D1ResourceFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Patchwork.Framework.Platform.Rendering.Resources; | ||
using SharpGen.Runtime; | ||
using Shin.Framework; | ||
using Shin.Framework.IoC.DependencyInjection; | ||
using Vortice.Direct2D1; | ||
using D2D1 = Vortice.Direct2D1.D2D1; | ||
|
||
namespace Patchwork.Framework.Platform.Rendering | ||
{ | ||
public sealed class D2D1ResourceFactory : NRenderResourceFactory | ||
{ | ||
private ID2D1Factory2 m_d2D1Factory; | ||
|
||
/// <inheritdoc /> | ||
public D2D1ResourceFactory(IContainer iocContainer) : base(iocContainer) { } | ||
|
||
/// <inheritdoc /> | ||
protected override void InitializeResources() | ||
{ | ||
base.InitializeResources(); | ||
|
||
var res = D2D1.D2D1CreateFactory(FactoryType.MultiThreaded, out m_d2D1Factory); | ||
Throw.If(res != Result.Ok).InvalidOperationException(); | ||
m_iocContainer.Register(m_d2D1Factory); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void DisposeManagedResources() | ||
{ | ||
m_d2D1Factory.Dispose(); | ||
|
||
base.DisposeManagedResources(); | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
protected override void RegisterResources() | ||
{ | ||
m_supportedResources.Add(typeof(D2D1RenderTarget)); | ||
} | ||
} | ||
} |
Oops, something went wrong.