2021-06-02 09:07:45 +04:30
|
|
|
#include "ltpch.h"
|
|
|
|
#include "dxRenderCommand.h"
|
|
|
|
#include "dxSharedContext.h"
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
2021-06-19 15:12:42 +04:30
|
|
|
dxRenderCommand::dxRenderCommand(std::shared_ptr<dxSharedContext> sharedContext)
|
|
|
|
: m_Context(sharedContext)
|
2021-07-01 19:25:46 +04:30
|
|
|
{ }
|
2021-06-02 09:07:45 +04:30
|
|
|
|
|
|
|
void dxRenderCommand::SwapBuffers()
|
|
|
|
{
|
2021-06-21 17:04:51 +04:30
|
|
|
#ifdef LIGHT_DEBUG
|
|
|
|
HRESULT hr;
|
2021-07-01 19:25:46 +04:30
|
|
|
if (FAILED(hr = m_Context->GetSwapChain()->Present(0u, 0u)))
|
2021-06-21 17:04:51 +04:30
|
|
|
{
|
|
|
|
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
|
|
|
{
|
|
|
|
LT_ENGINE_CRITICAL("dxRenderCommand::SwapBuffers: DeviceRemoved:");
|
2021-07-01 19:25:46 +04:30
|
|
|
LT_ENGINE_CRITICAL(" {}", m_Context->GetDevice()->GetDeviceRemovedReason());
|
|
|
|
throw dxException(hr, __FILE__, __LINE__);
|
2021-06-21 17:04:51 +04:30
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2021-07-01 19:25:46 +04:30
|
|
|
m_Context->GetSwapChain()->Present(0u, 0u);
|
2021-06-21 17:04:51 +04:30
|
|
|
#endif
|
2021-06-02 09:07:45 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
void dxRenderCommand::ClearBackBuffer()
|
|
|
|
{
|
2021-07-15 15:46:28 +04:30
|
|
|
float colors[] = { 0.1, 0.35f, 0.46f, 1.0f }; // #todo: use a local variable for this
|
2021-07-01 19:25:46 +04:30
|
|
|
m_Context->GetDeviceContext()->ClearRenderTargetView(m_Context->GetRenderTargetView().Get(), colors);
|
2021-06-02 09:07:45 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
void dxRenderCommand::Draw(unsigned int count)
|
|
|
|
{
|
2021-07-01 19:25:46 +04:30
|
|
|
m_Context->GetDeviceContext()->Draw(count, 0u);
|
2021-06-02 09:07:45 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
void dxRenderCommand::DrawIndexed(unsigned int count)
|
|
|
|
{
|
2021-07-01 19:25:46 +04:30
|
|
|
m_Context->GetDeviceContext()->DrawIndexed(count, 0u, 0u);
|
2021-06-02 09:07:45 +04:30
|
|
|
}
|
|
|
|
|
2021-07-15 15:46:28 +04:30
|
|
|
void dxRenderCommand::DefaultTargetFramebuffer()
|
|
|
|
{
|
|
|
|
m_Context->GetDeviceContext()->OMSetRenderTargets(1, m_Context->GetRenderTargetView().GetAddressOf(), nullptr);
|
|
|
|
}
|
|
|
|
|
2021-07-14 00:17:30 +04:30
|
|
|
void dxRenderCommand::SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
|
|
|
|
{
|
2021-07-22 13:00:41 +04:30
|
|
|
// #todo: maybe call this somewhere else??
|
|
|
|
SetResolution(width, height);
|
|
|
|
|
2021-07-14 00:17:30 +04:30
|
|
|
// create viewport
|
|
|
|
D3D11_VIEWPORT viewport;
|
|
|
|
|
|
|
|
viewport.TopLeftX = x;
|
|
|
|
viewport.TopLeftY = y;
|
|
|
|
|
|
|
|
viewport.Width = width;
|
|
|
|
viewport.Height = height;
|
|
|
|
|
|
|
|
viewport.MinDepth = 0.0f;
|
|
|
|
viewport.MaxDepth = 1.0f;
|
|
|
|
|
|
|
|
// set viewport
|
|
|
|
m_Context->GetDeviceContext()->RSSetViewports(1u, &viewport);
|
|
|
|
}
|
|
|
|
|
2021-07-22 13:00:41 +04:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-06-02 09:07:45 +04:30
|
|
|
}
|