1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/adapter-dx.cpp

153 lines
3.7 KiB
C++
Raw Normal View History

2024-03-18 15:41:46 -03:00
#include "adapter-dx.hpp"
#include "../helpers.hpp"
namespace xna {
2024-04-01 16:18:18 -03:00
PGraphicsAdapter GraphicsAdapter::DefaultAdapter() {
if (_adaptersList.empty())
return nullptr;
if (_defaultAdapterIndex >= _adaptersList.size())
return nullptr;
return _adaptersList[_defaultAdapterIndex];
}
2024-03-18 15:41:46 -03:00
String GraphicsAdapter::Description() const {
DXGI_ADAPTER_DESC1 desc;
2024-03-21 16:01:47 -03:00
_adapter->GetDesc1(&desc);
2024-03-18 15:41:46 -03:00
String description = WStringToString(desc.Description);
return description;
}
Uint GraphicsAdapter::DeviceId() const {
DXGI_ADAPTER_DESC1 desc;
2024-03-21 16:01:47 -03:00
_adapter->GetDesc1(&desc);
2024-03-18 15:41:46 -03:00
return static_cast<Uint>(desc.DeviceId);
}
String GraphicsAdapter::DeviceName() const {
IDXGIOutput* pOutput = nullptr;
DXGI_OUTPUT_DESC outputDesc;
2024-03-21 16:01:47 -03:00
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
2024-03-18 15:41:46 -03:00
pOutput->GetDesc(&outputDesc);
String deviceName = WStringToString(outputDesc.DeviceName);
pOutput->Release();
pOutput = nullptr;
return deviceName;
}
return String();
}
intptr_t GraphicsAdapter::MonitorHandle() const {
IDXGIOutput* pOutput = nullptr;
DXGI_OUTPUT_DESC outputDesc;
2024-03-21 16:01:47 -03:00
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
2024-03-18 15:41:46 -03:00
pOutput->GetDesc(&outputDesc);
pOutput->Release();
pOutput = nullptr;
return reinterpret_cast<intptr_t>(outputDesc.Monitor);
}
return 0;
}
Uint GraphicsAdapter::Revision() const {
DXGI_ADAPTER_DESC1 desc;
2024-03-21 16:01:47 -03:00
_adapter->GetDesc1(&desc);
2024-03-18 15:41:46 -03:00
return static_cast<Uint>(desc.Revision);
}
Uint GraphicsAdapter::SubSystemId() const {
DXGI_ADAPTER_DESC1 desc;
2024-03-21 16:01:47 -03:00
_adapter->GetDesc1(&desc);
2024-03-18 15:41:46 -03:00
return static_cast<Uint>(desc.SubSysId);
}
Uint GraphicsAdapter::VendorId() const {
DXGI_ADAPTER_DESC1 desc;
2024-03-21 16:01:47 -03:00
_adapter->GetDesc1(&desc);
2024-03-18 15:41:46 -03:00
return static_cast<Uint>(desc.VendorId);
}
PDisplayModeCollection GraphicsAdapter::SupportedDisplayModes() const {
IDXGIOutput* pOutput = nullptr;
UINT numModes = 0;
UINT totalModes = 0;
2024-03-24 16:12:17 -03:00
std::vector<DXGI_MODE_DESC> buffer(500);
2024-03-18 15:41:46 -03:00
2024-03-21 16:01:47 -03:00
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
2024-03-18 15:41:46 -03:00
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
const auto currentSurface = static_cast<SurfaceFormat>(f);
DXGI_FORMAT format = SurfaceFormatMapper::ParseToDXGI(currentSurface);
pOutput->GetDisplayModeList(format, 0, &numModes, nullptr);
if (numModes == 0)
continue;
2024-03-21 16:01:47 -03:00
if (buffer.size() < static_cast<size_t>(totalModes) + numModes)
buffer.resize(static_cast<size_t>(totalModes * 2));
2024-03-18 15:41:46 -03:00
pOutput->GetDisplayModeList(format, 0, &numModes, buffer.data() + totalModes);
totalModes += numModes;
}
2024-03-24 16:12:17 -03:00
pOutput->Release();
auto collection = New<DisplayModeCollection>(totalModes);
2024-03-18 15:41:46 -03:00
2024-03-24 16:12:17 -03:00
for (size_t i = 0; i < totalModes; ++i) {
2024-03-18 15:41:46 -03:00
const auto& modedesc = buffer[i];
const auto surface = SurfaceFormatMapper::ParseToSurface(modedesc.Format);
2024-03-24 16:12:17 -03:00
collection->_displayModes[i] = DisplayMode(modedesc.Width, modedesc.Height, surface);
2024-03-18 15:41:46 -03:00
}
2024-03-24 16:12:17 -03:00
return collection;
2024-03-18 15:41:46 -03:00
}
return New<DisplayModeCollection>();
}
2024-04-01 16:18:18 -03:00
std::vector<PGraphicsAdapter> GraphicsAdapter::getAllAdapters() {
2024-03-24 16:12:17 -03:00
IDXGIFactory1* pFactory = nullptr;
2024-03-18 15:41:46 -03:00
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) {
2024-03-24 16:12:17 -03:00
return std::vector<PGraphicsAdapter>();
2024-03-18 15:41:46 -03:00
}
2024-03-24 16:12:17 -03:00
std::vector<PGraphicsAdapter> adapters(2);
2024-03-18 15:41:46 -03:00
IDXGIAdapter1* pAdapter = nullptr;
UINT count = 0;
for (; pFactory->EnumAdapters1(count, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++count) {
auto adp = New<GraphicsAdapter>();
2024-03-21 16:01:47 -03:00
adp->_index = count;
adp->_adapter = pAdapter;
2024-03-18 15:41:46 -03:00
2024-03-24 16:12:17 -03:00
if (adapters.size() == count)
adapters.push_back(adp);
else
adapters[count] = adp;
2024-03-18 15:41:46 -03:00
}
2024-03-24 16:12:17 -03:00
if (!adapters.empty() && adapters.size() != count)
2024-03-18 15:41:46 -03:00
adapters.resize(count);
return adapters;
}
}