在我的场景中,我有几个永不改变的静态模型。有些模型只有float3顶点和16位索引,有些更复杂,顶点有颜色和法线,32位索引。
Q1。我可以将它们全部组合在一个顶点和索引缓冲区中,并绘制如下:
// Model #1 has only position and 16 bit indices
const int model1verts = 20, model1indices = 100;
UINT stride1 = sizeof( Vector3 ), offset1 = 0;
context->IASetVertexBuffers( 0, 1, &vb, &stride1, &offset1 );
context->IASetIndexBuffer( ib, DXGI_FORMAT_R16_UINT, 0 );
context->DrawIndexed( model1indices, 0, 0 );
// Set another shader + input layout here
// Model #2 has positions + normals, and 32 bit indices
const int model2verts = 200, model2indices = 500;
UINT stride2 = sizeof( Vector3 ) * 2, offset2 = stride1 * model1verts;
context->IASetVertexBuffers( 0, 1, &vb, &stride2, &offset2 );
context->IASetIndexBuffer( ib, DXGI_FORMAT_R32_UINT, model1indices * sizeof( uint16_t ) );
context->DrawIndexed( model2indices, 0, 0 );
// 20 more models to follow, all from the same buffers
Q2。 AFAIK,GPU喜欢对齐的数据。调用IASetVertexBuffers / IASetIndexBuffer时,这些偏移量应该是4或16字节的倍数吗?文档没有说明。
Q3。我应该这样做吗?与每个自己的格式的20-100个较小的缓冲区相比,这会节省资源吗?