Graphics Reference
In-Depth Information
{
desc.Usage = D3D11_USAGE_IMMUTABLE;
desc.CPUAccessFlags = 0 ;
}
// Create the buffer with the specified configuration
ID3DllBuffer* pBuffer = 0 ;
HRESULT hr = g_pDevice->CreateBuffer( &desc, pData, &pBuffer );
if ( FAILED( hr ) )
{
// Handle the error here...
return( 0 );
}
return( pBuffer );
}
Listing 2.7. A method for creating index buffers depending on their usage.
The first item to specify is the size of the buffer in bytes. As can be seen in the
code listing, the index buffer is always created with the D3D11_BIND_INDEX_BUFFER bind
flag. When a static index buffer is desired, the usage flag is specified as D3D11_USAGE_
IMMUTABLE, without any CPU access flags set. In this case, the intended contents of the
buffer must be provided to the creation call with the D3D11_SUBRES0URCE_DATA structure.
If a dynamic buffer is required, we would choose the D3D11_USAGE_DYNAMIC, along with
the D3D11_CPU_ACCESS_WRITE CPU access flag.
Resource view requirements. Index buffers are bound directly to the input assembler
stage, without the aid of a resource view. Because of this, there is no need to create a re-
source view to use index buffers.
Constant Buffers
The constant buffer is the first resource type that we have encountered that is accessible
from the programmable shader stages and is subsequently used in HLSL code. A constant
buffer is used to provide constant information to the programmable shader programs being
executed in the pipeline. The term constant refers to the fact that the data inside this buf-
fer remains constant throughout the execution of a draw or dispatch call. Any information
that only changes between pipeline invocations, such as a world transformation matrix
or object color, is supplied to the shader program in a constant buffer. This mechanism is
the primary means of data transfer from the host application to each of the programmable
shader stages. The type and amount of information contained within a constant buffer may
vary from buffer to buffer. This depends completely on the data needed for each particular
shader program, and is defined by a structure declaration in the shader program. The buffer
Search WWH ::




Custom Search