2024-03-18 15:41:46 -03:00
|
|
|
#ifndef XNA_PLATFORM_DEVICE_DX_HPP
|
|
|
|
#define XNA_PLATFORM_DEVICE_DX_HPP
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
#include "../common/color.hpp"
|
2024-03-18 15:41:46 -03:00
|
|
|
#include "../graphics/device.hpp"
|
2024-03-30 14:25:08 -03:00
|
|
|
#include "../graphics/presentparams.hpp"
|
2024-04-26 10:13:00 -03:00
|
|
|
#include "../graphics/viewport.hpp"
|
2024-04-21 19:55:50 -03:00
|
|
|
#include "adapter-dx.hpp"
|
2024-04-26 10:13:00 -03:00
|
|
|
#include "d3d11.h"
|
|
|
|
#include "dxgi.h"
|
2024-04-21 19:55:50 -03:00
|
|
|
#include "gdeviceinfo-dx.hpp"
|
|
|
|
#include "swapchain-dx.hpp"
|
2024-04-26 10:13:00 -03:00
|
|
|
#include "window-dx.hpp"
|
|
|
|
#include "presentparameters-dx.hpp"
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-03-21 16:01:47 -03:00
|
|
|
class GraphicsDevice : public IGraphicsDevice {
|
2024-03-18 15:41:46 -03:00
|
|
|
public:
|
2024-03-21 16:01:47 -03:00
|
|
|
GraphicsDevice();
|
2024-03-30 14:25:08 -03:00
|
|
|
GraphicsDevice(GraphicsDeviceInformation const& info);
|
2024-03-18 15:41:46 -03:00
|
|
|
|
2024-03-21 16:01:47 -03:00
|
|
|
virtual ~GraphicsDevice() override {
|
2024-03-18 15:41:46 -03:00
|
|
|
if (_device) {
|
|
|
|
_device->Release();
|
|
|
|
_device = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_context) {
|
|
|
|
_context->Release();
|
|
|
|
_context = nullptr;
|
|
|
|
}
|
2024-04-14 13:02:22 -03:00
|
|
|
|
|
|
|
if (_factory) {
|
|
|
|
_factory->Release();
|
|
|
|
_factory = nullptr;
|
|
|
|
}
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|
|
|
|
|
2024-03-21 16:01:47 -03:00
|
|
|
virtual void Clear() override;
|
2024-04-16 16:13:36 -03:00
|
|
|
virtual void Clear(Color const& color) override;
|
2024-03-21 16:01:47 -03:00
|
|
|
virtual bool Initialize(GameWindow& gameWindow) override;
|
|
|
|
virtual bool Present() override;
|
|
|
|
|
2024-04-26 11:35:59 -03:00
|
|
|
virtual sptr<GraphicsAdapter> Adapter() const override {
|
2024-04-02 09:27:43 -03:00
|
|
|
return _adapter;
|
|
|
|
}
|
|
|
|
|
2024-04-26 11:35:59 -03:00
|
|
|
virtual void Adapter(sptr<GraphicsAdapter> const& adapter) override {
|
2024-04-02 09:27:43 -03:00
|
|
|
_adapter = adapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual constexpr xna::Viewport Viewport() const override {
|
|
|
|
return _viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual constexpr void Viewport(xna::Viewport const& viewport) override {
|
|
|
|
_viewport = viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UseVSync(bool use) override {
|
|
|
|
_usevsync = use;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:41:46 -03:00
|
|
|
constexpr void SetCreateFlags(D3D11_CREATE_DEVICE_FLAG flags) {
|
|
|
|
_createDeviceFlags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void ClearCreateFlags() {
|
|
|
|
_createDeviceFlags = 0;
|
|
|
|
}
|
|
|
|
|
2024-03-21 16:01:47 -03:00
|
|
|
bool GetSwapChainBackBuffer(ID3D11Texture2D*& texture2D);
|
|
|
|
|
2024-03-18 15:41:46 -03:00
|
|
|
public:
|
|
|
|
ID3D11Device* _device{ nullptr };
|
|
|
|
ID3D11DeviceContext* _context{ nullptr };
|
2024-04-14 13:02:22 -03:00
|
|
|
IDXGIFactory1* _factory = nullptr;
|
2024-04-26 11:35:59 -03:00
|
|
|
sptr<SwapChain> _swapChain{ nullptr };
|
|
|
|
sptr<GraphicsAdapter> _adapter{ nullptr };
|
|
|
|
sptr<RenderTarget2D> _renderTarget2D{ nullptr };
|
|
|
|
sptr<BlendState> _blendState{ nullptr };
|
2024-04-22 16:14:55 -03:00
|
|
|
xna::Viewport _viewport{};
|
2024-04-26 10:13:00 -03:00
|
|
|
xna::PresentationParameters _presentationParameters;
|
2024-03-18 15:41:46 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int _createDeviceFlags{ 0 };
|
|
|
|
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
|
|
|
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
2024-04-16 16:13:36 -03:00
|
|
|
bool _usevsync{ true };
|
2024-03-21 16:01:47 -03:00
|
|
|
|
|
|
|
bool createDevice();
|
2024-04-26 10:13:00 -03:00
|
|
|
void reset();
|
2024-03-21 16:01:47 -03:00
|
|
|
};
|
2024-03-18 15:41:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|