Maintenance
- Added 'Get*Ref()' to 'dxSharedContext'
- Fixed 'dxFramebuffer::Resize' not resizing :/
- Fixed 'dxFrameBuffer::BindAsTarget' not setting the viewport
- Fixed 'dxRenderCommand::SetViewport()' not resizing the swapchain's
      buffer
- Improved 'dxGraphicsContext''s debug interface
-  Removed most of the 'ComPtr's in 'dxGraphicsContext',  they can be
      accessed with the 'm_SharedContext'
			
			
This commit is contained in:
		
							parent
							
								
									aac2c51bd5
								
							
						
					
					
						commit
						5cc82f1558
					
				
					 7 changed files with 104 additions and 47 deletions
				
			
		| 
						 | 
				
			
			@ -11,10 +11,10 @@
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
// version
 | 
			
		||||
#define LT_VERSION "0.7.4" 
 | 
			
		||||
#define LT_VERSION "0.7.5b"
 | 
			
		||||
///*** [  CHANGE_LOG  ] ***///
 | 
			
		||||
// --------------------------------------------------------------------
 | 
			
		||||
// Note: change log starts from 2021-07-21, the starting version is 0.7.0,
 | 
			
		||||
// Note: change log starts from 2021-07-21, the starting version is 0.7.0a,
 | 
			
		||||
// I came up with that version because of:
 | 
			
		||||
//     projects: 'Engine', 'Sandbox', 'Mirror' [+0.3]
 | 
			
		||||
//     graphics apis: 'OpenGL', 'DirectX11'    [+0.2]
 | 
			
		||||
| 
						 | 
				
			
			@ -22,16 +22,16 @@
 | 
			
		|||
// --------------------------------------------------------------------
 | 
			
		||||
// 
 | 
			
		||||
// 
 | 
			
		||||
// 0.7.0: started the change log
 | 
			
		||||
// 0.7.0a: started the change log
 | 
			
		||||
//
 | 
			
		||||
// 0.7.1: [ LT_BREAK ]
 | 
			
		||||
// 0.7.1a: [ LT_BREAK ]
 | 
			
		||||
//     - Added the 'LT_BERAK' macro, a portable debug-trap
 | 
			
		||||
// 
 | 
			
		||||
// 0.7.2: [ Failed engine/client assertion ]
 | 
			
		||||
// 0.7.2a: [ Failed engine/client assertion ]
 | 
			
		||||
//     - Separated 'FailedAssertion' into 'FailedEngineAssertion' and 'FailedClientAssertion'
 | 
			
		||||
//     - Minor adjustment to the change log
 | 
			
		||||
// 
 | 
			
		||||
// 0.7.3: [ Layer Improvements ]
 | 
			
		||||
// 0.7.3a: [ Layer Improvements ]
 | 
			
		||||
//     - Added 'Layer::OnEvent()', 'Layer' now handles an event by itself and doesn't need another class to determine the event's type
 | 
			
		||||
//     
 | 
			
		||||
//     - Added reverse iterators 'rend()' and 'rbegin()' to 'LayerStack'
 | 
			
		||||
| 
						 | 
				
			
			@ -44,11 +44,21 @@
 | 
			
		|||
//     
 | 
			
		||||
//     - Fixed a typo where in 'Mirror' where the name of the 'MirrorLayer' was "SandboxLayer" instead of "MirrorLayer"
 | 
			
		||||
// 
 | 
			
		||||
// 0.7.4 [ Input ]
 | 
			
		||||
// 0.7.4a: [ Input ]
 | 
			
		||||
//     - Added 'Input'
 | 
			
		||||
//     - - Added <InputCodes>
 | 
			
		||||
//     - The 'MirrorLayer''s ImGuiWindow, "GameView" will not receive/react to input events if the window is not focused
 | 
			
		||||
// 
 | 
			
		||||
//  0.7.4b [ Maintenance ]
 | 
			
		||||
//      - Added 'Get*Ref()' to 'dxSharedContext'
 | 
			
		||||
//      
 | 
			
		||||
//      - Fixed 'dxFramebuffer::Resize' not resizing : /
 | 
			
		||||
//      - Fixed 'dxFrameBuffer::BindAsTarget' not setting the viewport
 | 
			
		||||
