GraphicsResource class refactored
このコミットが含まれているのは:
1 親
8e041638db
コミット
79605702c8
4ファイル変更
+72
-58
検索条件に一致するファイルはありません
@@ -1,16 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using DirectX12GameEngine.Core;
|
||||
using DirectX12GameEngine.Graphics.Primitives.Abstract;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace DirectX12GameEngine.Graphics
|
||||
{
|
||||
public partial class Buffer : GraphicsResource
|
||||
{
|
||||
public Buffer()
|
||||
{
|
||||
}
|
||||
|
||||
protected Buffer(GraphicsDevice device) : base(device)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using DirectX12GameEngine.Graphics.Primitives.Abstract;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace DirectX12GameEngine.Graphics
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace DirectX12GameEngine.Graphics
|
||||
{
|
||||
public abstract class GraphicsResource : IDisposable
|
||||
{
|
||||
protected GraphicsResource()
|
||||
{
|
||||
}
|
||||
|
||||
protected GraphicsResource(GraphicsDevice device)
|
||||
{
|
||||
AttachToGraphicsDevice(device);
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
public GraphicsDevice GraphicsDevice { get; private set; }
|
||||
#nullable restore
|
||||
|
||||
public IntPtr MappedResource { get; private set; }
|
||||
|
||||
#nullable disable
|
||||
protected internal Resource NativeResource { get; set; }
|
||||
#nullable restore
|
||||
|
||||
protected internal CpuDescriptorHandle NativeCpuDescriptorHandle { get; protected set; }
|
||||
|
||||
protected internal GpuDescriptorHandle NativeGpuDescriptorHandle { get; protected set; }
|
||||
|
||||
public void AttachToGraphicsDevice(GraphicsDevice device)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
NativeResource.Dispose();
|
||||
}
|
||||
|
||||
public IntPtr Map(int subresource)
|
||||
{
|
||||
IntPtr mappedResource = NativeResource.Map(subresource);
|
||||
MappedResource = mappedResource;
|
||||
return mappedResource;
|
||||
}
|
||||
|
||||
public void Unmap(int subresource)
|
||||
{
|
||||
NativeResource.Unmap(subresource);
|
||||
MappedResource = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace DirectX12GameEngine.Graphics.Primitives.Abstract
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract <see langword="class"/> that represents a graphics resource object
|
||||
/// </summary>
|
||||
public abstract class GraphicsResource : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsResource"/> instance with the specified parameters
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance</param>
|
||||
protected GraphicsResource(GraphicsDevice device)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="GraphicsDevice"/> associated with the current instance
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IntPtr"/> associated to the currently mapped resource
|
||||
/// </summary>
|
||||
public IntPtr MappedResource { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Resource"/> object currently mapped
|
||||
/// </summary>
|
||||
protected internal Resource? NativeResource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CpuDescriptorHandle"/> instance for the current resource
|
||||
/// </summary>
|
||||
protected internal CpuDescriptorHandle NativeCpuDescriptorHandle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="GpuDescriptorHandle"/> instance for the current resource
|
||||
/// </summary>
|
||||
protected internal GpuDescriptorHandle NativeGpuDescriptorHandle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maps the current resource to a specified subresource
|
||||
/// </summary>
|
||||
/// <param name="subresource">The index of the target subresource to map</param>
|
||||
/// <returns>An <see cref="IntPtr"/> for the newly mapped resource</returns>
|
||||
public IntPtr Map(int subresource)
|
||||
{
|
||||
IntPtr mappedResource = NativeResource?.Map(subresource) ?? throw new InvalidOperationException("Missing resource");
|
||||
MappedResource = mappedResource;
|
||||
return mappedResource;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unmaps a subresource specified by a given index
|
||||
/// </summary>
|
||||
/// <param name="subresource">The index of the subresource to unmap</param>
|
||||
public void Unmap(int subresource)
|
||||
{
|
||||
NativeResource?.Unmap(subresource);
|
||||
MappedResource = IntPtr.Zero;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void Dispose() => NativeResource?.Dispose();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする