I'm quite confused as to how to correctly initialize the constant buffer using SharpDX. There is basically no documentation explaining how the process differs from the raw C++ process and the only posts I can find that mention doing it with SharpDX seem to be slightly varied use cases.
I have three matrices that need to go in the constant buffer. In my hlsl file, I have:
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
In my C# code, I set up my matrices like so:
_viewMatrix = Matrix.LookAtLH(new Vector3(0, 1, -5), new Vector3(0, 1, 0), Vector3.UnitY);
_projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI/4f, ratio, .1f, 110f);
_worldMatrix = Matrix.Identity;
Then I set up my constant buffer like so:
_constantBuffer = new BufferData<Matrix>(_device, BindFlags.ConstantBuffer,
Utilities.SizeOf<Matrix>()*3, new[] { _worldMatrix, _viewMatrix, _projectionMatrix });
_context.VertexShader.SetConstantBuffer(0, _constantBuffer.Buffer);
_context.UpdateSubresource(ref _worldMatrix, _constantBuffer.Buffer);
Now, I'm not 100% sure that I've done it wrong! However, my cube doesn't render anywhere, which I'm very confused about, and I guess I'm assuming it's related to the constant buffer setup as I can't see anything else that might be a problem.
For complete reference, all my code is here: https://gist.github.com/axefrog/7108721 (including "BufferData", which I referenced above)
If my constant buffer setup is fine, can you see anything else in the code that would stop a cube from appearing in the output window? For what it's worth, I am sure there are better ways of rendering cubes, but I'm just learning and it'd be nice to know what I've done wrong in this case.