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

Correções em Adapter

This commit is contained in:
Danilo 2024-07-19 22:11:57 -03:00
parent 64497afdf3
commit 6e10a3a669
4 changed files with 200 additions and 147 deletions

View File

@ -4,8 +4,17 @@
#include "xna/xna-dx.hpp"
namespace xna {
static String getDescription(comptr<IDXGIAdapter1> const& adapter);
static Uint getDeviceId(comptr<IDXGIAdapter1> const& adapter);
static String getDeviceName(comptr<IDXGIAdapter1> const& adapter);
static intptr_t getMonitorHandle(comptr<IDXGIAdapter1> const& adapter);
static Uint getRevision(comptr<IDXGIAdapter1> const& adapter);
static Uint getRevision(comptr<IDXGIAdapter1> const& adapter);
static Uint getSubSystemId(comptr<IDXGIAdapter1> const& adapter);
static Uint getVendorId(comptr<IDXGIAdapter1> const& adapter);
static size_t getDisplayModesCount(IDXGIAdapter* adapter);
static uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source);
static uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source);
static void setCurrentDisplayMode(GraphicsAdapter& adapter, SurfaceFormat surfaceFormat, Uint width, Uint height, sptr<DisplayMode>& currentDisplayMode);
GraphicsAdapter::GraphicsAdapter() {
impl = unew<PlatformImplementation>();
@ -21,10 +30,18 @@ namespace xna {
if (pFactory->EnumAdapters1(0, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
auto adp = unew<GraphicsAdapter>();
adp->impl->_index = 0;
adp->impl->dxAdapter = pAdapter;
adp->impl->dxFactory = pFactory;
adp->impl->dxFactory = pFactory;
adp->description = getDescription(pAdapter);
adp->deviceId = getDeviceId(pAdapter);
adp->deviceName = getDeviceName(pAdapter);
adp->isDefault = true;
adp->monitorHandle = getMonitorHandle(pAdapter);
adp->revision = getRevision(pAdapter);
adp->subSystemId = getSubSystemId(pAdapter);
adp->vendorId = getVendorId(pAdapter);
return adp;
}
@ -43,90 +60,21 @@ namespace xna {
for (UINT count = 0; pFactory->EnumAdapters1(count, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND; ++count) {
auto adp = unew<GraphicsAdapter>();
adp->impl->_index = count;
adp->impl->dxAdapter = pAdapter;
adp->impl->dxFactory = pFactory;
adp->description = getDescription(pAdapter);
adp->deviceId = getDeviceId(pAdapter);
adp->deviceName = getDeviceName(pAdapter);
adp->isDefault = count == 0;
adp->monitorHandle = getMonitorHandle(pAdapter);
adp->revision = getRevision(pAdapter);
adp->subSystemId = getSubSystemId(pAdapter);
adp->vendorId = getVendorId(pAdapter);
adapters.push_back(std::move(adp));
}
}
String GraphicsAdapter::Description() const {
if (!impl->dxAdapter) return String();
DXGI_ADAPTER_DESC1 desc;
impl->dxAdapter->GetDesc1(&desc);
String description = XnaHelper::ToString(desc.Description);
return description;
}
Uint GraphicsAdapter::DeviceId() const {
if (!impl->dxAdapter) return 0;
DXGI_ADAPTER_DESC1 desc;
impl->dxAdapter->GetDesc1(&desc);
return static_cast<Uint>(desc.DeviceId);
}
String GraphicsAdapter::DeviceName() const {
if (!impl->dxAdapter) return String();
comptr<IDXGIOutput> pOutput = nullptr;
if (impl->dxAdapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
DXGI_OUTPUT_DESC outputDesc{};
pOutput->GetDesc(&outputDesc);
String deviceName = XnaHelper::ToString(outputDesc.DeviceName);
return deviceName;
}
return String();
}
intptr_t GraphicsAdapter::MonitorHandle() const {
if (!impl->dxAdapter) return 0;
comptr<IDXGIOutput> pOutput = nullptr;
if (impl->dxAdapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
return reinterpret_cast<intptr_t>(outputDesc.Monitor);
}
return 0;
}
Uint GraphicsAdapter::Revision() const {
if (!impl->dxAdapter) return 0;
DXGI_ADAPTER_DESC1 desc;
impl->dxAdapter->GetDesc1(&desc);
return static_cast<Uint>(desc.Revision);
}
Uint GraphicsAdapter::SubSystemId() const {
if (!impl->dxAdapter) return 0;
DXGI_ADAPTER_DESC1 desc;
impl->dxAdapter->GetDesc1(&desc);
return static_cast<Uint>(desc.SubSysId);
}
Uint GraphicsAdapter::VendorId() const {
if (!impl->dxAdapter) return 0;
DXGI_ADAPTER_DESC1 desc;
impl->dxAdapter->GetDesc1(&desc);
return static_cast<Uint>(desc.VendorId);
}
}
uptr<DisplayModeCollection> GraphicsAdapter::SupportedDisplayModes() const {
if (!impl->dxAdapter) return nullptr;
@ -191,27 +139,16 @@ namespace xna {
}
sptr<DisplayMode> GraphicsAdapter::CurrentDisplayMode() {
if (!impl->_currentDisplayMode) {
CurrentDisplayMode(SurfaceFormat::Color, GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight);
if (!currentDisplayMode) {
setCurrentDisplayMode(*this,
SurfaceFormat::Color,
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight,
currentDisplayMode);
}
return impl->_currentDisplayMode;
}
void GraphicsAdapter::CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height) {
const auto modes = SupportedDisplayModes(surfaceFormat);
for (size_t i = 0; i < modes->DisplayModes.size(); ++i) {
auto& m = modes->DisplayModes[i];
if (m->Format == surfaceFormat && m->Width == width && m->Height == height) {
impl->_currentDisplayMode = m;
}
else if(i + 1 == modes->DisplayModes.size()) {
impl->_currentDisplayMode = m;
}
}
}
return currentDisplayMode;
}
bool GraphicsAdapter::PlatformImplementation::GetOutput(UINT slot, IDXGIOutput*& output) const {
if (!dxAdapter) return false;
@ -224,7 +161,22 @@ namespace xna {
//INTERNAL FUNCTIONS
static size_t getDisplayModesCount(IDXGIAdapter* adapter) {
void setCurrentDisplayMode(GraphicsAdapter& adapter, SurfaceFormat surfaceFormat, Uint width, Uint height, sptr<DisplayMode>& currentDisplayMode) {
const auto modes = adapter.SupportedDisplayModes(surfaceFormat);
for (size_t i = 0; i < modes->DisplayModes.size(); ++i) {
auto& m = modes->DisplayModes[i];
if (m->Format == surfaceFormat && m->Width == width && m->Height == height) {
currentDisplayMode = m;
}
else if (i + 1 == modes->DisplayModes.size()) {
currentDisplayMode = m;
}
}
}
size_t getDisplayModesCount(IDXGIAdapter* adapter) {
comptr<IDXGIOutput> pOutput = nullptr;
size_t numModes = 0;
@ -243,7 +195,7 @@ namespace xna {
return numModes;
}
static uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source) {
uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source) {
auto collection = unew<DisplayModeCollection>();
DisplayMode currentDisplayMode;
std::vector<sptr<DisplayMode>> displayList;
@ -274,4 +226,67 @@ namespace xna {
return collection;
}
String getDescription(comptr<IDXGIAdapter1> const& adapter) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
const auto description = XnaHelper::ToString(desc.Description);
return description;
}
Uint getDeviceId(comptr<IDXGIAdapter1> const& adapter) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
return static_cast<Uint>(desc.DeviceId);
}
String getDeviceName(comptr<IDXGIAdapter1> const& adapter) {
comptr<IDXGIOutput> pOutput = nullptr;
if (adapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
DXGI_OUTPUT_DESC outputDesc{};
pOutput->GetDesc(&outputDesc);
String deviceName = XnaHelper::ToString(outputDesc.DeviceName);
return deviceName;
}
return String();
}
intptr_t getMonitorHandle(comptr<IDXGIAdapter1> const& adapter) {
comptr<IDXGIOutput> pOutput = nullptr;
if (adapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
return reinterpret_cast<intptr_t>(outputDesc.Monitor);
}
return 0;
}
Uint getRevision(comptr<IDXGIAdapter1> const& adapter) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
return static_cast<Uint>(desc.Revision);
}
Uint getSubSystemId(comptr<IDXGIAdapter1> const& adapter) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
return static_cast<Uint>(desc.SubSysId);
}
Uint getVendorId(comptr<IDXGIAdapter1> const& adapter) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
return static_cast<Uint>(desc.VendorId);
}
}

View File

@ -77,11 +77,7 @@ namespace xna {
GraphicsDevice::GraphicsDevice() {
impl = unew<PlatformImplementation>();
impl->_adapter = GraphicsAdapter::DefaultAdapter();
impl->_adapter->CurrentDisplayMode(
SurfaceFormat::Color,
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight);
impl->_adapter = GraphicsAdapter::DefaultAdapter();
}
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
@ -89,11 +85,7 @@ namespace xna {
impl->_adapter = info.Adapter;
impl->_gameWindow = info.Window;
impl->_presentationParameters = info.Parameters;
impl->_adapter->CurrentDisplayMode(
impl->_presentationParameters->BackBufferFormat,
impl->_presentationParameters->BackBufferWidth,
impl->_presentationParameters->BackBufferHeight);
impl->_presentationParameters = info.Parameters;
}
bool GraphicsDevice::Initialize() {

View File

@ -2,6 +2,7 @@
#define XNA_GRAPHICS_ADAPTER_HPP
#include "../default.hpp"
#include "displaymode.hpp"
namespace xna {
//Provides methods to retrieve and manipulate graphics adapters.
@ -9,38 +10,88 @@ namespace xna {
public:
GraphicsAdapter();
//Retrieves a string used for presentation to the user.
String Description() const;
//Retrieves a value that is used to help identify a particular chip set.
Uint DeviceId() const;
//Retrieves a string that contains the device name.
String DeviceName() const;
//Determines if this instance of GraphicsAdapter is the default adapter.
bool IsDefaultAdapter() const;
//Retrieves the handle of the monitor
intptr_t MonitorHandle() const;
//Retrieves a value used to help identify the revision level of a particular chip set.
Uint Revision() const;
//Retrieves a value used to identify the subsystem.
Uint SubSystemId() const;
//Retrieves a value used to identify the manufacturer.
Uint VendorId() const;
//Collection of available adapters on the system.
static void Adapters(std::vector<uptr<GraphicsAdapter>>& adapters);
//Gets the current display mode.
sptr<DisplayMode> CurrentDisplayMode();
//Gets the default adapter.
static uptr<GraphicsAdapter> DefaultAdapter();
//Retrieves a string used for presentation to the user.
constexpr String Description() const { return description; }
//Retrieves a value that is used to help identify a particular chip set.
constexpr Uint DeviceId() const { return deviceId; }
//Retrieves a string that contains the device name.
constexpr String DeviceName() const { return deviceName; }
//Determines if this instance of GraphicsAdapter is the default adapter.
constexpr bool IsDefaultAdapter() const { return isDefault; }
//Determines if the graphics adapter is in widescreen mode.
constexpr bool IsWideScreen() const { return false; }
//Retrieves the handle of the monitor
constexpr intptr_t MonitorHandle() const { return monitorHandle; }
//Retrieves a value used to help identify the revision level of a particular chip set.
constexpr Uint Revision() const { return revision; }
//Retrieves a value used to identify the subsystem.
constexpr Uint SubSystemId() const { return subSystemId; }
//Returns a collection of supported display modes for the current adapter.
uptr<DisplayModeCollection> SupportedDisplayModes() const;
//Returns a collection of supported display modes for the current adapter.
uptr<DisplayModeCollection> SupportedDisplayModes(SurfaceFormat surfaceFormat) const;
//Gets the current display mode.
sptr<DisplayMode> CurrentDisplayMode();
//Gets the current display mode.
void CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height);
//Gets the default adapter.
static uptr<GraphicsAdapter> DefaultAdapter();
//Collection of available adapters on the system.
static void Adapters(std::vector<uptr<GraphicsAdapter>>& adapters);
//Retrieves a value used to identify the manufacturer.
constexpr Uint VendorId() const { return vendorId; }
//Tests to see if the adapter supports the requested profile.
bool IsProfileSupported(GraphicsProfile graphicsProfile) {
return false;
}
//Queries the adapter for support for the requested back buffer format.
bool QueryBackBufferFormat(
GraphicsProfile graphicsProfile,
SurfaceFormat format,
DepthFormat depthFormat,
Int multiSampleCount,
SurfaceFormat& selectedFormat,
DepthFormat& selectedDepthFormat,
Int& selectedMultiSampleCount
) {
return false;
}
//Queries the adapter for support for the requested render target format.
bool QueryRenderTargetFormat(
GraphicsProfile graphicsProfile,
SurfaceFormat format,
DepthFormat depthFormat,
Int multiSampleCount,
SurfaceFormat& selectedFormat,
DepthFormat& selectedDepthFormat,
int& selectedMultiSampleCount
) {
return false;
}
private:
String description;
Uint deviceId{0};
String deviceName;
bool isDefault{ false };
intptr_t monitorHandle{ 0 };
Uint revision{ 0 };
Uint subSystemId{ 0 };
Uint vendorId{ 0 };
sptr<DisplayMode> currentDisplayMode{ nullptr };
public:
struct PlatformImplementation;

View File

@ -591,15 +591,10 @@ namespace xna {
struct GraphicsAdapter::PlatformImplementation {
comptr<IDXGIAdapter1> dxAdapter = nullptr;
comptr<IDXGIFactory1> dxFactory = nullptr;
private:
friend class GraphicsAdapter;
Uint _index{ 0 };
sptr<DisplayMode> _currentDisplayMode = nullptr;
comptr<IDXGIFactory1> dxFactory = nullptr;
public:
bool GetOutput(UINT slot, IDXGIOutput*& output) const;
bool GetOutput(UINT slot, IDXGIOutput*& output) const;
};
struct BlendRenderTarget {