mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em GraphicsDevice
This commit is contained in:
parent
5d46b4246f
commit
e7deb038d5
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
The project is still under development and the next updates will focus on the following tasks:
|
The project is still under development and the next updates will focus on the following tasks:
|
||||||
- [x] Finish basic classes
|
- [x] Finish basic classes
|
||||||
- [x] Code refactoring and cleaning
|
- [ ] Code refactoring and cleaning
|
||||||
- [ ] 3D support
|
- [ ] 3D support
|
||||||
- [ ] Implementation of missing classes and functions
|
- [ ] Implementation of missing classes and functions
|
||||||
- [ ] Content Pipeline
|
- [ ] Content Pipeline
|
||||||
|
@ -18,10 +18,6 @@ namespace xna {
|
|||||||
impl._factory->Release();
|
impl._factory->Release();
|
||||||
impl._factory = nullptr;
|
impl._factory = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl._blendState = nullptr;
|
|
||||||
impl._swapChain = nullptr;
|
|
||||||
impl._renderTarget2D = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
|
static void createDevice(GraphicsDevice::PlatformImplementation& impl) {
|
||||||
@ -80,19 +76,15 @@ namespace xna {
|
|||||||
impl->_presentationParameters->BackBufferFormat,
|
impl->_presentationParameters->BackBufferFormat,
|
||||||
impl->_presentationParameters->BackBufferWidth,
|
impl->_presentationParameters->BackBufferWidth,
|
||||||
impl->_presentationParameters->BackBufferHeight);
|
impl->_presentationParameters->BackBufferHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsDevice::~GraphicsDevice() {
|
|
||||||
impl = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDevice::Initialize() {
|
bool GraphicsDevice::Initialize() {
|
||||||
|
auto _this = shared_from_this();
|
||||||
|
|
||||||
if (!impl)
|
if (!impl)
|
||||||
impl = uptr<PlatformImplementation>();
|
impl = uptr<PlatformImplementation>();
|
||||||
|
|
||||||
reset(*impl);
|
reset(*impl);
|
||||||
|
|
||||||
auto _this = shared_from_this();
|
|
||||||
|
|
||||||
createDevice(*impl);
|
createDevice(*impl);
|
||||||
|
|
||||||
@ -139,10 +131,7 @@ namespace xna {
|
|||||||
|
|
||||||
impl->_context->RSSetViewports(1, &view);
|
impl->_context->RSSetViewports(1, &view);
|
||||||
|
|
||||||
impl->_blendState = BlendState::NonPremultiplied();
|
impl->InitializeAndApplyStates(_this);
|
||||||
impl->_blendState->Bind(_this);
|
|
||||||
impl->_blendState->Initialize();
|
|
||||||
impl->_blendState->Apply();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -199,5 +188,42 @@ namespace xna {
|
|||||||
if (!impl) return;
|
if (!impl) return;
|
||||||
|
|
||||||
impl->_usevsync = use;
|
impl->_usevsync = use;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sptr<xna::BlendState> GraphicsDevice::BlendState() const {
|
||||||
|
return impl->_blendState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::BlendState(sptr<xna::BlendState> const& value) {
|
||||||
|
impl->_blendState = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<xna::DepthStencilState> GraphicsDevice::DepthStencilState() const {
|
||||||
|
return impl->_depthStencilState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::DepthStencilState(sptr<xna::DepthStencilState> const& value) {
|
||||||
|
impl->_depthStencilState = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<xna::RasterizerState> GraphicsDevice::RasterizerState() const {
|
||||||
|
return impl->_rasterizerState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::RasterizerState(sptr<xna::RasterizerState> const& value) {
|
||||||
|
impl->_rasterizerState = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
sptr<SamplerStateCollection> GraphicsDevice::SamplerStates() const {
|
||||||
|
return impl->_samplerStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int GraphicsDevice::MultiSampleMask() const {
|
||||||
|
return impl->_multiSampleMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsDevice::MultiSampleMask(Int value) {
|
||||||
|
impl->_multiSampleMask = value;
|
||||||
|
}
|
||||||
}
|
}
|
@ -74,6 +74,7 @@ namespace xna {
|
|||||||
class TextureCube;
|
class TextureCube;
|
||||||
class RasterizerState;
|
class RasterizerState;
|
||||||
class SamplerState;
|
class SamplerState;
|
||||||
|
class SamplerStateCollection;
|
||||||
class Shader;
|
class Shader;
|
||||||
class SpriteBatch;
|
class SpriteBatch;
|
||||||
class SpriteFont;
|
class SpriteFont;
|
||||||
|
@ -76,6 +76,8 @@ namespace xna {
|
|||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using PBlendState = sptr<BlendState>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -92,6 +92,8 @@ namespace xna {
|
|||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using PDepthStencilState = sptr<DepthStencilState>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,16 +4,40 @@
|
|||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders.
|
||||||
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> {
|
class GraphicsDevice : public std::enable_shared_from_this<GraphicsDevice> {
|
||||||
public:
|
public:
|
||||||
GraphicsDevice();
|
GraphicsDevice();
|
||||||
GraphicsDevice(GraphicsDeviceInformation const& info);
|
GraphicsDevice(GraphicsDeviceInformation const& info);
|
||||||
~GraphicsDevice();
|
|
||||||
|
//Gets the graphics adapter.
|
||||||
|
sptr<GraphicsAdapter> Adapter() const;
|
||||||
|
|
||||||
|
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
||||||
|
sptr<xna::BlendState> BlendState() const;
|
||||||
|
//Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque.
|
||||||
|
void BlendState(sptr<xna::BlendState> const& value);
|
||||||
|
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
||||||
|
sptr<xna::DepthStencilState> DepthStencilState() const;
|
||||||
|
//Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default.
|
||||||
|
void DepthStencilState(sptr<xna::DepthStencilState> const& value);
|
||||||
|
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
||||||
|
sptr<xna::RasterizerState> RasterizerState() const;
|
||||||
|
//Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise.
|
||||||
|
void RasterizerState(sptr<xna::RasterizerState> const& value);
|
||||||
|
//Retrieves a collection of SamplerState objects for the current GraphicsDevice.
|
||||||
|
sptr<SamplerStateCollection> SamplerStates() const;
|
||||||
|
|
||||||
|
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
||||||
|
Int MultiSampleMask() const;
|
||||||
|
//Gets or sets a bitmask controlling modification of the samples in a multisample render target. The default value is -1 (0xffffffff).
|
||||||
|
void MultiSampleMask(Int value);
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void Clear(Color const& color);
|
void Clear(Color const& color);
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
bool Present();
|
bool Present();
|
||||||
sptr<GraphicsAdapter> Adapter() const;
|
|
||||||
xna::Viewport Viewport() const;
|
xna::Viewport Viewport() const;
|
||||||
void Viewport(xna::Viewport const& viewport);
|
void Viewport(xna::Viewport const& viewport);
|
||||||
void UseVSync(bool use);
|
void UseVSync(bool use);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
//Contains rasterizer state, which determines how to convert vector data (shapes) into raster data (pixels).
|
//Contains rasterizer state, which determines how to convert vector data (shapes) into raster data (pixels).
|
||||||
class RasterizerState : GraphicsResource {
|
class RasterizerState : public GraphicsResource {
|
||||||
public:
|
public:
|
||||||
RasterizerState();
|
RasterizerState();
|
||||||
RasterizerState(sptr<GraphicsDevice> const& device);
|
RasterizerState(sptr<GraphicsDevice> const& device);
|
||||||
@ -58,6 +58,8 @@ namespace xna {
|
|||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using PRasterizerState = sptr<RasterizerState>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
//Contains sampler state, which determines how to sample texture data.
|
//Contains sampler state, which determines how to sample texture data.
|
||||||
class SamplerState : GraphicsResource {
|
class SamplerState : public GraphicsResource {
|
||||||
public:
|
public:
|
||||||
SamplerState();
|
SamplerState();
|
||||||
SamplerState(sptr<GraphicsDevice> const& device);
|
SamplerState(sptr<GraphicsDevice> const& device);
|
||||||
@ -70,6 +70,32 @@ namespace xna {
|
|||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using PSamplerState = sptr<SamplerState>;
|
||||||
|
|
||||||
|
//Collection of SamplerState objects.
|
||||||
|
class SamplerStateCollection {
|
||||||
|
public:
|
||||||
|
SamplerStateCollection(){}
|
||||||
|
|
||||||
|
SamplerStateCollection(size_t size)
|
||||||
|
: samplers(size){}
|
||||||
|
|
||||||
|
SamplerStateCollection(std::vector<PSamplerState> const& samplers)
|
||||||
|
: samplers(samplers) {}
|
||||||
|
|
||||||
|
PSamplerState operator[](size_t index) {
|
||||||
|
if (index >= samplers.size())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return samplers[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::vector<PSamplerState> samplers;
|
||||||
|
};
|
||||||
|
|
||||||
|
using PSamplerStateCollection = sptr<SamplerStateCollection>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -929,6 +929,13 @@ namespace xna {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GraphicsDevice::PlatformImplementation {
|
struct GraphicsDevice::PlatformImplementation {
|
||||||
|
PlatformImplementation() {
|
||||||
|
_blendState = xna::BlendState::Opaque();
|
||||||
|
_depthStencilState = xna::DepthStencilState::Default();
|
||||||
|
_rasterizerState = xna::RasterizerState::CullCounterClockwise();
|
||||||
|
_samplerStates = snew<SamplerStateCollection>();
|
||||||
|
}
|
||||||
|
|
||||||
~PlatformImplementation() {
|
~PlatformImplementation() {
|
||||||
if (_device) {
|
if (_device) {
|
||||||
_device->Release();
|
_device->Release();
|
||||||
@ -944,15 +951,37 @@ namespace xna {
|
|||||||
_factory->Release();
|
_factory->Release();
|
||||||
_factory = nullptr;
|
_factory = nullptr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void InitializeAndApplyStates(PGraphicsDevice const& device) {
|
||||||
|
_blendState->Bind(device);
|
||||||
|
_blendState->Initialize();
|
||||||
|
_blendState->Apply();
|
||||||
|
|
||||||
|
_rasterizerState->Bind(device);
|
||||||
|
_rasterizerState->Initialize();
|
||||||
|
_rasterizerState->Apply();
|
||||||
|
|
||||||
|
_depthStencilState->Bind(device);
|
||||||
|
_depthStencilState->Initialize();
|
||||||
|
_depthStencilState->Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D11Device* _device{ nullptr };
|
public:
|
||||||
ID3D11DeviceContext* _context{ nullptr };
|
ID3D11Device* _device = nullptr;
|
||||||
|
ID3D11DeviceContext* _context = nullptr;
|
||||||
IDXGIFactory1* _factory = nullptr;
|
IDXGIFactory1* _factory = nullptr;
|
||||||
sptr<SwapChain> _swapChain{ nullptr };
|
|
||||||
sptr<GraphicsAdapter> _adapter{ nullptr };
|
PBlendState _blendState = nullptr;
|
||||||
sptr<RenderTarget2D> _renderTarget2D{ nullptr };
|
PRasterizerState _rasterizerState = nullptr;
|
||||||
sptr<BlendState> _blendState{ nullptr };
|
PDepthStencilState _depthStencilState = nullptr;
|
||||||
|
PSamplerStateCollection _samplerStates = nullptr;
|
||||||
|
Int _multiSampleMask = 0xffffffff;
|
||||||
|
|
||||||
|
sptr<SwapChain> _swapChain = nullptr;
|
||||||
|
sptr<GraphicsAdapter> _adapter = nullptr;
|
||||||
|
sptr<RenderTarget2D> _renderTarget2D = nullptr;
|
||||||
sptr<GameWindow> _gameWindow = nullptr;
|
sptr<GameWindow> _gameWindow = nullptr;
|
||||||
xna::Viewport _viewport{};
|
xna::Viewport _viewport{};
|
||||||
sptr<xna::PresentationParameters> _presentationParameters;
|
sptr<xna::PresentationParameters> _presentationParameters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user