//      - Fixed 'dxRenderCommand::SetViewport()' not resizing the swapchain's buffer
 | 
			
		||||
//      
 | 
			
		||||
//      - Improved 'dxGraphicsContext''s debug interface
 | 
			
		||||
//      
 | 
			
		||||
//      - Removed most of the 'ComPtr's in 'dxGraphicsContext', they can be accessed with the 'm_SharedContext'
 | 
			
		||||
// 
 | 
			
		||||
///*** [  CHANGE_LOG  ] ***///
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,20 @@ namespace Light {
 | 
			
		|||
 | 
			
		||||
		m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr);
 | 
			
		||||
		m_Context->GetDeviceContext()->ClearRenderTargetView(m_RenderTargetView.Get(), color);
 | 
			
		||||
 | 
			
		||||
		D3D11_VIEWPORT viewport;
 | 
			
		||||
 | 
			
		||||
		viewport.TopLeftX = 0;
 | 
			
		||||
		viewport.TopLeftY = 0;
 | 
			
		||||
 | 
			
		||||
		viewport.Width = m_Specification.width;
 | 
			
		||||
		viewport.Height = m_Specification.height;
 | 
			
		||||
 | 
			
		||||
		viewport.MinDepth = 0.0f;
 | 
			
		||||
		viewport.MaxDepth = 1.0f;
 | 
			
		||||
 | 
			
		||||
		// set viewport
 | 
			
		||||
		m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxFramebuffer::BindAsResource()
 | 
			
		||||
