Game Development Reference
In-Depth Information
step rate. We have set this to 0 in our code since we are not using this feature, and
it is beyond the scope of this chapter.
With that, we're almost done now. The next line of code creates an InputLayout
objectthatwillholdtheinformationwejustsetup.Wepassinthreeparameterswhen
we create it. The first parameter is our Direct3D device object. The second paramet-
er is the signature of our vertex shader, and the last parameter is the input elements
array we just created.
The next line of code tells the input assembler to use our new InputLayout object.
Remember from earlier in this chapter that the input assembler is a stage in the Dir-
ect3D graphics pipeline.
Next, we call the SetVertexBuffers() method on the InputAssembler . This
tells it what vertex buffer we want to use. If you had multiple objects to draw, you can
reset the vertex buffers multiple times in the RenderScene() method. This method
takes three parameters. The first parameter is the slot we want to use. Depending
on the feature level we are using, the maximum number of slots available to use can
vary. The second parameter is a VertexBufferBinding object. We give it three
parameters when we create it. The first parameter is our vertex buffer that we cre-
ated a moment ago. The second parameter is the total size of our vertex buffer, and
the last parameter is an offset to the first vertex in the buffer. We have set this to 0
since our first vertex is at the very beginning of the buffer.
Finally, we have one more line of code to set the primitive topology . This setting
basically tells the graphics pipeline how to interpret our vertex data. In this case, we
set this to PrimitiveTopology.TriangleList . This tells Direct3D that our ver-
tex data is a list of triangles, or, in other words, every three vertices in the list form a
triangle. There are a number of other options you can use for this setting, and they
are all defined in the PrimitiveTopology enumeration.
The input assembler also has a SetIndexBuffer() method for setting index buf-
fers .Anindexbuffersimplyholdsalistofoffsets intoavertexbuffertoallowformore
efficient rendering. For example, let's say we want to render a square. It has four
vertices, but we'd have to create six to render it using a vertex buffer alone (three per
triangle, and a square is composed of two triangles). We could accomplish this using
only four vertices if we use an index buffer. Our index buffer would have two values
in it.
Search WWH ::




Custom Search