2024-03-30 14:25:08 -03:00
|
|
|
#ifndef XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
|
|
|
|
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
#include "../default.hpp"
|
2024-05-24 14:42:12 -03:00
|
|
|
#include "gdeviceinfo.hpp"
|
2024-07-28 17:03:13 -03:00
|
|
|
#include "../csharp/eventhandler.hpp"
|
2024-03-30 14:25:08 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-07-28 17:03:13 -03:00
|
|
|
struct IGraphicsDeviceService {
|
|
|
|
virtual sptr<GraphicsDevice> GetGraphicsDevice() = 0;
|
|
|
|
|
|
|
|
EventHandler<EventArgs> DeviceDisposing;
|
|
|
|
EventHandler<EventArgs> DeviceReset;
|
|
|
|
EventHandler<EventArgs> DeviceResetting;
|
|
|
|
EventHandler<EventArgs> DeviceCreated;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGraphicsDeviceManager {
|
|
|
|
virtual void CreateDevice() = 0;
|
|
|
|
virtual bool BeginDraw() = 0;
|
|
|
|
virtual void EndDraw() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GraphicsDeviceManager : public IGraphicsDeviceService, public IGraphicsDeviceManager {
|
2024-03-30 14:25:08 -03:00
|
|
|
public:
|
2024-07-28 17:03:13 -03:00
|
|
|
//Creates a new GraphicsDeviceManager and registers it to handle the configuration and management of the graphics device for the specified Game.
|
2024-05-24 14:42:12 -03:00
|
|
|
GraphicsDeviceManager(sptr<Game> const& game);
|
|
|
|
|
|
|
|
public:
|
2024-07-28 17:03:13 -03:00
|
|
|
//Specifies the default minimum back-buffer width.
|
2024-05-24 14:42:12 -03:00
|
|
|
static constexpr int DefaultBackBufferWidth = 800;
|
2024-07-28 17:03:13 -03:00
|
|
|
//Specifies the default minimum back-buffer height.
|
2024-05-30 22:14:01 -03:00
|
|
|
static constexpr int DefaultBackBufferHeight = 480;
|
2024-05-24 14:42:12 -03:00
|
|
|
|
2024-07-28 17:03:13 -03:00
|
|
|
public:
|
|
|
|
//Gets the GraphicsDevice associated with the GraphicsDeviceManager.
|
|
|
|
sptr<GraphicsDevice> GetGraphicsDevice() override {
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the graphics profile, which determines the graphics feature set.
|
|
|
|
constexpr GraphicsProfile PreferredGraphicsProfile() const {
|
|
|
|
return graphicsProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the graphics profile, which determines the graphics feature set.
|
|
|
|
constexpr void PreferredGraphicsProfile(xna::GraphicsProfile value) {
|
|
|
|
graphicsProfile = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets a value that indicates whether the device should start in full-screen mode.
|
|
|
|
constexpr bool IsFullScreen() const {
|
|
|
|
return isFullScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets a value that indicates whether the device should start in full-screen mode.
|
|
|
|
constexpr void IsFullScreen(bool value) {
|
|
|
|
isFullScreen = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the format of the back buffer.
|
|
|
|
constexpr SurfaceFormat PreferredBackBufferFormat() const {
|
|
|
|
return backBufferFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the format of the back buffer.
|
|
|
|
constexpr void PreferredBackBufferFormat(SurfaceFormat value) {
|
|
|
|
backBufferFormat = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the preferred back-buffer height.
|
|
|
|
constexpr Int PreferredBackBufferHeight() const {
|
|
|
|
return backBufferHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the preferred back-buffer height.
|
|
|
|
constexpr void PreferredBackBufferHeight(Int value) {
|
|
|
|
backBufferHeight = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the preferred back-buffer width.
|
|
|
|
constexpr Int PreferredBackBufferWidth() const {
|
|
|
|
return backBufferWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the preferred back-buffer width.
|
|
|
|
constexpr void PreferredBackBufferWidth(Int value) {
|
|
|
|
backBufferWidth = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the format of the depth stencil.
|
|
|
|
constexpr DepthFormat PreferredDepthStencilFormat() const {
|
|
|
|
return depthStencilFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the format of the depth stencil.
|
|
|
|
constexpr void PreferredDepthStencilFormat(DepthFormat value) {
|
|
|
|
depthStencilFormat = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
2024-07-30 10:43:39 -03:00
|
|
|
constexpr bool PreferMultiSampling() const {
|
|
|
|
return allowMultiSampling;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void PreferMultiSampling(bool value) {
|
|
|
|
allowMultiSampling = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
2024-07-28 17:03:13 -03:00
|
|
|
//Gets or sets the display orientations that are available if automatic rotation and scaling is enabled.
|
|
|
|
constexpr DisplayOrientation SupportedOrientations() const {
|
|
|
|
return supportedOrientations;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets the display orientations that are available if automatic rotation and scaling is enabled.
|
|
|
|
constexpr void SupportedOrientations(DisplayOrientation value) {
|
|
|
|
supportedOrientations = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets or sets a value that indicates whether to sync to the vertical trace (vsync) when presenting the back buffer.
|
|
|
|
constexpr bool SynchronizeWithVerticalRetrace() const {
|
|
|
|
return synchronizeWithVerticalRetrace;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets or sets a value that indicates whether to sync to the vertical trace(vsync) when presenting the back buffer.
|
|
|
|
constexpr void SynchronizeWithVerticalRetrace(bool value) {
|
|
|
|
synchronizeWithVerticalRetrace = value;
|
|
|
|
isDeviceDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
//Applies any changes to device-related properties, changing the graphics device as necessary.
|
|
|
|
void ApplyChanges();
|
|
|
|
bool Initialize();
|
2024-07-30 15:29:58 -03:00
|
|
|
bool ToggleFullScreen();
|
|
|
|
|
2024-07-31 17:07:06 -03:00
|
|
|
inline void CreateDevice() { ChangeDevice(true); }
|
2024-07-28 17:03:13 -03:00
|
|
|
|
2024-07-31 17:07:06 -03:00
|
|
|
protected:
|
2024-07-30 14:21:35 -03:00
|
|
|
inline virtual void RankDevices(std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) {
|
|
|
|
RankDevicesPlatform(foundDevices);
|
|
|
|
}
|
|
|
|
|
2024-07-30 14:26:52 -03:00
|
|
|
inline virtual sptr<GraphicsDeviceInformation> FindBestDevice(bool anySuitableDevice) {
|
|
|
|
return FindBestPlatformDevice(anySuitableDevice);
|
|
|
|
}
|
|
|
|
|
2024-07-30 16:31:36 -03:00
|
|
|
virtual bool CanResetDevice(GraphicsDeviceInformation& newDeviceInfo);
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
private:
|
2024-07-30 15:29:58 -03:00
|
|
|
void ChangeDevice(bool forceCreate);
|
|
|
|
void AddDevices(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
|
|
|
|
void AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr<GraphicsDeviceInformation>& baseDeviceInfo, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) const;
|
|
|
|
|
2024-07-28 17:03:13 -03:00
|
|
|
bool BeginDraw() override { return false; }
|
|
|
|
void EndDraw() override{ }
|
|
|
|
|
2024-07-30 14:21:35 -03:00
|
|
|
sptr<GraphicsDeviceInformation> FindBestPlatformDevice(bool anySuitableDevice);
|
|
|
|
|
|
|
|
void RankDevicesPlatform(std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
|
|
|
|
|
2024-07-30 21:56:17 -03:00
|
|
|
void CreateDevice(GraphicsDeviceInformation& newInfo);
|
2024-07-30 21:36:22 -03:00
|
|
|
|
|
|
|
void MassagePresentParameters(PresentationParameters& pp);
|
|
|
|
void ValidateGraphicsDeviceInformation(GraphicsDeviceInformation& devInfo);
|
2024-07-30 16:31:36 -03:00
|
|
|
|
2024-07-28 17:03:13 -03:00
|
|
|
private:
|
|
|
|
sptr<Game> game = nullptr;
|
|
|
|
bool isDeviceDirty{ false };
|
|
|
|
sptr<GraphicsDevice> device = nullptr;
|
2024-05-24 14:42:12 -03:00
|
|
|
GraphicsDeviceInformation _information{};
|
2024-07-28 17:03:13 -03:00
|
|
|
|
|
|
|
bool isFullScreen{ false };
|
|
|
|
Int backBufferWidth{ DefaultBackBufferWidth };
|
|
|
|
Int backBufferHeight{ DefaultBackBufferHeight };
|
2024-07-30 10:43:39 -03:00
|
|
|
GraphicsProfile graphicsProfile{GraphicsProfile::HiDef};
|
2024-07-28 17:03:13 -03:00
|
|
|
DepthFormat depthStencilFormat{ DepthFormat::Depth24 };
|
2024-07-30 10:43:39 -03:00
|
|
|
SurfaceFormat backBufferFormat{SurfaceFormat::Color};
|
|
|
|
DisplayOrientation supportedOrientations{DisplayOrientation::Default};
|
2024-07-28 17:03:13 -03:00
|
|
|
bool synchronizeWithVerticalRetrace{ true };
|
2024-07-30 10:43:39 -03:00
|
|
|
bool useResizedBackBuffer{ false };
|
|
|
|
Int resizedBackBufferWidth{ 0 };
|
|
|
|
Int resizedBackBufferHeight{ 0 };
|
|
|
|
bool allowMultiSampling{ false };
|
2024-07-30 15:29:58 -03:00
|
|
|
bool inDeviceTransition{ false };
|
2024-07-30 16:31:36 -03:00
|
|
|
bool isReallyFullScreen{ false };
|
2024-07-30 21:36:22 -03:00
|
|
|
DisplayOrientation currentWindowOrientation{ DisplayOrientation::Default };
|
2024-07-30 10:43:39 -03:00
|
|
|
|
|
|
|
std::vector<sptr<GraphicsDeviceInformation>> foundDevices;
|
2024-03-30 14:25:08 -03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|