update GetDisplaySettings function
This commit is contained in:
parent
2ff0d1ad95
commit
3fd3fbbbd8
|
|
@ -105,11 +105,13 @@ public:
|
|||
Size logical_size_;
|
||||
Size output_size_;
|
||||
unsigned long ref_count_;
|
||||
DXGI_FORMAT desired_color_format_;
|
||||
};
|
||||
|
||||
D3D10DeviceResources::D3D10DeviceResources()
|
||||
: ref_count_(0)
|
||||
, hwnd_(nullptr)
|
||||
, desired_color_format_(DXGI_FORMAT_B8G8R8A8_UNORM)
|
||||
{
|
||||
dpi_ = 96.f; // dpi_ = (float)GetDpiForWindow(hwnd);
|
||||
}
|
||||
|
|
@ -255,7 +257,7 @@ HRESULT D3D10DeviceResources::CreateDeviceResources()
|
|||
swap_chain_desc.BufferCount = 2;
|
||||
swap_chain_desc.BufferDesc.Width = ::lround(output_size_.x);
|
||||
swap_chain_desc.BufferDesc.Height = ::lround(output_size_.y);
|
||||
swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
swap_chain_desc.BufferDesc.Format = desired_color_format_;
|
||||
swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
|
||||
swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
|
||||
swap_chain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
|
||||
|
|
@ -308,7 +310,7 @@ HRESULT D3D10DeviceResources::CreateWindowSizeDependentResources()
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
D3D10_RENDER_TARGET_VIEW_DESC renderDesc;
|
||||
renderDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
renderDesc.Format = desired_color_format_;
|
||||
renderDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
|
||||
renderDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
|
|
@ -430,42 +432,36 @@ HRESULT D3D10DeviceResources::ResizeTarget(UINT width, UINT height)
|
|||
|
||||
HRESULT D3D10DeviceResources::GetDisplaySettings(DXGI_MODE_DESC** mode_descs, int* num)
|
||||
{
|
||||
ComPtr<IDXGIAdapter> dxgi_adapter;
|
||||
KGE_ASSERT(dxgi_swap_chain_);
|
||||
|
||||
ComPtr<IDXGIOutput> output;
|
||||
HRESULT hr = dxgi_swap_chain_->GetContainingOutput(&output);
|
||||
|
||||
HRESULT hr = dxgi_device_->GetAdapter(&dxgi_adapter);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ComPtr<IDXGIOutput> output;
|
||||
hr = dxgi_adapter->EnumOutputs(0, &output);
|
||||
UINT num_of_supported_modes = 0;
|
||||
output->GetDisplayModeList(desired_color_format_, 0, &num_of_supported_modes, 0);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
if (num_of_supported_modes > 0)
|
||||
{
|
||||
UINT modes_num = 0;
|
||||
DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
UINT flags = DXGI_ENUM_MODES_INTERLACED;
|
||||
DXGI_MODE_DESC* supported_modes = new DXGI_MODE_DESC[num_of_supported_modes];
|
||||
ZeroMemory(supported_modes, sizeof(DXGI_MODE_DESC) * num_of_supported_modes);
|
||||
|
||||
output->GetDisplayModeList(format, flags, &modes_num, 0);
|
||||
|
||||
if (modes_num > 0)
|
||||
hr = output->GetDisplayModeList(desired_color_format_, 0, &num_of_supported_modes, supported_modes);
|
||||
if (SUCCEEDED(hr) && mode_descs && num)
|
||||
{
|
||||
DXGI_MODE_DESC* temp = new DXGI_MODE_DESC[modes_num];
|
||||
|
||||
hr = output->GetDisplayModeList(format, flags, &modes_num, temp);
|
||||
if (SUCCEEDED(hr) && mode_descs && num)
|
||||
{
|
||||
(*mode_descs) = temp;
|
||||
(*num) = (int)modes_num;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete[] temp;
|
||||
}
|
||||
(*mode_descs) = supported_modes;
|
||||
(*num) = (int)num_of_supported_modes;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = E_FAIL;
|
||||
delete[] supported_modes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = E_FAIL;
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/render/DirectX/D3D11DeviceResources.h>
|
||||
#include <memory>
|
||||
|
||||
KGE_SUPPRESS_WARNING_PUSH
|
||||
KGE_SUPPRESS_WARNING(4800) // Implicit conversion from 'type' to bool
|
||||
|
|
@ -96,12 +97,14 @@ public:
|
|||
unsigned long ref_count_;
|
||||
|
||||
D3D_FEATURE_LEVEL d3d_feature_level_;
|
||||
DXGI_FORMAT desired_color_format_;
|
||||
};
|
||||
|
||||
D3D11DeviceResources::D3D11DeviceResources()
|
||||
: ref_count_(0)
|
||||
, hwnd_(nullptr)
|
||||
, d3d_feature_level_(D3D_FEATURE_LEVEL_9_1)
|
||||
, desired_color_format_(DXGI_FORMAT_B8G8R8A8_UNORM)
|
||||
{
|
||||
dpi_ = 96.f; // dpi_ = (float)GetDpiForWindow(hwnd);
|
||||
}
|
||||
|
|
@ -277,7 +280,7 @@ HRESULT D3D11DeviceResources::CreateDeviceResources()
|
|||
swap_chain_desc.BufferCount = 2;
|
||||
swap_chain_desc.BufferDesc.Width = ::lround(output_size_.x);
|
||||
swap_chain_desc.BufferDesc.Height = ::lround(output_size_.y);
|
||||
swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
swap_chain_desc.BufferDesc.Format = desired_color_format_;
|
||||
swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
|
||||
swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
|
||||
swap_chain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
|
||||
|
|
@ -450,42 +453,36 @@ HRESULT D3D11DeviceResources::ResizeTarget(UINT width, UINT height)
|
|||
|
||||
HRESULT D3D11DeviceResources::GetDisplaySettings(DXGI_MODE_DESC** mode_descs, int* num)
|
||||
{
|
||||
ComPtr<IDXGIAdapter> dxgi_adapter;
|
||||
KGE_ASSERT(dxgi_swap_chain_);
|
||||
|
||||
ComPtr<IDXGIOutput> output;
|
||||
HRESULT hr = dxgi_swap_chain_->GetContainingOutput(&output);
|
||||
|
||||
HRESULT hr = dxgi_device_->GetAdapter(&dxgi_adapter);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ComPtr<IDXGIOutput> output;
|
||||
hr = dxgi_adapter->EnumOutputs(0, &output);
|
||||
UINT num_of_supported_modes = 0;
|
||||
output->GetDisplayModeList(desired_color_format_, 0, &num_of_supported_modes, 0);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
if (num_of_supported_modes > 0)
|
||||
{
|
||||
UINT modes_num = 0;
|
||||
DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
UINT flags = DXGI_ENUM_MODES_INTERLACED;
|
||||
DXGI_MODE_DESC* supported_modes = new DXGI_MODE_DESC[num_of_supported_modes];
|
||||
ZeroMemory(supported_modes, sizeof(DXGI_MODE_DESC) * num_of_supported_modes);
|
||||
|
||||
output->GetDisplayModeList(format, flags, &modes_num, 0);
|
||||
|
||||
if (modes_num > 0)
|
||||
hr = output->GetDisplayModeList(desired_color_format_, 0, &num_of_supported_modes, supported_modes);
|
||||
if (SUCCEEDED(hr) && mode_descs && num)
|
||||
{
|
||||
DXGI_MODE_DESC* temp = new DXGI_MODE_DESC[modes_num];
|
||||
|
||||
hr = output->GetDisplayModeList(format, flags, &modes_num, temp);
|
||||
if (SUCCEEDED(hr) && mode_descs && num)
|
||||
{
|
||||
(*mode_descs) = temp;
|
||||
(*num) = (int)modes_num;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete[] temp;
|
||||
}
|
||||
(*mode_descs) = supported_modes;
|
||||
(*num) = (int)num_of_supported_modes;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = E_FAIL;
|
||||
delete[] supported_modes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = E_FAIL;
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue