update D3DDeviceResources API

minor
This commit is contained in:
Nomango 2019-07-29 09:40:39 +08:00
parent ef4b0d85e6
commit 080cd5523b
7 changed files with 80 additions and 36 deletions

View File

@ -227,12 +227,12 @@ namespace kiwano
if (show) if (show)
{ {
debug_node_ = new DebugNode; debug_node_ = new DebugNode;
Renderer::Instance().StartCollectData(); Renderer::Instance().SetCollectingStatus(true);
} }
else else
{ {
debug_node_.Reset(); debug_node_.Reset();
Renderer::Instance().StopCollectData(); Renderer::Instance().SetCollectingStatus(false);
} }
} }

View File

@ -29,7 +29,7 @@
namespace kiwano namespace kiwano
{ {
#if defined(_DEBUG)
namespace DX namespace DX
{ {
HRESULT CreateD3DDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, UINT flags, ID3D10Device1 **device) HRESULT CreateD3DDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, UINT flags, ID3D10Device1 **device)
@ -63,6 +63,7 @@ namespace kiwano
return hr; return hr;
} }
#if defined(KGE_DEBUG)
inline bool SdkLayersAvailable() inline bool SdkLayersAvailable()
{ {
HRESULT hr = CreateD3DDevice( HRESULT hr = CreateD3DDevice(
@ -74,9 +75,11 @@ namespace kiwano
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
}
#endif #endif
} // namespace DX
D3D10DeviceResources::D3D10DeviceResources() D3D10DeviceResources::D3D10DeviceResources()
: hwnd_(nullptr) : hwnd_(nullptr)
{ {
@ -133,6 +136,26 @@ namespace kiwano
return hr; return hr;
} }
HRESULT D3D10DeviceResources::Present(bool vsync)
{
// The first argument instructs DXGI to block until VSync.
return dxgi_swap_chain_->Present(vsync ? 1 : 0, 0);
}
HRESULT D3D10DeviceResources::ClearRenderTarget(Color& clear_color)
{
d3d_device_->OMSetRenderTargets(
1,
&d3d_rt_view_,
d3d_ds_view_.Get()
);
d3d_device_->ClearRenderTargetView(
d3d_rt_view_.Get(),
reinterpret_cast<float*>(&clear_color)
);
return S_OK;
}
void D3D10DeviceResources::DiscardResources() void D3D10DeviceResources::DiscardResources()
{ {
d3d_device_.Reset(); d3d_device_.Reset();

View File

@ -38,6 +38,14 @@ namespace kiwano
HWND hwnd HWND hwnd
); );
HRESULT Present(
bool vsync
);
HRESULT ClearRenderTarget(
Color& clear_color
);
HRESULT HandleDeviceLost(); HRESULT HandleDeviceLost();
HRESULT SetLogicalSize( HRESULT SetLogicalSize(

View File

@ -29,7 +29,7 @@
namespace kiwano namespace kiwano
{ {
#if defined(_DEBUG) #if defined(KGE_DEBUG)
namespace DX namespace DX
{ {
inline bool SdkLayersAvailable() inline bool SdkLayersAvailable()
@ -109,6 +109,26 @@ namespace kiwano
return hr; return hr;
} }
HRESULT D3D11DeviceResources::Present(bool vsync)
{
// The first argument instructs DXGI to block until VSync.
return dxgi_swap_chain_->Present(vsync ? 1 : 0, 0);
}
HRESULT D3D11DeviceResources::ClearRenderTarget(Color& clear_color)
{
d3d_device_context_->OMSetRenderTargets(
1,
&d3d_rt_view_,
d3d_ds_view_.Get()
);
d3d_device_context_->ClearRenderTargetView(
d3d_rt_view_.Get(),
reinterpret_cast<float*>(&clear_color)
);
return S_OK;
}
void D3D11DeviceResources::DiscardResources() void D3D11DeviceResources::DiscardResources()
{ {
d3d_device_.Reset(); d3d_device_.Reset();

View File

@ -38,6 +38,14 @@ namespace kiwano
HWND hwnd HWND hwnd
); );
HRESULT Present(
bool vsync
);
HRESULT ClearRenderTarget(
Color& clear_color
);
HRESULT HandleDeviceLost(); HRESULT HandleDeviceLost();
HRESULT SetLogicalSize( HRESULT SetLogicalSize(

View File

@ -32,7 +32,7 @@ namespace kiwano
, text_antialias_(TextAntialias::ClearType) , text_antialias_(TextAntialias::ClearType)
, clear_color_(Color::Black) , clear_color_(Color::Black)
, opacity_(1.f) , opacity_(1.f)
, collecting_data_(false) , collecting_status_(false)
{ {
status_.primitives = 0; status_.primitives = 0;
} }
@ -128,7 +128,7 @@ namespace kiwano
if (!device_context_) if (!device_context_)
return E_UNEXPECTED; return E_UNEXPECTED;
if (collecting_data_) if (collecting_status_)
{ {
status_.start = Time::Now(); status_.start = Time::Now();
status_.primitives = 0; status_.primitives = 0;
@ -151,20 +151,12 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// The first argument instructs DXGI to block until VSync. hr = device_resources_->Present(vsync_);
hr = device_resources_->GetDXGISwapChain()->Present(vsync_ ? 1 : 0, 0); }
auto main_rt_view = device_resources_->GetD3DRenderTargetView(); if (SUCCEEDED(hr))
device_resources_->GetD3DDeviceContext()->OMSetRenderTargets( {
1, hr = device_resources_->ClearRenderTarget(clear_color_);
&main_rt_view,
device_resources_->GetD3DDepthStencilView()
);
device_resources_->GetD3DDeviceContext()->ClearRenderTargetView(
main_rt_view,
reinterpret_cast<float*>(&clear_color_)
);
} }
if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
@ -173,7 +165,7 @@ namespace kiwano
hr = HandleDeviceLost(); hr = HandleDeviceLost();
} }
if (collecting_data_) if (collecting_status_)
{ {
status_.duration = Time::Now() - status_.start; status_.duration = Time::Now() - status_.start;
} }
@ -208,7 +200,7 @@ namespace kiwano
device_resources_->GetStrokeStyle(stroke) device_resources_->GetStrokeStyle(stroke)
); );
if (collecting_data_) if (collecting_status_)
++status_.primitives; ++status_.primitives;
return S_OK; return S_OK;
} }
@ -243,7 +235,7 @@ namespace kiwano
DX::ConvertToRectF(image->GetCropRect()) DX::ConvertToRectF(image->GetCropRect())
); );
if (collecting_data_) if (collecting_status_)
++status_.primitives; ++status_.primitives;
return S_OK; return S_OK;
} }
@ -265,7 +257,7 @@ namespace kiwano
DX::ConvertToRectF(src_rect) DX::ConvertToRectF(src_rect)
); );
if (collecting_data_) if (collecting_status_)
++status_.primitives; ++status_.primitives;
return S_OK; return S_OK;
} }
@ -275,7 +267,7 @@ namespace kiwano
if (!text_renderer_) if (!text_renderer_)
return E_UNEXPECTED; return E_UNEXPECTED;
if (collecting_data_) if (collecting_status_)
++status_.primitives; ++status_.primitives;
return text_layout->Draw(nullptr, text_renderer_.Get(), 0, 0); return text_layout->Draw(nullptr, text_renderer_.Get(), 0, 0);
} }
@ -347,14 +339,9 @@ namespace kiwano
return S_OK; return S_OK;
} }
void Renderer::StartCollectData() void Renderer::SetCollectingStatus(bool collecting)
{ {
collecting_data_ = true; collecting_status_ = collecting;
}
void Renderer::StopCollectData()
{
collecting_data_ = false;
} }
void Renderer::SetClearColor(const Color & color) void Renderer::SetClearColor(const Color & color)

View File

@ -141,9 +141,7 @@ namespace kiwano
void DestroyComponent() override; void DestroyComponent() override;
void StartCollectData(); void SetCollectingStatus(bool collecting);
void StopCollectData();
inline HWND GetTargetWindow() const { return hwnd_; } inline HWND GetTargetWindow() const { return hwnd_; }
@ -173,7 +171,7 @@ namespace kiwano
float opacity_; float opacity_;
bool antialias_; bool antialias_;
bool vsync_; bool vsync_;
bool collecting_data_; bool collecting_status_;
Size output_size_; Size output_size_;
Color clear_color_; Color clear_color_;