firstly little background. I've seen a lot posts "Write games on engines" and I don't need this type of stuff here. I'm just trying to separate engine and game early on instead of having a lot of hardcoded things later on. This is where I encountered a problem. I'm trying to wrap DirectX into a bit more friendly classes, but they need DirectX Device and I can't think of a decent way of passing device to these objects. Roughly my code looks like this:
class VertexShader {
ID3D11VertexShader *shdr;
void Create(void *bytecode, uint32 size); // requires ID3D11Device or DXWrapper;
};
class DXWrapper {
ID3D11Device *dvc;
ID3D11DeviceContext *dvcc;
};
class Engine {
DXWrapper DXW;
};
// this is how I use VertexShader class:
class SkinnedRenderer {
VertexShader vrtShader;
SkinnedRenderer() {
auto bytecode = ResourceManager.Get("skinned_vs.cso");
vrtShader.Create(bytecode.data(), bytecode.size());
}
};
I managed to think of 2 possible solutions (workarounds?) but I'm not satisfied with either of them.
- Pass D3D Device as argument in VertexShader::Create() call, but I feel it's a bit messy doing it all the time.
- Make Engine or DXWrapper class's instance static/global, allowing global access, but I'm trying to avoid such dependency, as code re-useability decreases.
Anyone have any ideas how can I resolve this issue, or solution #1 is the right way?
Thank you in advance.
Edited by Ripiz, 03 October 2012 - 09:14 AM.