| 
						 | 
				
			
			@ -56,14 +70,20 @@ namespace Light {
 | 
			
		|||
 | 
			
		||||
	void dxFramebuffer::Resize(const glm::vec2& size)
 | 
			
		||||
	{
 | 
			
		||||
		m_Specification.width = std::clamp(size.x, 1.0f, 16384.0f);  
 | 
			
		||||
		m_Specification.height= std::clamp(size.y, 1.0f, 16384.0f);  
 | 
			
		||||
 | 
			
		||||
		D3D11_TEXTURE2D_DESC textureDesc;
 | 
			
		||||
		D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
 | 
			
		||||
		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
 | 
			
		||||
		D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;	
 | 
			
		||||
 | 
			
		||||
		m_ColorAttachment->GetDesc(&textureDesc);
 | 
			
		||||
		m_RenderTargetView->GetDesc(&rtvDesc);
 | 
			
		||||
		m_ResourceView->GetDesc(&srvDesc);
 | 
			
		||||
 | 
			
		||||
		textureDesc.Width = m_Specification.width;
 | 
			
		||||
		textureDesc.Height = m_Specification.height;
 | 
			
		||||
 | 
			
		||||
		HRESULT hr;
 | 
			
		||||
		DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment));
 | 
			
		||||
		DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,18 +21,19 @@ namespace Light {
 | 
			
		|||
	{
 | 
			
		||||
		// set 'GraphicsAPI';
 | 
			
		||||
		m_GraphicsAPI = GraphicsAPI::DirectX;
 | 
			
		||||
		
 | 
			
		||||
		m_SharedContext = std::make_shared<dxSharedContext>();
 | 
			
		||||
 | 
			
		||||
		// setup stuff
 | 
			
		||||
		SetupDeviceAndSwapChain(windowHandle);
 | 
			
		||||
		SetupRenderTargets();
 | 
			
		||||
		SetupDebugInterface();
 | 
			
		||||
 | 
			
		||||
		// create 'dxSharedContext'
 | 
			
		||||
		m_SharedContext = std::make_shared<dxSharedContext>(m_Device, m_DeviceContext, m_SwapChain, m_RenderTargetView);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle)
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
 | 
			
		||||
 | 
			
		||||
		// swap chain desc
 | 
			
		||||
		DXGI_SWAP_CHAIN_DESC sd = { 0 };
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -77,61 +78,70 @@ namespace Light {
 | 
			
		|||
		                                  NULL,
 | 
			
		||||
		                                  D3D11_SDK_VERSION,
 | 
			
		||||
		                                  &sd, 
 | 
			
		||||
		                                  &m_SwapChain,
 | 
			
		||||
		                                  &m_Device,
 | 
			
		||||
		                                  &context->GetSwapChainRef(),
 | 
			
		||||
		                                  &context->GetDeviceRef(),
 | 
			
		||||
		                                  nullptr,
 | 
			
		||||
		                                  &m_DeviceContext));
 | 
			
		||||
		                                  &context->GetDeviceContextRef()));
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxGraphicsContext::SetupRenderTargets()
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
 | 
			
		||||
 | 
			
		||||
		// set primitive topology
 | 
			
		||||
		m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 | 
			
		||||
		context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 | 
			
		||||
 | 
			
		||||
		// create render target view 
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer;
 | 
			
		||||
 | 
			
		||||
		HRESULT hr;
 | 
			
		||||
		DXC(m_SwapChain->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
 | 
			
		||||
		DXC(m_Device->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_RenderTargetView));
 | 
			
		||||
		DXC(context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
 | 
			
		||||
		DXC(context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &context->GetRenderTargetViewRef()));
 | 
			
		||||
 | 
			
		||||
		// set render target view
 | 
			
		||||
		m_DeviceContext->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr);
 | 
			
		||||
		context->GetDeviceContext()->OMSetRenderTargets(1u, context->GetRenderTargetView().GetAddressOf(), nullptr);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxGraphicsContext::SetupDebugInterface()
 | 
			
		||||
	{
 | 
			
		||||
#ifdef LIGHT_DEBUG
 | 
			
		||||
		// configure the debug interface
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11InfoQueue> infoQueue;
 | 
			
		||||
		std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
 | 
			
		||||
 | 
			
		||||
		HRESULT hr;
 | 
			
		||||
		DXC(m_Device.As(&m_DebugInterface));
 | 
			
		||||
		DXC(m_DebugInterface.As(&infoQueue));
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
 | 
			
		||||
		DXC(context->GetDevice()->QueryInterface(__uuidof(ID3D11Debug), &debugInterface));
 | 
			
		||||
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11InfoQueue> infoQueue = nullptr;
 | 
			
		||||
		DXC(debugInterface->QueryInterface(__uuidof(ID3D11InfoQueue), &infoQueue));
 | 
			
		||||
 | 
			
		||||
		infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
 | 
			
		||||
		infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
 | 
			
		||||
 | 
			
		||||
		D3D11_MESSAGE_ID hide[] =
 | 
			
		||||
		{
 | 
			
		||||
			D3D11_MESSAGE_ID_DEVICE_DRAW_SAMPLER_NOT_SET,
 | 
			
		||||
 | 
			
		||||
			// #todo: add more message ids here as needed
 | 
			
		||||
			D3D11_MESSAGE_ID_UNKNOWN,
 | 
			
		||||
			// #todo: add more messages here as needed
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		D3D11_INFO_QUEUE_FILTER filter = { 0 };
 | 
			
		||||
		D3D11_INFO_QUEUE_FILTER filter = { };
 | 
			
		||||
		filter.DenyList.NumIDs = _countof(hide);
 | 
			
		||||
		filter.DenyList.pIDList = hide;
 | 
			
		||||
 | 
			
		||||
		DXC(infoQueue->AddStorageFilterEntries(&filter));
 | 
			
		||||
		infoQueue->AddStorageFilterEntries(&filter);
 | 
			
		||||
		infoQueue->Release();
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxGraphicsContext::LogDebugData()
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
 | 
			
		||||
 | 
			
		||||
		// locals 
 | 
			
		||||
		IDXGIDevice* DXGIDevice;
 | 
			
		||||
		IDXGIAdapter* DXGIAdapter;
 | 
			
		||||
		DXGI_ADAPTER_DESC DXGIAdapterDesc;
 | 
			
		||||
 | 
			
		||||
		m_Device->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice);
 | 
			
		||||
		context->GetDevice()->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice);
 | 
			
		||||
		DXGIDevice->GetAdapter(&DXGIAdapter);
 | 
			
		||||
		DXGIAdapter->GetDesc(&DXGIAdapterDesc);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,12 +14,6 @@ namespace Light {
 | 
			
		|||
	{
 | 
			
		||||
	private:
 | 
			
		||||
		GLFWwindow* m_WindowHandle;
 | 
			
		||||
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Device> m_Device;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_DeviceContext;
 | 
			
		||||
		Microsoft::WRL::ComPtr<IDXGISwapChain> m_SwapChain;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView;
 | 
			
		||||
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Debug> m_DebugInterface;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,6 +49,9 @@ namespace Light {
 | 
			
		|||
 | 
			
		||||
	void dxRenderCommand::SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
 | 
			
		||||
	{
 | 
			
		||||
		// #todo: maybe call this somewhere else??
 | 
			
		||||
		SetResolution(width, height);
 | 
			
		||||
 | 
			
		||||
		// create viewport
 | 
			
		||||
		D3D11_VIEWPORT viewport;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,4 +68,24 @@ namespace Light {
 | 
			
		|||
		m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void dxRenderCommand::SetResolution(unsigned int width, unsigned int height)
 | 
			
		||||
	{
 | 
			
		||||
		HRESULT hr;
 | 
			
		||||
 | 
			
		||||
		// remove render target
 | 
			
		||||
		ID3D11RenderTargetView* nullViews[] = { nullptr };
 | 
			
		||||
		m_Context->GetDeviceContext()->OMSetRenderTargets(1u, nullViews, nullptr);
 | 
			
		||||
		m_Context->GetRenderTargetViewRef().Reset();
 | 
			
		||||
 | 
			
		||||
		// resize buffer
 | 
			
		||||
		DXC(m_Context->GetSwapChain()->ResizeBuffers(0u, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, NULL));
 | 
			
		||||
 | 
			
		||||
		// create render target
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer = nullptr;
 | 
			
		||||
		DXC(m_Context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
 | 
			
		||||
		DXC(m_Context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_Context->GetRenderTargetViewRef()));
 | 
			
		||||
		// set render target
 | 
			
		||||
		m_Context->GetDeviceContext()->OMSetRenderTargets(1, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +27,9 @@ namespace Light {
 | 
			
		|||
		virtual void DefaultTargetFramebuffer() override;
 | 
			
		||||
 | 
			
		||||
		virtual void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) override;
 | 
			
		||||
 | 
			
		||||
	private:
 | 
			
		||||
		void SetResolution(unsigned int width, unsigned int height);
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -12,24 +12,21 @@ namespace Light {
 | 
			
		|||
	class dxSharedContext : public SharedContext
 | 
			
		||||
	{
 | 
			
		||||
	private:
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Device          > m_Device;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11DeviceContext   > m_DeviceContext;
 | 
			
		||||
		Microsoft::WRL::ComPtr<IDXGISwapChain        > m_SwapChain;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11Device          > m_Device           = nullptr;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11DeviceContext   > m_DeviceContext    = nullptr;
 | 
			
		||||
		Microsoft::WRL::ComPtr<IDXGISwapChain        > m_SwapChain        = nullptr;
 | 
			
		||||
		Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView = nullptr;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		dxSharedContext(Microsoft::WRL::ComPtr<ID3D11Device          > device,
 | 
			
		||||
		                Microsoft::WRL::ComPtr<ID3D11DeviceContext   > deviceContext,
 | 
			
		||||
		                Microsoft::WRL::ComPtr<IDXGISwapChain        > swapChain,
 | 
			
		||||
		                Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView)
 | 
			
		||||
			: m_Device(device), m_DeviceContext(deviceContext), m_SwapChain(swapChain), m_RenderTargetView(renderTargetView)
 | 
			
		||||
		{
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11Device          > GetDevice          () { return m_Device;           }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11DeviceContext   > GetDeviceContext   () { return m_DeviceContext;    }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<IDXGISwapChain        > GetSwapChain       () { return m_SwapChain;        }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> GetRenderTargetView() { return m_RenderTargetView; }
 | 
			
		||||
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11Device          >& GetDeviceRef          () { return m_Device;           }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11DeviceContext   >& GetDeviceContextRef   () { return m_DeviceContext;    }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<IDXGISwapChain        >& GetSwapChainRef       () { return m_SwapChain;        }
 | 
			
		||||
		inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView>& GetRenderTargetViewRef() { return m_RenderTargetView; }
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue