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