Hi, I'm using SharpDX (virtually identical to SlimDX), and I'm having a bit of a problem with my vertex processing:
Initially, I set it up in a very brute-force method that just makes the vertex buffer and stream, and then draws everything, but it did this for every triangle for every frame! This was alright at first, because I just wanted to get it working as simply as possible, and I was just drawing a few triangles, but needless to say, as I started to get lots of triangles it began to slow way down.
So I tweaked some things, so that now it is supposed to draw a list of all the triangles in any one object at a time, and also should be creating the stream and buffer ahead of time, and potentially altering the data each frame, but not re-creating the whole thing.
However, now the objects don't get drawn. It's not drawing them black, it's just not drawing them at all. I know this, because when I draw other objects the old way, they still appear, even when they're behind other objects that I'm telling to display using the new method.
Anyway, I can't get you all the source code, but I wrote down a sort of a sampling of the significant changes I've made, and I can't tell what's caused the problem:
In the initialization function:
totalBytes = bytesPerVertex * triangles.Count() * 3;
stream = new DataStream(totalBytes, true, true);
buffer = new Buffer(device, stream, totalBytes, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
triangles is just a list of triangles I store in my own format.
I changed the ResourceUsage from Default to Dynamic.
I changed the CpuAccessFlags from None to Write.
I'm still using the same device and context and stuff as before, and they're already set up at this point, and still work with the old method.
I'm still using the same old matrix transformations for movement and projections as before, and I'm not backface culling, so none of that should affect it.
In the drawing function:
First, I change the data in the Point[] points array however necessary.
Point is a custom structure but just holds data, and hasn't changed since before.
Also, I'm sure the data is being calculated how I want because I'm getting the positions, colors, normals, etc. that I expect.
Then:
stream.Position = 0; // Reset the position each time
stream.WriteRange<Point>(points);
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffer, bytesPerVertex, 0));
context.Draw(triangles.Count() * 3, 0);
This is all working the way it was before, except that I'm resetting the position (before I didn't need to because I recreated the whole thing each frame).
Anyway, if anyone can find any obvious flaw in this that would explain why it doesn't draw anything, I would really appreciate it. Thanks!