mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige GraphicsAdapter
This commit is contained in:
parent
40e0c00e79
commit
f429fcd0ab
@ -100,8 +100,10 @@ namespace xna {
|
|||||||
using PDisplayMode = std::shared_ptr<DisplayMode>;
|
using PDisplayMode = std::shared_ptr<DisplayMode>;
|
||||||
class DisplayModeCollection;
|
class DisplayModeCollection;
|
||||||
using PDisplayModeCollection = std::shared_ptr<DisplayModeCollection>;
|
using PDisplayModeCollection = std::shared_ptr<DisplayModeCollection>;
|
||||||
|
using UDisplayModeCollection = std::unique_ptr<DisplayModeCollection>;
|
||||||
class GraphicsAdapter;
|
class GraphicsAdapter;
|
||||||
using PGraphicsAdapter = std::shared_ptr<GraphicsAdapter>;
|
using PGraphicsAdapter = std::shared_ptr<GraphicsAdapter>;
|
||||||
|
using UGraphicsAdapter = std::unique_ptr<GraphicsAdapter>;
|
||||||
class GraphicsDevice;
|
class GraphicsDevice;
|
||||||
using PGraphicsDevice = std::shared_ptr<GraphicsDevice>;
|
using PGraphicsDevice = std::shared_ptr<GraphicsDevice>;
|
||||||
class GraphicsDeviceInformation;
|
class GraphicsDeviceInformation;
|
||||||
|
@ -19,7 +19,11 @@ namespace xna {
|
|||||||
virtual Uint Revision() const = 0;
|
virtual Uint Revision() const = 0;
|
||||||
virtual Uint SubSystemId() const = 0;
|
virtual Uint SubSystemId() const = 0;
|
||||||
virtual Uint VendorId() const = 0;
|
virtual Uint VendorId() const = 0;
|
||||||
virtual PDisplayModeCollection SupportedDisplayModes() const = 0;
|
virtual UDisplayModeCollection SupportedDisplayModes() const = 0;
|
||||||
|
|
||||||
|
static UGraphicsAdapter DefaultAdapter();
|
||||||
|
static void GetAllAdapters(std::vector<PGraphicsAdapter>& adapters);
|
||||||
|
static void GetAllAdapters(std::vector<UGraphicsAdapter>& adapters);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,17 +3,76 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
|
||||||
PGraphicsAdapter GraphicsAdapter::DefaultAdapter() {
|
UGraphicsAdapter IGraphicsAdapter::DefaultAdapter() {
|
||||||
if (_adaptersList.empty())
|
IDXGIFactory1* pFactory = nullptr;
|
||||||
|
|
||||||
|
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (_defaultAdapterIndex >= _adaptersList.size())
|
IDXGIAdapter1* pAdapter = nullptr;
|
||||||
return nullptr;
|
|
||||||
|
if (pFactory->EnumAdapters1(0, &pAdapter) != DXGI_ERROR_NOT_FOUND) {
|
||||||
|
auto adp = uNew<GraphicsAdapter>();
|
||||||
|
|
||||||
return _adaptersList[_defaultAdapterIndex];
|
adp->_index = 0;
|
||||||
|
adp->_adapter = pAdapter;
|
||||||
|
|
||||||
|
return std::move(adp);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFactory->Release();
|
||||||
|
pFactory = nullptr;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IGraphicsAdapter::GetAllAdapters(std::vector<PGraphicsAdapter>& adapters){
|
||||||
|
IDXGIFactory1* pFactory = nullptr;
|
||||||
|
|
||||||
|
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IDXGIAdapter1* pAdapter = nullptr;
|
||||||
|
UINT count = 0;
|
||||||
|
|
||||||
|
for (; pFactory->EnumAdapters1(count, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++count) {
|
||||||
|
auto adp = New<GraphicsAdapter>();
|
||||||
|
|
||||||
|
adp->_index = count;
|
||||||
|
adp->_adapter = pAdapter;
|
||||||
|
|
||||||
|
adapters.push_back(adp);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFactory->Release();
|
||||||
|
pFactory = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IGraphicsAdapter::GetAllAdapters(std::vector<UGraphicsAdapter>& adapters) {
|
||||||
|
IDXGIFactory1* pFactory = nullptr;
|
||||||
|
|
||||||
|
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))
|
||||||
|
return;
|
||||||
|
|
||||||
|
IDXGIAdapter1* pAdapter = nullptr;
|
||||||
|
UINT count = 0;
|
||||||
|
|
||||||
|
for (; pFactory->EnumAdapters1(count, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++count) {
|
||||||
|
auto adp = uNew<GraphicsAdapter>();
|
||||||
|
|
||||||
|
adp->_index = count;
|
||||||
|
adp->_adapter = pAdapter;
|
||||||
|
|
||||||
|
adapters.push_back(std::move(adp));
|
||||||
|
}
|
||||||
|
|
||||||
|
pFactory->Release();
|
||||||
|
pFactory = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String GraphicsAdapter::Description() const {
|
String GraphicsAdapter::Description() const {
|
||||||
|
if (!_adapter) return String();
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
_adapter->GetDesc1(&desc);
|
_adapter->GetDesc1(&desc);
|
||||||
String description = XnaHToString(desc.Description);
|
String description = XnaHToString(desc.Description);
|
||||||
@ -21,6 +80,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint GraphicsAdapter::DeviceId() const {
|
Uint GraphicsAdapter::DeviceId() const {
|
||||||
|
if (!_adapter) return 0;
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
_adapter->GetDesc1(&desc);
|
_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
@ -28,6 +89,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String GraphicsAdapter::DeviceName() const {
|
String GraphicsAdapter::DeviceName() const {
|
||||||
|
if (!_adapter) return String();
|
||||||
|
|
||||||
IDXGIOutput* pOutput = nullptr;
|
IDXGIOutput* pOutput = nullptr;
|
||||||
DXGI_OUTPUT_DESC outputDesc;
|
DXGI_OUTPUT_DESC outputDesc;
|
||||||
|
|
||||||
@ -45,6 +108,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
intptr_t GraphicsAdapter::MonitorHandle() const {
|
intptr_t GraphicsAdapter::MonitorHandle() const {
|
||||||
|
if (!_adapter) return 0;
|
||||||
|
|
||||||
IDXGIOutput* pOutput = nullptr;
|
IDXGIOutput* pOutput = nullptr;
|
||||||
DXGI_OUTPUT_DESC outputDesc;
|
DXGI_OUTPUT_DESC outputDesc;
|
||||||
|
|
||||||
@ -61,6 +126,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint GraphicsAdapter::Revision() const {
|
Uint GraphicsAdapter::Revision() const {
|
||||||
|
if (!_adapter) return 0;
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
_adapter->GetDesc1(&desc);
|
_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
@ -68,6 +135,8 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint GraphicsAdapter::SubSystemId() const {
|
Uint GraphicsAdapter::SubSystemId() const {
|
||||||
|
if (!_adapter) return 0;
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
_adapter->GetDesc1(&desc);
|
_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
@ -75,13 +144,17 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uint GraphicsAdapter::VendorId() const {
|
Uint GraphicsAdapter::VendorId() const {
|
||||||
|
if (!_adapter) return 0;
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
_adapter->GetDesc1(&desc);
|
_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
return static_cast<Uint>(desc.VendorId);
|
return static_cast<Uint>(desc.VendorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDisplayModeCollection GraphicsAdapter::SupportedDisplayModes() const {
|
UDisplayModeCollection GraphicsAdapter::SupportedDisplayModes() const {
|
||||||
|
if (!_adapter) return nullptr;
|
||||||
|
|
||||||
IDXGIOutput* pOutput = nullptr;
|
IDXGIOutput* pOutput = nullptr;
|
||||||
UINT numModes = 0;
|
UINT numModes = 0;
|
||||||
UINT totalModes = 0;
|
UINT totalModes = 0;
|
||||||
@ -90,7 +163,7 @@ namespace xna {
|
|||||||
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
|
if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) {
|
||||||
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
|
for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) {
|
||||||
const auto currentSurface = static_cast<SurfaceFormat>(f);
|
const auto currentSurface = static_cast<SurfaceFormat>(f);
|
||||||
DXGI_FORMAT format = SurfaceFormatMapper::ParseToDXGI(currentSurface);
|
DXGI_FORMAT format = GraphicsAdapter::ToDXGI(currentSurface);
|
||||||
|
|
||||||
pOutput->GetDisplayModeList(format, 0, &numModes, nullptr);
|
pOutput->GetDisplayModeList(format, 0, &numModes, nullptr);
|
||||||
|
|
||||||
@ -107,47 +180,18 @@ namespace xna {
|
|||||||
|
|
||||||
pOutput->Release();
|
pOutput->Release();
|
||||||
|
|
||||||
auto collection = New<DisplayModeCollection>(totalModes);
|
auto collection = uNew<DisplayModeCollection>(totalModes);
|
||||||
|
|
||||||
for (size_t i = 0; i < totalModes; ++i) {
|
for (size_t i = 0; i < totalModes; ++i) {
|
||||||
const auto& modedesc = buffer[i];
|
const auto& modedesc = buffer[i];
|
||||||
const auto surface = SurfaceFormatMapper::ParseToSurface(modedesc.Format);
|
const auto surface = GraphicsAdapter::ToSurface(modedesc.Format);
|
||||||
|
|
||||||
collection->_displayModes[i] = DisplayMode(modedesc.Width, modedesc.Height, surface);
|
collection->_displayModes[i] = DisplayMode(modedesc.Width, modedesc.Height, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return std::move(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
return New<DisplayModeCollection>();
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<PGraphicsAdapter> GraphicsAdapter::getAllAdapters() {
|
|
||||||
IDXGIFactory1* pFactory = nullptr;
|
|
||||||
|
|
||||||
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) {
|
|
||||||
return std::vector<PGraphicsAdapter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<PGraphicsAdapter> adapters(2);
|
|
||||||
IDXGIAdapter1* pAdapter = nullptr;
|
|
||||||
UINT count = 0;
|
|
||||||
|
|
||||||
for (; pFactory->EnumAdapters1(count, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++count) {
|
|
||||||
auto adp = New<GraphicsAdapter>();
|
|
||||||
|
|
||||||
adp->_index = count;
|
|
||||||
adp->_adapter = pAdapter;
|
|
||||||
|
|
||||||
if (adapters.size() == count)
|
|
||||||
adapters.push_back(adp);
|
|
||||||
else
|
|
||||||
adapters[count] = adp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!adapters.empty() && adapters.size() != count)
|
|
||||||
adapters.resize(count);
|
|
||||||
|
|
||||||
return adapters;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,12 +2,13 @@
|
|||||||
#define XNA_PLATFORM_ADAPTER_DX_HPP
|
#define XNA_PLATFORM_ADAPTER_DX_HPP
|
||||||
|
|
||||||
#include "../graphics/adapter.hpp"
|
#include "../graphics/adapter.hpp"
|
||||||
#include "dxgi.h"
|
#include "dxheaders.hpp"
|
||||||
#include "d3d11.h"
|
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class GraphicsAdapter : public IGraphicsAdapter {
|
class GraphicsAdapter : public IGraphicsAdapter {
|
||||||
public:
|
public:
|
||||||
|
friend class IGraphicsAdapter;
|
||||||
|
|
||||||
GraphicsAdapter() {}
|
GraphicsAdapter() {}
|
||||||
|
|
||||||
virtual ~GraphicsAdapter() override {
|
virtual ~GraphicsAdapter() override {
|
||||||
@ -24,31 +25,16 @@ namespace xna {
|
|||||||
virtual Uint Revision() const override;
|
virtual Uint Revision() const override;
|
||||||
virtual Uint SubSystemId() const override;
|
virtual Uint SubSystemId() const override;
|
||||||
virtual Uint VendorId() const override;
|
virtual Uint VendorId() const override;
|
||||||
virtual PDisplayModeCollection SupportedDisplayModes() const override;
|
virtual UDisplayModeCollection SupportedDisplayModes() const override;
|
||||||
virtual constexpr bool IsDefaultAdapter() const { return _index == _defaultAdapterIndex; }
|
virtual constexpr bool IsDefaultAdapter() const { return _index == 0; }
|
||||||
|
|
||||||
static PGraphicsAdapter DefaultAdapter();
|
|
||||||
|
|
||||||
static constexpr void DefaultAdapter(size_t index) {
|
|
||||||
_defaultAdapterIndex = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr std::vector<PGraphicsAdapter> Adapters() {
|
|
||||||
return _adaptersList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IDXGIAdapter1* _adapter{ nullptr };
|
IDXGIAdapter1* _adapter{ nullptr };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Uint _index{ 0 };
|
Uint _index{ 0 };
|
||||||
inline static size_t _defaultAdapterIndex = 0;
|
|
||||||
static std::vector<PGraphicsAdapter> getAllAdapters();
|
|
||||||
inline static std::vector<PGraphicsAdapter> _adaptersList = getAllAdapters();
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SurfaceFormatMapper {
|
public:
|
||||||
static constexpr DXGI_FORMAT ParseToDXGI(SurfaceFormat format)
|
static constexpr DXGI_FORMAT ToDXGI(SurfaceFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -97,7 +83,7 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr SurfaceFormat ParseToSurface(DXGI_FORMAT format) {
|
static constexpr SurfaceFormat ToSurface(DXGI_FORMAT format) {
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
||||||
@ -140,7 +126,7 @@ namespace xna {
|
|||||||
return SurfaceFormat::Color;
|
return SurfaceFormat::Color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,7 +85,7 @@ namespace xna {
|
|||||||
if (!_dxAudioEngine) return;
|
if (!_dxAudioEngine) return;
|
||||||
|
|
||||||
const auto reverb = static_cast<DirectX::AUDIO_ENGINE_REVERB>(value);
|
const auto reverb = static_cast<DirectX::AUDIO_ENGINE_REVERB>(value);
|
||||||
_dxAudioEngine->SetMasterVolume(reverb);
|
_dxAudioEngine->SetReverb(reverb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -11,8 +11,9 @@ namespace xna {
|
|||||||
bool GraphicsDeviceManager::Initialize() {
|
bool GraphicsDeviceManager::Initialize() {
|
||||||
GraphicsDeviceInformation information;
|
GraphicsDeviceInformation information;
|
||||||
|
|
||||||
const auto adp = GraphicsAdapter::DefaultAdapter();
|
auto adp = GraphicsAdapter::DefaultAdapter();
|
||||||
information.Adapter(adp);
|
const PGraphicsAdapter sadp = std::move(adp);
|
||||||
|
information.Adapter(sadp);
|
||||||
information.GraphicsProfile(xna::GraphicsProfile::HiDef);
|
information.GraphicsProfile(xna::GraphicsProfile::HiDef);
|
||||||
|
|
||||||
PresentationParameters parameters;
|
PresentationParameters parameters;
|
||||||
|
@ -60,8 +60,6 @@ namespace xna {
|
|||||||
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
|
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PLATFORM_DEVELOPMENT
|
|
||||||
|
|
||||||
//See ref: https://en.cppreference.com/w/cpp/error/assert
|
//See ref: https://en.cppreference.com/w/cpp/error/assert
|
||||||
#define assertm(exp, msg) assert(((void)msg, exp))
|
#define assertm(exp, msg) assert(((void)msg, exp))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user