Graphics Reference
In-Depth Information
create a buffer that will be updated by the GPU with the stream output functionality. In
this case, the D3D11_USAGE_DEFAULT usage flag would be used. A sample buffer creation
process is provided in Listing 2.6 to demonstrate these options.
// Initialize the device using it...
ID3DllDevice* g_pDevice = 0;
ID3DllBuffer* CreateVertexBuffer( UINT size,
bool dynamic,
bool streamout,
D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = size;
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
// Select the appropriate binding locations based on the passed in flags
if ( streamout )
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_STREAM_0UTPUT;
else
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
// Select the appropriate usage and CPU access flags based on the passed
// in flags
if ( dynamic )
{
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
}
else
{
desc.Usage = D3D11_USAGE_IMMUTABLE;
desc.CPUAccessFlags = 0;
}
// Create the buffer with the specified configuration
ID3D11Buffer* pBuffer = 0;
HRESULT hr = g_pDevice->CreateBuffer( &desc, pData, &pBuffer );
if ( FAILED( hr ) )
{
// Handle the error here...
return( 0 );
}
return( pBuffer );
Listing 2.6. A method for creating vertex buffers with various usage considerations.
Search WWH ::




Custom Search