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:
Light 2021-07-22 13:00:41 +04:30
parent aac2c51bd5
commit 5cc82f1558
7 changed files with 104 additions and 47 deletions

View file

@ -11,10 +11,10 @@
// version // version
#define LT_VERSION "0.7.4" #define LT_VERSION "0.7.5b"
///*** [ CHANGE_LOG ] ***/// ///*** [ 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: // I came up with that version because of:
// projects: 'Engine', 'Sandbox', 'Mirror' [+0.3] // projects: 'Engine', 'Sandbox', 'Mirror' [+0.3]
// graphics apis: 'OpenGL', 'DirectX11' [+0.2] // 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 // - 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' // - Separated 'FailedAssertion' into 'FailedEngineAssertion' and 'FailedClientAssertion'
// - Minor adjustment to the change log // - 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 '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' // - 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" // - 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 'Input'
// - - Added <InputCodes> // - - Added <InputCodes>
// - The 'MirrorLayer''s ImGuiWindow, "GameView" will not receive/react to input events if the window is not focused // - 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 ] ***/// ///*** [ CHANGE_LOG ] ***///

View file

@ -47,6 +47,20 @@ namespace Light {
m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr); m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr);
m_Context->GetDeviceContext()->ClearRenderTargetView(m_RenderTargetView.Get(), color); 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() void dxFramebuffer::BindAsResource()
@ -56,14 +70,20 @@ namespace Light {
void dxFramebuffer::Resize(const glm::vec2& size) 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_TEXTURE2D_DESC textureDesc;
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
m_ColorAttachment->GetDesc(&textureDesc); m_ColorAttachment->GetDesc(&textureDesc);
m_RenderTargetView->GetDesc(&rtvDesc); m_RenderTargetView->GetDesc(&rtvDesc);
m_ResourceView->GetDesc(&srvDesc); m_ResourceView->GetDesc(&srvDesc);
textureDesc.Width = m_Specification.width;
textureDesc.Height = m_Specification.height;
HRESULT hr; HRESULT hr;
DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment)); DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment));
DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView)); DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView));

View file

