Call for Design Comments

Started by
0 comments, last by incertia 11 years, 5 months ago
I'd really like some opinions on the following idea:


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...
Advertisement
If it's personal code and you understand everything that is going on, then sure.

However, if other people are reading your code or if you may forget why you did it like that, then I suggest you you wrap everything in a nice class with functions that can change how you want the device to be created.
what

This topic is closed to new replies.

Advertisement