I managed to build a working base for which to run a DirectX 11 application. However, while encapulating code away, I noticed that some COM pointers didn't run as intuitively expected when they were placed as protected:
members of a base class.
In Engine.h (header)
class Infinity3D{
public:
Infinity3D();
~Infinity3D();
virtual void Render();
virtual void Update();
virtual void D3DProcess();
virtual void ViewPort(UINT Height, UINT Width, float MaxDepth, float MinDepth, int TopLeftX, int TopLeftY);
virtual void StartSwapChain(ID3D11DepthStencilView *DepthStenView);
virtual void InitializeD3D();
virtual void TerminateD3D();
virtual void InitializeShader();
protected:
IDXGISwapChain* Swapchain;
ID3D11Device* Device;
ID3D11DeviceContext* DeviceContext;
ID3D11RenderTargetView* RenderTargetView;
IDXGIAdapter* DeviceAdapter;
ID3D11InputLayout* InputLayout;
ID3D11VertexShader* VertexShader;
ID3D11PixelShader* PixelShader;
ID3D11Buffer* D3DBuffer;
ID3D11Buffer* D3DIndexBuffer;
ID3D11DepthStencilView* DepthStenView;
ID3D11Texture2D* DepthStenBuffer;
ID3D11Buffer* MatrixBuffer;
XMMATRIX mWorld;
XMMATRIX mView;
XMMATRIX mProjection;
XMMATRIX mWVP;
HWND hWnd;
UINT cWidth;
UINT cHeight;
};
As a test, I ran only the basic functions of DirectX initialization: SwapChain,Viewport, and Rendering.
(I've a separate [header] class for window creation, which shows the window successfully.)
The instance to the class(es) has been created.
Infinity3D D3DSystem;
InfinityEngine Engine(hInstance);
When calling D3DSystem.InitializeD3D()
, or any Infinity3D
member function that requires a DirectX COM object, the program produces a runtime error:
The functions are called as:
int InfinityEngine::Process(){
while(WM_QUIT != msg.message){
if(PeekMessage(&msg, NULL, 0,0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
D3DSystem.Update();
D3DSystem.Render();
}
}
D3DSystem.TerminateD3D();
return msg.wParam;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow){
if(Engine.DisplayWindow()){D3DSystem.InitializeD3D();Engine.Process();}
}
For the sake of space, I'll show just the usage of COM pointers within the InitializeD3D class member.This is after DXGI_SWAP_CHAIN_DESC
is instantiated and D3D11CreateDeviceAndSwapChain()
is called.
Swapchain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)&Texture2d);