So we had this pattern in some of our code. Some sort of “device/API specific objects” need to be created out of simple “descriptor/key” structures. Think D3D11 rasterizer state or Metal pipeline state, or something similar to them.
Most of that code looked something like this (names changed and simplified):
// m_States is std::map<StateDesc, DeviceState> const DeviceState* GfxDevice::CreateState(const StateDesc& key) { // insert default state (will do nothing if key already there) std::pair<CachedStates::iterator, bool> res = m_States.
↧