Game Development Reference
In-Depth Information
we set the SizeInBytes property to the size of our vertex data, so the vertex
buffer will be big enough to hold it all. Then, we set the BindFlags property to
BindFlags.VertexBuffer since this buffer is going to be used as a vertex buffer.
We have set both the CpuAccessFlags and OptionFlags properties to None on
the next two lines as they are beyond the scope of this discussion.
The next line of code creates the VertexBuffer object. We pass in three paramet-
ers when we create it. The first parameter is our Direct3D device. The second para-
meter is the DataStream object we wrote our vertex data into, and the last para-
meter is the BufferDescription object we just created.
At this point, the using block ends. When program execution reaches this point, our
DataStream object gets disposed of since we no longer need it.
The next bit of code creates an array of the InputElement objects. This tells Direc-
t3D what data we have stored in each of our vertices, and how it is formatted. As you
can see, we have only added one input element here. It is the position of the vertex
in 3D space.
There are a handful of parameters we pass in when creating this InputElement
object. The first parameter is a string indicating what type of element this is. We set
this to "POSITION" since this input element holds the position of our vertex in 3D
space. The second parameter is an index that is used when you have multiple ele-
ments with the same name. So if we had two elements named "POSITION" , we
would set the index parameter to 1 for the second one. The third parameter is the
data format used by this input element. In this case, we need to store three num-
bers since a coordinate in 3D space is composed of three integers. So, we used the
format Format.R32G32B32_Float . This format holds three float values, each of
which is 32 bits in size. The next parameter is an offset to the next input element.
For convenience, we've set this to InputElement.AppendAligned , which means
this input element will start directly after the previous one. The next parameter is the
input slot to use for this input element. The valid values for this property are 0 - 15 .
Then, we have the slot class parameter, which we've set to InputClassifica-
tion.PerVertexData . This is because this element is being used on a per-vertex
basis since we need to store the position for every vertex. The last parameter is the
Search WWH ::




Custom Search