I need help with a image processing task... I'm using SharpDX which I am very new to. I have a device3D, device3DContext... I have a Texture2D for off-screen rendering... I have a RenderTargetView...
Here is what I cannot figure out... I need to create a Quad aligned to the target dimensions... based on a TriangleStrip... I need to load an image onto said Quad... I need to be able to apply a Pixel Shader to it...
Here is my prototype so far...
public event Action OnInitialized;
public ImageProcessor()
{
}
public void Initialize(System.Drawing.Size size)
{
try
{
var bestAdapter = DisplayAdapters.GetBestAdapter(SharpDX.Direct3D.FeatureLevel.Level_10_0);
using (
var device = new SharpDX.Direct3D11.Device(bestAdapter,
SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, bestAdapter.FeatureLevel()))
{
Device = device.QueryInterface<SharpDX.Direct3D11.Device1>();
}
using (var dxgiDevice = Device.QueryInterface<SharpDX.DXGI.Device>())
{
GPUDescription = dxgiDevice.Adapter.Description.Description;
}
DeviceContext = AddDisposable(Device.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>());
var colorFormat = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
var bufferDescription = new SharpDX.Direct3D11.Texture2DDescription()
{
ArraySize = 1,
BindFlags = SharpDX.Direct3D11.BindFlags.RenderTarget | SharpDX.Direct3D11.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
Format = colorFormat,
Height = size.Height,
Width = size.Width,
MipLevels = 1,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D11.ResourceUsage.Default
};
Target = new SharpDX.Direct3D11.Texture2D(Device, bufferDescription);
RenderTargetView = new SharpDX.Direct3D11.RenderTargetView(Device, Target);
OnInitialized?.Invoke(this);
}
catch (SharpDX.SharpDXException ex)
{
var desc = ex.ResultCode;
}
}
public System.Drawing.Image ProcessImage(string filename)
{
Device.ImmediateContext.ClearRenderTargetView(RenderTargetView, SharpDX.Color.Gray);
Target = TextureLoader.CreateTexture2DFromFile(Device, filename);
Device.ImmediateContext.Flush();
var memoryStream = new MemoryStream();
CopyTexture.ToImage(DeviceContext, Target, memoryStream);
memoryStream?.Flush();
var processedImage = System.Drawing.Image.FromStream(memoryStream);
memoryStream?.Dispose();
return processedImage;
}
private SharpDX.Direct3D11.Device1 Device;
private SharpDX.Direct3D11.DeviceContext1 DeviceContext;
private SharpDX.Direct3D11.Texture2D Target;
private SharpDX.Direct3D11.RenderTargetView RenderTargetView;
public string GPUDescription = string.Empty;
Please explain code in detail...
I've asked a similar question and someone provided a HLSL file which didn't require vertices however, I have no idea how to apply it... So I figured I'd provide the code and ask for more detailed help.