Graphics Reference
In-Depth Information
When creating the vertex buffer, any structure can be used to represent the vertex as long as
its memory layout matches the input layout. We have used an array of Vector4 instances in
this example; however, this could, just as easily, have been a new structure with two Vector4
members or an array of floats. In this code, every second Vector4 represents the color of the
vertex (RGBA).
Coordinates of the vertices in the vertex buffer are in the object space
or model space, and they are usually created around the origin point.
The axis lines in the AxisLinesRenderer class are made up of 18 vertices to draw the
lines and arrow shapes for the axes. We create the buffer like any other Buffer object but
with a binding of BindFlags.VertexBuffer . Then, we create a VertexBufferBinding ,
passing the size of a single element as the stride and 0 as the offset.
buffer=Buffer.Create(device, BindFlags.VertexBuffer , new[] {...});
binding = new VertexBufferBinding(buffer, Utilities.SizeOf<Vector4>()
* 2 , 0);
Before issuing the draw command for the axis lines, first we must tell the IA that the
vertex buffer represents a list of lines by setting the context.InputAssembler.
PrimitiveTopology to PrimitiveTopology.LineList . Then, we set the vertex buffers
of the IA, and issue the DeviceContext draw command for 18 vertices—starting at the first
vertex with a call to context.Draw(18, 0) .
The axis-lines could be added to any scene during development to
assist with the orientation.
The TriangleRenderer class is made in exactly the same way except that we need
three vertices to render an object, and when drawing, we must set PrimitiveTopology to
PrimitiveTopology.TriangleList . The context.Draw command passes three vertices.
The Input Assembler will automatically ignore malformed primitives, that is, lines require a
start and end point. If an odd number of vertices was provided in the vertex buffer, the last
vertex will be discarded. This applies to all vertex buffers.
The QuadRenderer class does not represent a quad primitive type (there is no such
primitive). Instead, we create two triangles for the halves of the quad. This is done exactly
the same as the triangle example, but, with two triangles. All complex shapes are made up
of multiple triangles in a similar fashion.
 
Search WWH ::




Custom Search