So I've went through some tutorials and resources such as the DirectX Documentation / Reference itself and either I missed something or I really can't find an answer to my question.
The question is as stated in the title: How does DirectX read in Vertices into Vertex Buffers?
I've understood, of course, that you have to provide one or more FVF codes. But it doesn't say anywhere how to properly set up your Vertex struct. The only thing I could imagine would be, that DirectX checks flags in a linear "timeline", of course, so one flag which may require the same data types and orders must come first in the struct as well.
As a little example for what I mean:
struct MyVertex {
float x, y, z;
float nx, ny, ny;
};
!=
struct MyVertex {
float nx, ny, nz;
float x, y, z;
};
with the FVF codes:
D3DFVF_XYZ | D3DFVF_NORMAL
and nx
, ny
, nz
representing the 3D coordinates of the normal vertex.
Any help on how to properly set up your vertex struct is appreciated...
Sincerely,
Derija
You need to ensure the C++ and HLSL Structure, matches the order in which it was specified in the Vertex Format (if you specified XYZ then Normal, your structure must match this), then you need to use the device->CreateBuffer to create the vertex buffer, from the array of vertex structures, after which the arrays of vertex structures may be released and freed as DirectX will manage the buffer data independently from there, to alter the data in the render loop, the buffer must be writable, and can be updated after create using ID3D10Buffer Map and Unmap.
MSDN:
Create Vertexbufferm http://msdn.microsoft.com/en-us/library/windows/desktop/bb173544(v=vs.85).aspx Buffer: http://msdn.microsoft.com/en-us/library/windows/desktop/bb173510(v=vs.85).aspx
Eg: C++
HLSL: