Remove build message saying that a content file is still valid and will be skipped. Use OnApply for Effects, instead of an internal PreBindSetParameters. Removed unnecessary dependencies from EffectParameterCollection and EffectTechniqueCollection. Moved Apply from INativeEffect to INativeEffectPass as Apply can only be called on an EffectPass. Added IDisposable to many Native object interfaces. Added an InputLayoutManager so the InputLayouts don't get created on every call. Increased the amount of shared code for the GraphicsDevice between DX10 and DX11. Simplified the amount of stuff the Draw calls do. It's possible to use specific renderPasses when drawing and the drawing methods of the GraphicsDevice don't draw all effectPasses of an effec anymore. Fixed the bug that a DynamicVertexBuffer created a staging buffer when setting Elements for DX10 and DX11, which was unnecessary. Also it didn't create a staging before for normal VertexBuffers which made it not possible to set data there. Implement EffectAnnotations for DX10. Fixed SetRenderTargets for DX11.
109 lines
3.0 KiB
C#
109 lines
3.0 KiB
C#
using ANX.Framework.Graphics;
|
|
using SharpDX;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Dx = SharpDX.Direct3D11;
|
|
|
|
namespace ANX.RenderSystem.Windows.DX11
|
|
{
|
|
public abstract class Buffer : IDisposable
|
|
{
|
|
public Dx.Buffer NativeBuffer
|
|
{
|
|
get { return nativeBuffer; }
|
|
protected set
|
|
{
|
|
if (value != null)
|
|
SizeInBytes = value.Description.SizeInBytes;
|
|
else
|
|
SizeInBytes = 0;
|
|
|
|
nativeBuffer = value;
|
|
}
|
|
}
|
|
|
|
private Dx.Buffer nativeBuffer;
|
|
|
|
private Dx.Device device;
|
|
private BufferUsage usage;
|
|
private bool isDynamic;
|
|
|
|
public int SizeInBytes
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
protected Buffer(Dx.Device device, BufferUsage usage, bool isDynamic)
|
|
{
|
|
this.device = device;
|
|
this.usage = usage;
|
|
this.isDynamic = isDynamic;
|
|
}
|
|
|
|
protected DataStream MapBuffer(Dx.Buffer buffer, ResourceMapping mapping)
|
|
{
|
|
CheckUsage(mapping);
|
|
|
|
Dx.MapMode mapMode;
|
|
if (isDynamic && mapping == ResourceMapping.Write)
|
|
mapMode = Dx.MapMode.WriteDiscard;
|
|
else
|
|
mapMode = mapping.ToMapMode();
|
|
|
|
DataStream dataStream;
|
|
device.ImmediateContext.MapSubresource(buffer, mapMode, Dx.MapFlags.None, out dataStream);
|
|
return dataStream;
|
|
}
|
|
|
|
protected void UnmapBuffer(Dx.Buffer buffer)
|
|
{
|
|
device.ImmediateContext.UnmapSubresource(buffer, 0);
|
|
}
|
|
|
|
protected void CopySubresource(Dx.Buffer source, Dx.Buffer destination)
|
|
{
|
|
BufferHelper.ValidateCopyResource(source, destination);
|
|
|
|
this.NativeBuffer.Device.ImmediateContext.CopyResource(source, destination);
|
|
}
|
|
|
|
protected bool WriteNeedsStaging
|
|
{
|
|
get { return !this.isDynamic; }
|
|
}
|
|
|
|
private void CheckUsage(ResourceMapping mapping)
|
|
{
|
|
if ((mapping & ResourceMapping.Write) != 0 && usage == BufferUsage.None)
|
|
throw new NotSupportedException("Resource was created with WriteOnly, reading from it is not supported.");
|
|
}
|
|
|
|
protected Dx.Buffer CreateStagingBuffer(ResourceMapping mapping)
|
|
{
|
|
CheckUsage(mapping);
|
|
|
|
var description = new Dx.BufferDescription()
|
|
{
|
|
Usage = Dx.ResourceUsage.Staging,
|
|
SizeInBytes = NativeBuffer.Description.SizeInBytes,
|
|
CpuAccessFlags = mapping.ToCpuAccessFlags(),
|
|
OptionFlags = Dx.ResourceOptionFlags.None
|
|
};
|
|
|
|
return new Dx.Buffer(device, description);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (NativeBuffer != null)
|
|
{
|
|
NativeBuffer.Dispose();
|
|
NativeBuffer = null;
|
|
}
|
|
}
|
|
}
|
|
}
|