mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações iniciais em GraphicsDeviceManager
This commit is contained in:
parent
989abcfa13
commit
626bc01dad
@ -1,41 +1,44 @@
|
||||
#include "xna/game/gdevicemanager.hpp"
|
||||
#include "xna/graphics/presentparams.hpp"
|
||||
#include "xna/graphics/swapchain.hpp"
|
||||
#include "xna/xna-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
GraphicsDeviceManager::GraphicsDeviceManager(sptr<Game> const& game) : _game(game)
|
||||
GraphicsDeviceManager::GraphicsDeviceManager(sptr<Game> const& game) : game(game)
|
||||
{
|
||||
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
|
||||
_information.Adapter = adp;
|
||||
_information.Profile = xna::GraphicsProfile::HiDef;
|
||||
|
||||
auto parameters = snew<PresentationParameters>();
|
||||
parameters->BackBufferWidth = _backBufferWidth;
|
||||
parameters->BackBufferHeight = _backBufferHeight;
|
||||
parameters->BackBufferWidth = backBufferWidth;
|
||||
parameters->BackBufferHeight = backBufferHeight;
|
||||
parameters->BackBufferFormat = SurfaceFormat::Color;
|
||||
parameters->Fullscreen = false;
|
||||
_information.Parameters = parameters;
|
||||
|
||||
if (_game)
|
||||
_information.Window = _game->Window();
|
||||
if (game)
|
||||
_information.Window = game->Window();
|
||||
}
|
||||
|
||||
bool GraphicsDeviceManager::Initialize() {
|
||||
if (!_game)
|
||||
if (!game)
|
||||
return false;
|
||||
|
||||
return CreateDevice();
|
||||
CreateDevice();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::ApplyChanges() {
|
||||
if (device && !isDeviceDirty)
|
||||
return;
|
||||
|
||||
ChangeDevice(false);
|
||||
}
|
||||
|
||||
bool GraphicsDeviceManager::ToggleFullScreen() {
|
||||
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->impl->_swapChain)
|
||||
if (!game || !game->graphicsDevice || !game->graphicsDevice->impl->_swapChain)
|
||||
return false;
|
||||
|
||||
auto& swap = _game->graphicsDevice->impl->_swapChain;
|
||||
auto& swap = game->graphicsDevice->impl->_swapChain;
|
||||
|
||||
BOOL state = false;
|
||||
auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr);
|
||||
@ -46,20 +49,10 @@ namespace xna {
|
||||
|
||||
if (FAILED(hr)) return false;
|
||||
|
||||
_isFullScreen = !state;
|
||||
isFullScreen = !state;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::PreferredBackBufferWidth(Int value) {
|
||||
_backBufferWidth = value;
|
||||
_isDeviceDirty = true;
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::PreferredBackBufferHeight(Int value) {
|
||||
_backBufferHeight = value;
|
||||
_isDeviceDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool initWindow(GraphicsDeviceInformation& info, Game& game, int backWidth, int backHeight)
|
||||
{
|
||||
@ -98,21 +91,36 @@ namespace xna {
|
||||
}
|
||||
|
||||
|
||||
bool GraphicsDeviceManager::CreateDevice() {
|
||||
if (_isDeviceDirty) {
|
||||
_information.Parameters->BackBufferWidth = _backBufferWidth;
|
||||
_information.Parameters->BackBufferHeight = _backBufferHeight;
|
||||
void GraphicsDeviceManager::CreateDevice() {
|
||||
if (isDeviceDirty) {
|
||||
_information.Parameters->BackBufferWidth = backBufferWidth;
|
||||
_information.Parameters->BackBufferHeight = backBufferHeight;
|
||||
}
|
||||
|
||||
auto result = initWindow(_information, *_game, _backBufferWidth, _backBufferHeight);
|
||||
auto result = initWindow(_information, *game, backBufferWidth, backBufferHeight);
|
||||
|
||||
if (!result) return false;
|
||||
//if (!result) return false;
|
||||
|
||||
return initDevice(_information, *_game, _device);
|
||||
initDevice(_information, *game, device);
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::ChangeDevice() {
|
||||
}
|
||||
|
||||
|
||||
void GraphicsDeviceManager::AddDevice(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) {
|
||||
const auto handle = game->Window()->Handle();
|
||||
|
||||
std::vector<uptr<GraphicsAdapter>> adapters;
|
||||
GraphicsAdapter::Adapters(adapters);
|
||||
|
||||
for (size_t i = 0; adapters.size(); ++i) {
|
||||
auto& adapter = adapters[i];
|
||||
|
||||
if (!anySuitableDevice) {
|
||||
//TODO
|
||||
//if (!this.IsWindowOnAdapter(handle, adapter))
|
||||
//continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,36 +3,161 @@
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "gdeviceinfo.hpp"
|
||||
#include "../csharp/eventhandler.hpp"
|
||||
|
||||
namespace xna {
|
||||
class GraphicsDeviceManager {
|
||||
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 {
|
||||
public:
|
||||
//Creates a new GraphicsDeviceManager and registers it to handle the configuration and management of the graphics device for the specified Game.
|
||||
GraphicsDeviceManager(sptr<Game> const& game);
|
||||
~GraphicsDeviceManager() {}
|
||||
|
||||
public:
|
||||
//Specifies the default minimum back-buffer width.
|
||||
static constexpr int DefaultBackBufferWidth = 800;
|
||||
//Specifies the default minimum back-buffer height.
|
||||
static constexpr int DefaultBackBufferHeight = 480;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//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();
|
||||
bool ToggleFullScreen();
|
||||
Int PreferredBackBufferWidth() const;
|
||||
Int PreferredBackBufferHeight() const;
|
||||
void PreferredBackBufferWidth(Int value);
|
||||
void PreferredBackBufferHeight(Int value);
|
||||
|
||||
public:
|
||||
static constexpr int DefaultBackBufferWidth = 800;
|
||||
static constexpr int DefaultBackBufferHeight = 480;
|
||||
private:
|
||||
void ChangeDevice(bool forceCreate){}
|
||||
void AddDevice(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
|
||||
|
||||
protected:
|
||||
bool CreateDevice();
|
||||
void CreateDevice();
|
||||
void ChangeDevice();
|
||||
|
||||
private:
|
||||
sptr<Game> _game = nullptr;
|
||||
Int _backBufferWidth{ DefaultBackBufferWidth };
|
||||
Int _backBufferHeight{ DefaultBackBufferHeight };
|
||||
bool _isDeviceDirty{ false };
|
||||
sptr<GraphicsDevice> _device = nullptr;
|
||||
bool _isFullScreen{ false };
|
||||
bool BeginDraw() override { return false; }
|
||||
void EndDraw() override{ }
|
||||
|
||||
private:
|
||||
sptr<Game> game = nullptr;
|
||||
bool isDeviceDirty{ false };
|
||||
sptr<GraphicsDevice> device = nullptr;
|
||||
GraphicsDeviceInformation _information{};
|
||||
|
||||
bool isFullScreen{ false };
|
||||
Int backBufferWidth{ DefaultBackBufferWidth };
|
||||
Int backBufferHeight{ DefaultBackBufferHeight };
|
||||
GraphicsProfile graphicsProfile;
|
||||
DepthFormat depthStencilFormat{ DepthFormat::Depth24 };
|
||||
SurfaceFormat backBufferFormat;
|
||||
DisplayOrientation supportedOrientations;
|
||||
bool synchronizeWithVerticalRetrace{ true };
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace xna {
|
||||
String Title() const;
|
||||
void Title(String const& title);
|
||||
Rectangle ClientBounds() const;
|
||||
intptr_t Handle() const;
|
||||
intptr_t Handle() const;
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
|
@ -16,7 +16,7 @@ namespace xna {
|
||||
|
||||
void Initialize() override {
|
||||
auto game = reinterpret_cast<Game*>(this);
|
||||
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
||||
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
||||
graphics->Initialize();
|
||||
|
||||
std::any device = graphicsDevice;
|
||||
@ -45,7 +45,7 @@ namespace xna {
|
||||
private:
|
||||
sptr<GraphicsDeviceManager> graphics = nullptr;
|
||||
sptr<SpriteBatch> spriteBatch = nullptr;
|
||||
sptr<Texture2D> texture = nullptr;
|
||||
sptr<Texture2D> texture = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user