struct DXBundle {
ID3D11Device* device;
ID3D11DeviceContext* context;
D3D_FEATURE_LEVEL* featureLevel;
DXBundle() {
UINT createFlags = 0;
#if _DEBUG
createFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
return D3D11CreateDevice(
0, D3D_DRIVER_TYPE_HARDWARE, 0, createFlags,
0, 0, D3D11_SDK_VERSION, device, featureLevel, context);
}
~DXBundle() {
if(context) {
context->ClearState();
context->Flush();
context->Release();
}
if(device) {
device->Release();
}
}
};
There's a couple places I could see using this, the above example is a simple one that appears fairly convenient. Automatic construction and release at the cost of a dot operator seems like a fair trade. Anyone know of any reasons to avoid creating little "construction wrappers" like this?
Note: I've left out copy and copy assign intentionally for readability, that and the jury's still out on how I want to handle them in this particular instance...