Game Development Reference
In-Depth Information
two transformation matrices for processing vertex positions into screen space and
vertex normals from object space into world space. Defining a constant buffer for
Direct3D 11 is done by filling in the D3D11_BUFFER_DESC structure and sending
the result into ID3D11Device::CreateBuffer() . This is simply creating a data
buffer with a size sufficient for the data we
re going to copy into it during rendering.
As you might expect, the definition for the ConstantBuffer_Matrices is just the
two transform matrices the vertex shader needs:
'
struct ConstantBuffer_Matrices
{
Mat4x4 m_WorldViewProj;
Mat4x4 m_World;
};
The results are stored in the m_pcbVSMatrices member of the class. The two C++
structures referenced in the D3D11_BUFFER_DESC for material and lighting are
defined as follows:
struct ConstantBuffer_Material
{
Vec4 m_vDiffuseObjectColor;
Vec4 m_vAmbientObjectColor;
BOOL m_bHasTexture;
Vec3 m_vUnused;
};
struct ConstantBuffer_Lighting
{
Vec4 m_vLightDiffuse[MAXIMUM_LIGHTS_SUPPORTED];
Vec4 m_vLightDir[MAXIMUM_LIGHTS_SUPPORTED];
Vec4 m_vLightAmbient;
UINT m_nNumLights;
Vec3 m_vUnused;
};
There is a notable difference in these structures from the ConstantBuffer_
Matrices structure. At the end of each one, there is a Vec3 m_vUnused member.
The reason for this is that in each case, the previous member occupies only one byte
of the structure, leaving it at a size that can
'
t be properly aligned. GPU hardware is
notoriously picky about the size of structures, and if you don ' t send data to them
aligned on 16-byte boundaries, you
'
ll get an E_INVALIDARG error coming back
from the call to CreateBuffer() .
So here
s a quick review. The shader source code was loaded, compiled, and created
ready to use for rendering. The vertex layout was defined. The constant buffers for
'
Search WWH ::




Custom Search