diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 9a9524c..ee514a7 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -29,7 +29,7 @@ add_library (Xn65 STATIC "platform-dx/blendstate.cpp" "platform-dx/game.cpp" "platform-dx/gdevicemanager.cpp" -"platform-dx/shader.cpp" + "platform-dx/rasterizerstate.cpp" "platform-dx/samplerstate.cpp" "platform-dx/sprite.cpp" @@ -40,7 +40,7 @@ add_library (Xn65 STATIC "platform-dx/soundeffect.cpp" "platform-dx/displaymode.cpp" "platform-dx/init.cpp" -"platform-dx/buffer.cpp" + "platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp" "platform-dx/impl.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) diff --git a/framework/platform-dx/buffer.cpp b/framework/platform-dx/buffer.cpp deleted file mode 100644 index 7992e90..0000000 --- a/framework/platform-dx/buffer.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "xna/graphics/buffer.hpp" -#include "xna/common/numerics.hpp" -#include "xna/platform-dx/dx.hpp" - -namespace xna { - ConstantBuffer::ConstantBuffer() : GraphicsResource(nullptr){ - impl = unew(); - } - - ConstantBuffer::ConstantBuffer(sptr const& device) : GraphicsResource(device){ - impl = unew(); - } - - ConstantBuffer::~ConstantBuffer() { - impl = nullptr; - } - - bool ConstantBuffer::Initialize() - { - if (!m_device || !m_device->impl->_device) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->_buffer) { - impl->_buffer = nullptr; - } - - const auto hr = m_device->impl->_device->CreateBuffer( - &impl->_description, - &impl->_subResource, - impl->_buffer.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - return true; - } - - DataBuffer::DataBuffer() : GraphicsResource(nullptr) { - impl = unew(); - } - - DataBuffer::DataBuffer(sptr const& device) : GraphicsResource(device) { - impl = unew(); - } - - DataBuffer::~DataBuffer() { - impl = nullptr; - } - - bool DataBuffer::Initialize() { - if (!m_device || !m_device->impl->_device) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->_blob) { - impl->_blob = nullptr; - } - - return true; - } - - IndexBuffer::IndexBuffer() : GraphicsResource(nullptr) { - impl = unew(); - } - - IndexBuffer::IndexBuffer(sptr const& device) : GraphicsResource(device) { - impl = unew(); - } - - IndexBuffer::~IndexBuffer() { - impl = nullptr; - } - - bool IndexBuffer::Apply() { - if (!m_device || !m_device->impl->_context || !impl || !impl->dxBuffer) { - Exception::Throw(ExMessage::ApplyComponent); - } - - m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); - - return true; - } - - VertexBuffer::VertexBuffer() : GraphicsResource(nullptr) { - impl = unew(); - } - - VertexBuffer::VertexBuffer(sptr const& device) : GraphicsResource(device) { - impl = unew(); - } - - VertexBuffer::~VertexBuffer() { - impl = nullptr; - } - - bool VertexBuffer::Apply() { - if (!impl || !m_device || !m_device->impl->_context) { - Exception::Throw(ExMessage::ApplyComponent); - } - - if (!impl->dxBuffer) { - Exception::Throw(ExMessage::UnintializedComponent); - } - - UINT stride = impl->size; - UINT offset = 0; - m_device->impl->_context->IASetVertexBuffers(0, 1, - impl->dxBuffer.GetAddressOf(), &stride, &offset); - - return true; - } - - VertexInputLayout::VertexInputLayout() : GraphicsResource(nullptr) { - impl = unew(); - } - - VertexInputLayout::VertexInputLayout(sptr const& device) : GraphicsResource(device) { - impl = unew(); - } - - VertexInputLayout::~VertexInputLayout() { - impl = nullptr; - } - - bool VertexInputLayout::Initialize(DataBuffer& blob) { - if (!impl || !m_device || !m_device->impl->_device || !blob.impl->_blob) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->_inputLayout) { - impl->_inputLayout = nullptr; - } - - const auto hr = m_device->impl->_device->CreateInputLayout( - impl->_description.data(), - static_cast(impl->_description.size()), - blob.impl->_blob->GetBufferPointer(), - blob.impl->_blob->GetBufferSize(), - impl->_inputLayout.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - return true; - } -} \ No newline at end of file diff --git a/framework/platform-dx/shader.cpp b/framework/platform-dx/shader.cpp deleted file mode 100644 index d8e29ca..0000000 --- a/framework/platform-dx/shader.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "xna/graphics/buffer.hpp" -#include "xna/platform-dx/dx.hpp" -#include "xna/graphics/shader.hpp" - -namespace xna { - static HRESULT shaderCompileFromFile(_In_ LPCWSTR srcFile, _In_ LPCSTR entryPoint, _In_ LPCSTR profile, _Outptr_ ID3DBlob** blob) - { - //https://learn.microsoft.com/en-us/windows/win32/direct3d11/how-to--compile-a-shader - - if (!srcFile || !entryPoint || !profile || !blob) - return E_INVALIDARG; - - *blob = nullptr; - - UINT flags = D3DCOMPILE_ENABLE_STRICTNESS; -#if defined( DEBUG ) || defined( _DEBUG ) - flags |= D3DCOMPILE_DEBUG; -#endif - - const D3D_SHADER_MACRO defines[] = - { - "EXAMPLE_DEFINE", "1", - NULL, NULL - }; - - ID3DBlob* shaderBlob = nullptr; - ID3DBlob* errorBlob = nullptr; - HRESULT hr = D3DCompileFromFile(srcFile, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, - entryPoint, profile, - flags, 0, &shaderBlob, &errorBlob); - if (FAILED(hr)) - { - if (errorBlob) - { - OutputDebugStringA((char*)errorBlob->GetBufferPointer()); - errorBlob->Release(); - } - - if (shaderBlob) - shaderBlob->Release(); - - return hr; - } - - *blob = shaderBlob; - - return hr; - } - - bool Shader::CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob) { - const auto hr = shaderCompileFromFile(srcFile.c_str(), entryPoint.c_str(), profile.c_str(), &blob.impl->_blob); - - return SUCCEEDED(hr); - } - - VertexShader::~VertexShader() { - impl = nullptr; - } - - PixelShader::~PixelShader() { - impl = nullptr; - } - - bool VertexShader::Initialize(DataBuffer& buffer) - { - if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->_vertexShader) { - impl->_vertexShader.ReleaseAndGetAddressOf(); - } - - const auto hr = m_device->impl->_device->CreateVertexShader( - buffer.impl->_blob->GetBufferPointer(), - buffer.impl->_blob->GetBufferSize(), - NULL, - impl->_vertexShader.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - return true; - } - - bool PixelShader::Initialize(DataBuffer& buffer) - { - if (!impl || !m_device || !m_device->impl->_device || !buffer.impl->_blob) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->_pixelShader) { - impl->_pixelShader.ReleaseAndGetAddressOf(); - } - - const auto hr = m_device->impl->_device->CreatePixelShader( - buffer.impl->_blob->GetBufferPointer(), - buffer.impl->_blob->GetBufferSize(), - NULL, - impl->_pixelShader.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - return true; - } -} \ No newline at end of file diff --git a/inc/xna/graphics/buffer.hpp b/inc/xna/graphics/buffer.hpp deleted file mode 100644 index 66e4671..0000000 --- a/inc/xna/graphics/buffer.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef XNA_GRAPHICS_BUFFER_HPP -#define XNA_GRAPHICS_BUFFER_HPP - -#include "../default.hpp" -#include "gresource.hpp" - -namespace xna { - class ConstantBuffer : public GraphicsResource { - public: - ConstantBuffer(); - ConstantBuffer(sptr const&); - ~ConstantBuffer() override; - bool Initialize(); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - class DataBuffer : public GraphicsResource { - public: - DataBuffer(); - DataBuffer(sptr const&); - ~DataBuffer() override; - bool Initialize(); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - class IndexBuffer : public GraphicsResource { - public: - IndexBuffer(); - IndexBuffer(sptr const&); - ~IndexBuffer() override; - - template - bool Initialize(std::vector const& data); - bool Apply(); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - class VertexBuffer : public GraphicsResource { - public: - VertexBuffer(); - VertexBuffer(sptr const&); - ~VertexBuffer(); - template - bool Initialize(std::vector const& data); - bool Apply(); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - class VertexInputLayout : public GraphicsResource { - public: - VertexInputLayout(); - VertexInputLayout(sptr const&); - ~VertexInputLayout(); - - bool Initialize(DataBuffer& blob); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; -} - -#endif \ No newline at end of file diff --git a/inc/xna/graphics/shader.hpp b/inc/xna/graphics/shader.hpp deleted file mode 100644 index 158eb19..0000000 --- a/inc/xna/graphics/shader.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef XNA_GRAPHICS_SHADER_HPP -#define XNA_GRAPHICS_SHADER_HPP - -#include "../default.hpp" -#include "gresource.hpp" - -namespace xna { - class Shader : public GraphicsResource { - public: - Shader(); - Shader(sptr const& device); - ~Shader() override {} - bool Initialize(DataBuffer& buffer); - static bool CompileFromFile(WString srcFile, String entryPoint, String profile, DataBuffer& blob); - }; - - class VertexShader : public Shader { - public: - VertexShader(); - VertexShader(sptr const& device); - ~VertexShader() override; - bool Initialize(DataBuffer& buffer); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - class PixelShader : public Shader { - public: - PixelShader(); - PixelShader(sptr const& device); - ~PixelShader() override; - bool Initialize(DataBuffer& buffer); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; -} - -#endif \ No newline at end of file diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index 6b3dc4f..8fa8f04 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -66,7 +66,6 @@ using comptr = Microsoft::WRL::ComPtr; #include "../graphics/device.hpp" #include "../graphics/adapter.hpp" #include "../graphics/blendstate.hpp" -#include "../graphics/buffer.hpp" #include "../graphics/depthstencilstate.hpp" #include "../graphics/displaymode.hpp" #include "../graphics/sprite.hpp" @@ -77,7 +76,6 @@ using comptr = Microsoft::WRL::ComPtr; #include "../input/mouse.hpp" #include "../graphics/rasterizerstate.hpp" #include "../graphics/presentparams.hpp" -#include "../graphics/shader.hpp" #include "../graphics/swapchain.hpp" #include "../graphics/texture.hpp" #include "../graphics/rendertarget.hpp" @@ -541,22 +539,7 @@ namespace xna { D3D11_BLEND_DESC dxDescription{}; float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F }; UINT sampleMask{ 0xffffffff }; - }; - - struct ConstantBuffer::PlatformImplementation { - D3D11_BUFFER_DESC _description{}; - D3D11_SUBRESOURCE_DATA _subResource{}; - comptr _buffer = nullptr; - DirectX::XMMATRIX _worldViewProjection{}; - }; - - struct DataBuffer::PlatformImplementation { - comptr _blob = nullptr; - - void Set(comptr const& blob) { - _blob = blob; - } - }; + }; struct DepthStencilState::PlatformImplementation { comptr dxDepthStencil = nullptr; @@ -611,10 +594,6 @@ namespace xna { } }; - struct IndexBuffer::PlatformImplementation { - comptr dxBuffer = nullptr; - }; - struct Keyboard::PlatformImplementation { uptr _dxKeyboard = unew(); @@ -641,15 +620,7 @@ namespace xna { struct SamplerState::PlatformImplementation { comptr _samplerState = nullptr; D3D11_SAMPLER_DESC _description{}; - }; - - struct VertexShader::PlatformImplementation { - comptr _vertexShader = nullptr; - }; - - struct PixelShader::PlatformImplementation { - comptr _pixelShader = nullptr; - }; + }; struct SwapChain::PlatformImplementation { comptr dxSwapChain{ nullptr }; @@ -677,17 +648,7 @@ namespace xna { struct RenderTarget2D::PlatformImplementation { comptr _renderTargetView = nullptr; D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{}; - }; - - struct VertexBuffer::PlatformImplementation { - comptr dxBuffer = nullptr; - UINT size{ 0 }; - }; - - struct VertexInputLayout::PlatformImplementation { - comptr _inputLayout{ nullptr }; - std::vector _description{}; - }; + }; enum class GameWindowMode : UINT { Fullscreen = WS_POPUP | WS_VISIBLE, @@ -887,54 +848,6 @@ namespace xna { struct EffectParameter::PlatformImplementation { comptr dxVariable = nullptr; - }; - - template - inline bool IndexBuffer::Initialize(std::vector const& data) { - if (!impl || !m_device || !m_device->impl->_device || data.empty()) { - Exception::Throw(ExMessage::InitializeComponent); - } - - if (impl->dxBuffer) { - impl->dxBuffer = nullptr; - } - - const auto hr = DirectX::CreateStaticBuffer( - m_device->impl->_device.Get(), - data.data(), - data.size(), - sizeof(T), - D3D11_BIND_INDEX_BUFFER, - impl->dxBuffer.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - return true; - } - - template - inline bool VertexBuffer::Initialize(std::vector const& data) { - if (!impl || !m_device || !m_device->impl->_device || data.empty()) { - Exception::Throw(ExMessage::InitializeComponent); - } - - const auto hr = DirectX::CreateStaticBuffer( - m_device->impl->_device.Get(), - data.data(), - data.size(), - sizeof(T), - D3D11_BIND_VERTEX_BUFFER, - impl->dxBuffer.GetAddressOf()); - - if (FAILED(hr)) { - Exception::Throw(ExMessage::CreateComponent); - } - - impl->size = sizeof(T); - - return true; - } + }; } #endif \ No newline at end of file diff --git a/inc/xna/xna.hpp b/inc/xna/xna.hpp index fe1fe83..fdb60a7 100644 --- a/inc/xna/xna.hpp +++ b/inc/xna/xna.hpp @@ -43,7 +43,6 @@ #include "graphics/rasterizerstate.hpp" #include "graphics/rendertarget.hpp" #include "graphics/samplerstate.hpp" -#include "graphics/shader.hpp" #include "graphics/sprite.hpp" #include "graphics/swapchain.hpp" #include "graphics/texture.hpp"