0

I want to structure my pipeline so that each mesh has a possibility to have only set elements like position, normals etc and since some meshes won't have all of them and some shaders won't require all of them I would like to have each attribute in a different buffer, now I don't know if it's better to call SetBuffers for each buffer setting just this 1 buffer at index x or there is a possibility to set all of them as an array at once but some will be null(I want to preserve slot numbers)

Werem
  • 21
  • 2

1 Answers1

0

IASetVertexBuffers allows you to specify a set of buffers in one call:

ID3D11DeviceContext* Context; // Initialized at creation
ID3D11Buffer* buffers[] = /* Initialized to a set of buffers, unused buffers set to null. */;
UINT Strides[] = /* Initialized to the size of each element in each buffer. */;
UINT Offsets[] = /* Initialized to the offset into each buffer, typically all zeros. */; 
Context->IASetVertexBuffers(0, ARRAYSIZE(buffers), buffers, Strides, Offsets);

See the documentation for more information about each parameter.

Note that this requires your input layouts for all your shaders to match all the meshes that can exist in your pipeline, which could complicate things if you have a shader that requires more parameters than the mesh provides. I'm not exactly certain what DirectX/the GPU will do when presented a null pointer on a required parameter, but I wouldn't assume it'd be good.

The easier option here would be to provide explicit default values for each mesh in the pipeline when the attributes are required but not provided by the source. This way, there's no issue with missing values.

Alex
  • 1,794
  • 9
  • 20