I'm building a very basic object loader with DirectX and I decided I wanted to separate its logic from the main portion of my program and put it into its own class (as it probably should be).
The problem I'm having is that my Loader needs access to some of my MainWindow variables such as a DX11 SwapChain
to handle the backbuffer for frame rendering.
I'm very new to C++ so I am not sure if I am utilizing pointers efficiently here, but it would be of great help if someone could tell me if what I'm doing is wrong or maybe suggest a more efficient way of handling the problem.
Main Window:
// Global variables
IDXGISwapChain* g_swapChain; // Pointer to global swap chain
// Obj loader init example - pass the reference of global swap chain?
ObjectLoader l( &g_swapChain );
// Condensed method call as you don't need to see all parameters
loader.__loadModel("model.obj");
Now, in my ObjectLoader class, what sort of pointer would I set up in order to be able to constantly reference my Main Windows g_swapChain
? Am I right in thinking that I should use a double pointer, such as, with the encapsulated class global being a reference to that double pointer.
private:
IDXGISwapChain& loader_swapChain;
public:
ObjectLoader::ObjectLoader( IDXGISwapChain** swapChain )
{
loader_swapChain = swapChain;
}
The example below demonstrates where I would need to use MainWindow's swapchain.
ObjectLoader::__loadModel(std::string fielname)
{
if (modelLoaded)
...
else {
// this is an example of where I want to use the swap chain in MainWindow
loader_swapChain->SetFullscreenState(false, NULL);
}
}
Coming from a Java background, this pointer stuff is giving me headache - hopefully what I am asking makes sense, if not please ask and I will provide more information.