Game Development Reference
In-Depth Information
// Tell the VertexShader to use our
constant buffers.
m_DeviceContext.VertexShader.SetConstantBuffer(m_CbChangesOnResize,
0);
m_DeviceContext.VertexShader.SetConstantBuffer(m_CbChangesPerFrame,
1);
m_DeviceContext.VertexShader.SetConstantBuffer(m_CbChangesPerObject,
2);
}
In this method, we start by creating a
BufferDescription
. In this case, all three
of our constant buffers will be the same size (64 bytes), which means we can
get away with using just this one
BufferDescription
to create all three buf-
fers. We set its
ResourceUsage
property to
default
and its
BindFlags
prop-
erty to
BindFlags.ConstantBuffer
since we want to use these buffers as con-
stant buffers. We set the
CpuAccessFlags
property to
None
once again, and the
SizeInBytes
property we set to
64
since that's the size we need our constant buf-
fers to be. The reason is that in this demo, each of these buffers will simply hold a
single 4 x 4 matrix, which takes 64 bytes of memory.
The next three lines of code create each of our three constant buffers. Then, the next
block of code creates a
DataStream
object and stores it in our
m_DataStream
member variable so we can re-use it. Then we set the position of the data stream
to
0
so that we start writing at the beginning of it. Next, we write the transpose of
the projection matrix into the data stream and reset its position back to
0
again.
The last line is slightly complex, but it simply sends the data in the data stream into
the
m_CbChangesOnResize
constant buffer to make it available to the graphics
pipeline. The details of how this line actually works are beyond the scope of this
chapter.