@ -21,18 +21,19 @@ namespace Light {
{ {
// set 'GraphicsAPI'; // set 'GraphicsAPI';
m_GraphicsAPI = GraphicsAPI::DirectX; m_GraphicsAPI = GraphicsAPI::DirectX;
m_SharedContext = std::make_shared<dxSharedContext>();
// setup stuff // setup stuff
SetupDeviceAndSwapChain(windowHandle); SetupDeviceAndSwapChain(windowHandle);
SetupRenderTargets(); SetupRenderTargets();
SetupDebugInterface(); SetupDebugInterface();
// create 'dxSharedContext'
m_SharedContext = std::make_shared<dxSharedContext>(m_Device, m_DeviceContext, m_SwapChain, m_RenderTargetView);
} }
void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle) void dxGraphicsContext::SetupDeviceAndSwapChain(GLFWwindow* windowHandle)
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// swap chain desc // swap chain desc
DXGI_SWAP_CHAIN_DESC sd = { 0 }; DXGI_SWAP_CHAIN_DESC sd = { 0 };
@ -77,61 +78,70 @@ namespace Light {
NULL, NULL,
D3D11_SDK_VERSION, D3D11_SDK_VERSION,
&sd, &sd,
&m_SwapChain, &context->GetSwapChainRef(),
&m_Device, &context->GetDeviceRef(),
nullptr, nullptr,
&m_DeviceContext)); &context->GetDeviceContextRef()));
} }
void dxGraphicsContext::SetupRenderTargets() void dxGraphicsContext::SetupRenderTargets()
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// set primitive topology // set primitive topology
m_DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->GetDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// create render target view // create render target view
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer; Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer;
HRESULT hr; HRESULT hr;
DXC(m_SwapChain->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer)); DXC(context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
DXC(m_Device->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_RenderTargetView)); DXC(context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &context->GetRenderTargetViewRef()));
// set render target view // set render target view
m_DeviceContext->OMSetRenderTargets(1u, m_RenderTargetView.GetAddressOf(), nullptr); context->GetDeviceContext()->OMSetRenderTargets(1u, context->GetRenderTargetView().GetAddressOf(), nullptr);
} }
void dxGraphicsContext::SetupDebugInterface() void dxGraphicsContext::SetupDebugInterface()
{ {
#ifdef LIGHT_DEBUG #ifdef LIGHT_DEBUG
// configure the debug interface std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
Microsoft::WRL::ComPtr<ID3D11InfoQueue> infoQueue;
HRESULT hr; HRESULT hr;
DXC(m_Device.As(&m_DebugInterface)); Microsoft::WRL::ComPtr<ID3D11Debug> debugInterface = nullptr;
DXC(m_DebugInterface.As(&infoQueue)); 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 hide[] =
{ {
D3D11_MESSAGE_ID_DEVICE_DRAW_SAMPLER_NOT_SET, D3D11_MESSAGE_ID_UNKNOWN,
// #todo: add more messages here as needed
// #todo: add more message ids here as needed
}; };
D3D11_INFO_QUEUE_FILTER filter = { 0 }; D3D11_INFO_QUEUE_FILTER filter = { };
filter.DenyList.NumIDs = _countof(hide); filter.DenyList.NumIDs = _countof(hide);
filter.DenyList.pIDList = hide; filter.DenyList.pIDList = hide;
infoQueue->AddStorageFilterEntries(&filter);
DXC(infoQueue->AddStorageFilterEntries(&filter)); infoQueue->Release();
#endif #endif
} }
void dxGraphicsContext::LogDebugData() void dxGraphicsContext::LogDebugData()
{ {
std::shared_ptr<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_SharedContext);
// locals // locals
IDXGIDevice* DXGIDevice; IDXGIDevice* DXGIDevice;
IDXGIAdapter* DXGIAdapter; IDXGIAdapter* DXGIAdapter;
DXGI_ADAPTER_DESC DXGIAdapterDesc; DXGI_ADAPTER_DESC DXGIAdapterDesc;
m_Device->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice); context->GetDevice()->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice);
DXGIDevice->GetAdapter(&DXGIAdapter); DXGIDevice->GetAdapter(&DXGIAdapter);
DXGIAdapter->GetDesc(&DXGIAdapterDesc); DXGIAdapter->GetDesc(&DXGIAdapterDesc);

View file

@ -14,12 +14,6 @@ namespace Light {
{ {
private: private:
GLFWwindow* m_WindowHandle; 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; Microsoft::WRL::ComPtr<ID3D11Debug> m_DebugInterface;
public: public:

View file

@ -49,6 +49,9 @@ namespace Light {
void dxRenderCommand::SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) 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 // create viewport
D3D11_VIEWPORT viewport; D3D11_VIEWPORT viewport;
@ -65,4 +68,24 @@ namespace Light {
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport); 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);
}
} }

View file

@ -27,6 +27,9 @@ namespace Light {
virtual void DefaultTargetFramebuffer() override; virtual void DefaultTargetFramebuffer() override;
virtual void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) 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);
}; };
} }

View file

@ -12,24 +12,21 @@ namespace Light {
class dxSharedContext : public SharedContext class dxSharedContext : public SharedContext
{ {
private: private:
Microsoft::WRL::ComPtr<ID3D11Device > m_Device; Microsoft::WRL::ComPtr<ID3D11Device > m_Device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext > m_DeviceContext; Microsoft::WRL::ComPtr<ID3D11DeviceContext > m_DeviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain > m_SwapChain; Microsoft::WRL::ComPtr<IDXGISwapChain > m_SwapChain = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView; Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView = nullptr;
public: 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<ID3D11Device > GetDevice () { return m_Device; }
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext > GetDeviceContext () { return m_DeviceContext; } inline Microsoft::WRL::ComPtr<ID3D11DeviceContext > GetDeviceContext () { return m_DeviceContext; }
inline Microsoft::WRL::ComPtr<IDXGISwapChain > GetSwapChain () { return m_SwapChain; } inline Microsoft::WRL::ComPtr<IDXGISwapChain > GetSwapChain () { return m_SwapChain; }
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> GetRenderTargetView() { return m_RenderTargetView; } 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; }
}; };
} }