• Advertisement
Sign in to follow this  

Call for Design Comments

This topic is 1895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd really like some opinions on the following idea:

[CODE]
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();
}
}
};
[/CODE]

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement