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

Implementações de GraphicsDeviceManager

This commit is contained in:
Danilo 2024-03-30 14:25:08 -03:00
parent c590f0dde4
commit 17365b2af3
16 changed files with 281 additions and 8 deletions

View File

@ -3,7 +3,7 @@
#
# Add source to this project's executable.
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp")
add_executable (xna WIN32 "xna.cpp" "xna.h" "platform/window-dx.cpp" "platform/device-dx.cpp" "platform/adapter-dx.cpp" "platform/swapchain-dx.cpp" "platform/rendertarget-dx.cpp" "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" "platform/clock-dx.cpp" "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET xna PROPERTY CXX_STANDARD 20)

View File

@ -40,6 +40,13 @@ namespace xna {
using BlendOperation = BlendFunction;
enum class DepthFormat {
None,
Depth16,
Depth24,
Depth24Stencil8
};
enum class DisplayOrientation {
Default = 0,
LandscapeLeft = 1,
@ -47,6 +54,24 @@ namespace xna {
Portrait = 4,
};
enum class GraphicsProfile {
Reach,
HiDef
};
enum class PresentInterval {
Default,
One,
Two,
Immediate
};
enum RenderTargetUsage {
DiscardContents,
PreserveContents,
PlatformContents
};
enum class SeekOrigin {
Begin,
Current,

View File

@ -50,7 +50,6 @@ namespace xna {
struct Vector4;
using PVector4 = std::shared_ptr<Vector4>;
//Game
class DrawableGameComponent;
using PDrawableGameComponent = std::shared_ptr<DrawableGameComponent>;
@ -63,15 +62,19 @@ namespace xna {
class GameClock;
using PGameClock = std::shared_ptr<GameClock>;
class GameTime;
using PGameTime = std::shared_ptr<GameTime>;
using PGameTime = std::shared_ptr<GameTime>;
class GameWindow;
using PGameWindow = std::shared_ptr<GameWindow>;
class GraphicsDeviceInformation;
using PGraphicsDeviceInformation = std::shared_ptr<GraphicsDeviceInformation>;
class GraphicsDeviceManager;
using PGraphicsDeviceManager = std::shared_ptr<GraphicsDeviceManager>;
class IDrawable;
using PIDrawable = std::shared_ptr<IDrawable>;
class IGameComponent;
using PIGameComponent = std::shared_ptr<IGameComponent>;
class IUpdatable;
using PIUpdatable = std::shared_ptr<IUpdatable>;
using PIUpdatable = std::shared_ptr<IUpdatable>;
//Graphics
class BlendState;
@ -84,6 +87,10 @@ namespace xna {
using PGraphicsAdapter = std::shared_ptr<GraphicsAdapter>;
class GraphicsDevice;
using PGraphicsDevice = std::shared_ptr<GraphicsDevice>;
class GraphicsDeviceInformation;
using PGraphicsDeviceInformation = std::shared_ptr<GraphicsDeviceInformation>;
class PresentationParameters;
using PPresentationParameters = std::shared_ptr< PresentationParameters>;
class RenderTarget2D;
using PRenderTarget2D = std::shared_ptr<RenderTarget2D>;
class SwapChain;

View File

@ -14,11 +14,12 @@ namespace xna {
virtual void Exit() = 0;
virtual int Run() = 0;
virtual PGameWindow Window() = 0;
protected:
virtual void Draw(GameTime const& gameTime) = 0;
virtual void Initialize() = 0;
virtual void Update(GameTime const& gameTime) = 0;
virtual void Update(GameTime const& gameTime) = 0;
};
}

View File

@ -0,0 +1,19 @@
#ifndef XNA_GAME_GDEVICEINFO_HPP
#define XNA_GAME_GDEVICEINFO_HPP
#include "../forward.hpp"
#include "../enums.hpp"
namespace xna {
class IGraphicsDeviceInformation {
public:
virtual PGraphicsAdapter Adapter() const = 0;
virtual void Adapter(PGraphicsAdapter const& value) = 0;
virtual xna::PresentationParameters PresentationParameters() const = 0;
virtual void PresentationParameters(xna::PresentationParameters const& value) = 0;
virtual xna::GraphicsProfile GraphicsProfile() const = 0;
virtual void GraphicsProfile(xna::GraphicsProfile value) = 0;
};
}
#endif

View File

@ -0,0 +1,23 @@
#ifndef XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
#include "../types.hpp"
#include "../csharp/timespan.hpp"
#include "../forward.hpp"
namespace xna {
class IGraphicsDeviceManager {
public:
virtual void ApplyChanges() = 0;
virtual void ToggleFullScreen() = 0;
virtual Int PreferredBackBufferWidth() const = 0;
virtual Int PreferredBackBufferHeight() const = 0;
virtual void PreferredBackBufferWidth(Int value) = 0;
virtual void PreferredBackBufferHeight(Int value) = 0;
protected:
virtual void CreateDevice(GraphicsDeviceInformation const& info) = 0;
virtual void ChangeDevice() = 0;
};
}
#endif

View File

@ -0,0 +1,23 @@
#ifndef XNA_GRAPHICS_PRESENTPARAMS_HPP
#define XNA_GRAPHICS_PRESENTPARAMS_HPP
#include "../types.hpp"
#include "../enums.hpp"
namespace xna {
class PresentationParameters {
public:
Int BackBufferWidth{ 0 };
Int BackBufferHeight{ 0 };
SurfaceFormat BackBufferFormat{ SurfaceFormat::Color };
DepthFormat DepthStencilFormat{ DepthFormat::None };
Int MultiSampleCount{ 0 };
xna::DisplayOrientation DisplayOrientation{ xna::DisplayOrientation::Default };
PresentInterval PresentationInterval{ PresentInterval::Default };
xna::RenderTargetUsage RenderTargetUsage{ xna::RenderTargetUsage::DiscardContents };
intptr_t DeviceWindowHandle{ 0 };
bool IsFullScreen{ false };
};
}
#endif

View File

@ -4,6 +4,7 @@
#include "rendertarget-dx.hpp"
#include "adapter-dx.hpp"
#include "blendstate-dx.hpp"
#include "gdeviceinfo-dx.hpp"
namespace xna {
GraphicsDevice::GraphicsDevice() {
@ -12,7 +13,15 @@ namespace xna {
auto a = _adapter->DeviceId();
}
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
_adapter = info.Adapter();
_presentParameters = info.PresentationParameters();
}
bool GraphicsDevice::Initialize(GameWindow& gameWindow) {
if (_blendState == nullptr)
_blendState = BlendState::NonPremultiplied();
_createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
if (_device) {

View File

@ -2,6 +2,7 @@
#define XNA_PLATFORM_DEVICE_DX_HPP
#include "../graphics/device.hpp"
#include "../graphics/presentparams.hpp"
#include "dxgi.h"
#include "d3d11.h"
@ -9,6 +10,7 @@ namespace xna {
class GraphicsDevice : public IGraphicsDevice {
public:
GraphicsDevice();
GraphicsDevice(GraphicsDeviceInformation const& info);
virtual ~GraphicsDevice() override {
if (_device) {
@ -44,6 +46,7 @@ namespace xna {
unsigned int _createDeviceFlags{ 0 };
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
float _backgroundColor[4] = { 0, 0, 0, 0 };
xna::PresentationParameters _presentParameters;
bool createDevice();
};

View File

@ -3,12 +3,16 @@
#include "device-dx.hpp"
#include "Windows.h"
#include "../game/time.hpp"
#include "gdevicemanager-dx.hpp"
namespace xna {
Game::Game() {
_gameWindow = New<GameWindow>();
_gameWindow->Color(255, 155, 55);
_gameWindow->Title("Teste de título");
_gameWindow->Size(
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, false);
_graphicsDevice = New<GraphicsDevice>();
}

View File

@ -16,6 +16,10 @@ namespace xna {
virtual void Exit() override{}
virtual int Run() override;
virtual PGameWindow Window() override {
return _gameWindow;
}
protected:
virtual void Draw(GameTime const& gameTime) override{}

View File

@ -0,0 +1,41 @@
#ifndef XNA_PLATFORM_GDEVICEINFOR_DX_HPP
#define XNA_PLATFORM_GDEVICEINFOR_DX_HPP
#include "../game/gdeviceinfo.hpp"
#include "adapter-dx.hpp"
namespace xna {
class GraphicsDeviceInformation : public IGraphicsDeviceInformation {
public:
inline virtual PGraphicsAdapter Adapter() const override {
return _adapter;
};
inline virtual void Adapter(PGraphicsAdapter const& value) override {
_adapter = value;
}
inline virtual xna::PresentationParameters PresentationParameters() const override{
return _parameters;
};
inline virtual void PresentationParameters(xna::PresentationParameters const& value) override{
_parameters = value;
};
inline virtual xna::GraphicsProfile GraphicsProfile() const override {
return _profile;
};
inline virtual void GraphicsProfile(xna::GraphicsProfile value) override {
_profile = value;
};
private:
PGraphicsAdapter _adapter{ nullptr };
xna::GraphicsProfile _profile{xna::GraphicsProfile::Reach};
xna::PresentationParameters _parameters{};
};
}
#endif

View File

@ -0,0 +1,25 @@
#include "gdevicemanager-dx.hpp"
#include "device-dx.hpp"
#include "game-dx.hpp"
#include "window-dx.hpp"
#include "gdeviceinfo-dx.hpp"
namespace xna {
void GraphicsDeviceManager::ApplyChanges() {
}
void GraphicsDeviceManager::ToggleFullScreen() {
}
void GraphicsDeviceManager::CreateDevice(GraphicsDeviceInformation const& info) {
_device = New<GraphicsDevice>();
auto window = _game->Window();
window->Size(_backBufferWidth, _backBufferHeight);
_device->Initialize(*window);
}
void GraphicsDeviceManager::ChangeDevice() {
}
}

View File

@ -0,0 +1,50 @@
#ifndef XNA_PLATFORM_GDEVICEMANAGER_DX_HPP
#define XNA_PLATFORM_GDEVICEMANAGER_DX_HPP
#include "../game/gdevicemanager.hpp"
namespace xna {
class GraphicsDeviceManager : public IGraphicsDeviceManager {
public:
GraphicsDeviceManager(Game* game) : _game(game){}
virtual void ApplyChanges() override;
virtual void ToggleFullScreen() override;
virtual constexpr Int PreferredBackBufferWidth() const {
return _backBufferWidth;
}
virtual constexpr Int PreferredBackBufferHeight() const {
return _backBufferHeight;
}
virtual void PreferredBackBufferWidth(Int value) {
_backBufferWidth = value;
_isDeviceDirty = true;
}
virtual void PreferredBackBufferHeight(Int value) {
_backBufferHeight = value;
_isDeviceDirty = true;
}
protected:
virtual void CreateDevice(GraphicsDeviceInformation const& info) override;
virtual void ChangeDevice() override;
public:
static constexpr int DefaultBackBufferWidth = 800;
static constexpr int DefaultBackBufferHeight = 480;
private:
Game*& _game;
Int _backBufferWidth{ DefaultBackBufferWidth };
Int _backBufferHeight{ DefaultBackBufferHeight };
bool _isDeviceDirty{ false };
PGraphicsDevice _device;
};
}
#endif

View File

@ -11,11 +11,21 @@ namespace xna {
}
void GameWindow::Size(int width, int height) {
void GameWindow::Position(int width, int height, bool update) {
_windowPosX = width;
_windowPosY = height;
setCenter();
if(update) Update();
}
void GameWindow::Size(int width, int height, bool update) {
_windowWidth = width;
_windowHeight = height;
setPosition();
setCenter();
if(update) Update();
}
void GameWindow::Title(String const& title) {
@ -77,6 +87,32 @@ namespace xna {
return true;
}
bool GameWindow::Update() {
if (_windowStyle == static_cast<int>(GameWindowMode::Windowed)) {
RECT winRect = { 0, 0, _windowWidth, _windowHeight };
AdjustWindowRectEx(&winRect,
GetWindowStyle(_windowHandle),
GetMenu(_windowHandle) != NULL,
GetWindowExStyle(_windowHandle));
_windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - (winRect.right - winRect.left) / 2;
_windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - (winRect.bottom - winRect.top) / 2;
MoveWindow(
_windowHandle,
_windowPosX,
_windowPosY,
winRect.right - winRect.left,
winRect.bottom - winRect.top,
TRUE);
return _windowHandle ? true : false;
}
return true;
}
String GameWindow::Title() const {
return _windowTitle;
}

View File

@ -25,7 +25,8 @@ namespace xna {
return static_cast<GameWindowMode>(_windowStyle);
}
void Size(int width, int height);
void Position(int width, int height, bool update = true);
void Size(int width, int height, bool update = true);
inline HINSTANCE HInstance() const {
return _hInstance;
@ -88,6 +89,8 @@ namespace xna {
}
bool Create();
bool Update();
static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
virtual String Title() const override;