I've been thinking about how to go about doing this for a while now. I've got a shader parameter system that basically creates a chunk of data from a parameter list and allows them to be set using a map of names and offsets. The thing I can't figure out though, is how I should calculate padding for the parameters. Basically I allocate the data and store offsets like this:
bool IShaderParameterBuffer::init(const std::vector<SShaderParameterDesc>& paramDesc)
{
size_t offset = 0;
for ( unsigned int i=0; i<paramDesc.size(); ++i )
{
size_t paramSz = IInputLayout::getElementSize(paramDesc[i].Format);
m_offsetMap[paramDesc[i].Name] = offset;
offset += paramSz;
}
m_paramBuffer = (char*)malloc(offset);
m_bufferSz = offset;
return true;
}
And I take this information to create a constant buffer, but const buffer size has to be a multiple of 16. What would be the best way to go about making sure that the data size is a multiple of 16?