diff --git a/framework/content/manager.hpp b/framework/content/manager.hpp index 05db4f7..d69dbf8 100644 --- a/framework/content/manager.hpp +++ b/framework/content/manager.hpp @@ -1,15 +1,18 @@ #ifndef XNA_CONTENT_MANAGER_HPP #define XNA_CONTENT_MANAGER_HPP +#include "../csharp/stream.hpp" #include "../default.hpp" +#include "reader.hpp" +#include #include #include -#include -#include "../csharp/stream.hpp" namespace xna { class ContentManager { public: + friend class ContentReader; + ContentManager(String const& rootDirectory) : _rootDirectory(rootDirectory), _path(rootDirectory){}; @@ -35,7 +38,7 @@ namespace xna { } template - sptr Load(String const& assetName) { + T Load(String const& assetName) { if (assetName.empty()) return nullptr; if (_loadedAssets.contains(assetName)) { @@ -69,6 +72,7 @@ namespace xna { std::filesystem::path _path; std::map> _loadedAssets; inline const static String contentExtension = ".xnb"; + std::vector byteBuffer; }; } diff --git a/framework/content/reader.cpp b/framework/content/reader.cpp index e108343..df63c50 100644 --- a/framework/content/reader.cpp +++ b/framework/content/reader.cpp @@ -2,6 +2,7 @@ #include "manager.hpp" #include "lzx/decoderstream.hpp" #include "typereadermanager.hpp" +#include "manager.hpp" namespace xna { sptr ContentReader::Create(ContentManager* contentManager, sptr& input, String const& assetName) @@ -88,6 +89,29 @@ namespace xna { return *(double*)&int64; } + std::vector ContentReader::ReadByteBuffer(size_t size, xna_error_ptr_arg) + { + std::vector& buffer = _contentManager->byteBuffer; + + if (buffer.empty() || buffer.size() < size) + { + buffer = std::vector(size); + //_contentManager->byteBuffer = buffer; + } + + Int num = 0; + for (size_t index = 0; index < size; index += num) + { + num = Read(buffer, index, size - index); + if (num == 0) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return std::vector(); + } + } + + return buffer; + } + sptr ContentReader::PrepareStream(sptr& input, String const& assetName, Int& graphicsProfile) { BinaryReader binaryReader = BinaryReader(input); diff --git a/framework/content/reader.hpp b/framework/content/reader.hpp index 0f8fc77..c521be1 100644 --- a/framework/content/reader.hpp +++ b/framework/content/reader.hpp @@ -1,15 +1,15 @@ #ifndef XNA_CONTENT_READER_HPP #define XNA_CONTENT_READER_HPP -#include "../default.hpp" -#include "../csharp/binary.hpp" -#include "../csharp/type.hpp" -#include "typereadermanager.hpp" -#include -#include "../common/vectors.hpp" +#include "../common/color.hpp" #include "../common/matrix.hpp" #include "../common/quaternion.hpp" -#include "../common/color.hpp" +#include "../common/vectors.hpp" +#include "../csharp/binary.hpp" +#include "../csharp/type.hpp" +#include "../default.hpp" +#include "typereadermanager.hpp" +#include namespace xna { class ContentReader : public BinaryReader, public std::enable_shared_from_this{ @@ -34,6 +34,8 @@ namespace xna { float ReadSingle(); double ReadDouble(); + std::vector ReadByteBuffer(size_t size, xna_error_nullarg); + private: ContentReader(ContentManager* contentManager, sptr& input, String const& assetName, Int graphicsProfile) : BinaryReader(input), _contentManager(contentManager), _assetName(assetName){} diff --git a/framework/content/typereadermanager.hpp b/framework/content/typereadermanager.hpp index 79a812f..9bab3c2 100644 --- a/framework/content/typereadermanager.hpp +++ b/framework/content/typereadermanager.hpp @@ -41,7 +41,7 @@ namespace xna { return std::any(); } - virtual T Read(ContentReader& input, T existingInstance) = 0; + virtual T Read(ContentReader& input, T& existingInstance) = 0; }; //-------------------------------------------------------// @@ -175,7 +175,7 @@ namespace xna { }); } - virtual Object Read(ContentReader& input, Object existingInstance) override { + virtual Object Read(ContentReader& input, Object& existingInstance) override { return Object(); } }; diff --git a/framework/csharp/binary.cpp b/framework/csharp/binary.cpp index 03c60ce..fffdee9 100644 --- a/framework/csharp/binary.cpp +++ b/framework/csharp/binary.cpp @@ -683,6 +683,11 @@ namespace xna { return InternalReadChars(buffer.data(), buffer.size(), index, count, err); } + Int BinaryReader::Read(std::vector& buffer, size_t index, size_t count, xna_error_ptr_arg) + { + auto data = reinterpret_cast(buffer.data()); + return InternalReadChars(data, buffer.size(), index, count, err); + } std::vector BinaryReader::ReadBytes(size_t count, xna_error_ptr_arg) { std::vector result(count); diff --git a/framework/csharp/binary.hpp b/framework/csharp/binary.hpp index 9721817..1c9cea3 100644 --- a/framework/csharp/binary.hpp +++ b/framework/csharp/binary.hpp @@ -29,6 +29,7 @@ namespace xna { std::string ReadString(xna_error_nullarg); Int Read(std::vector& buffer, size_t index, size_t count, xna_error_nullarg); + Int Read(std::vector& buffer, size_t index, size_t count, xna_error_nullarg); std::vector ReadBytes(size_t count, xna_error_nullarg); diff --git a/framework/platform/content-readers/texture2Dreader-dx.hpp b/framework/platform/content-readers/texture2Dreader-dx.hpp new file mode 100644 index 0000000..ca930a3 --- /dev/null +++ b/framework/platform/content-readers/texture2Dreader-dx.hpp @@ -0,0 +1,28 @@ +#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP +#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP + +#include "../../content/reader.hpp" +#include "../texture-dx.hpp" + +namespace xna { + class Texture2DReader : public ContentTypeReaderT { + Texture2D Read(ContentReader& input, Texture2D& existingInstance) override{ + const auto format = static_cast(input.ReadInt32()); + const auto width = input.ReadInt32(); + const auto height = input.ReadInt32(); + const auto mipMaps = input.ReadInt32(); + auto texture2D = Texture2D(nullptr, width, height, mipMaps, format); + + for (size_t level = 0; level < mipMaps; ++level) { + auto elementCount = input.ReadInt32(); + std::vector data = input.ReadByteBuffer(elementCount); + + texture2D.SetData(level, nullptr, data, 0, elementCount); + } + + return texture2D; + } + }; +} + +#endif \ No newline at end of file diff --git a/framework/platform/dxheaders.hpp b/framework/platform/dxheaders.hpp index a2fc464..c08436a 100644 --- a/framework/platform/dxheaders.hpp +++ b/framework/platform/dxheaders.hpp @@ -1,9 +1,33 @@ +//DirectX #include "dxgi.h" #include "d3d11.h" #include #include +//HSLS #include +//DirectXTK #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//Windows #define NOMINMAX #include #include diff --git a/framework/platform/spritebatch-dx.cpp b/framework/platform/spritebatch-dx.cpp index e01457c..0345150 100644 --- a/framework/platform/spritebatch-dx.cpp +++ b/framework/platform/spritebatch-dx.cpp @@ -63,7 +63,7 @@ namespace xna { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; const auto _position = XMFLOAT2(position.X, position.Y); @@ -71,7 +71,7 @@ namespace xna { XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W }; _dxspriteBatch->Draw( - texture.dxShaderResourceView, + texture.dxShaderResource, _position, _color ); @@ -81,7 +81,7 @@ namespace xna { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; const auto _position = XMFLOAT2(position.X, position.Y); @@ -98,7 +98,7 @@ namespace xna { }; _dxspriteBatch->Draw( - texture.dxShaderResourceView, + texture.dxShaderResource, _position, sourceRectangle ? &_sourceRect : nullptr, _color); @@ -108,7 +108,7 @@ namespace xna { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; const auto _position = XMFLOAT2(position.X, position.Y); @@ -128,7 +128,7 @@ namespace xna { const DxSpriteEffects _effects = static_cast(effects); _dxspriteBatch->Draw( - texture.dxShaderResourceView, + texture.dxShaderResource, _position, sourceRectangle ? &_sourceRect : nullptr, _color, @@ -143,7 +143,7 @@ namespace xna { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; const auto _position = XMFLOAT2(position.X, position.Y); @@ -164,7 +164,7 @@ namespace xna { const XMFLOAT2 _scale = { scale.X, scale.Y }; _dxspriteBatch->Draw( - texture.dxShaderResourceView, + texture.dxShaderResource, _position, sourceRectangle ? &_sourceRect : nullptr, _color, @@ -179,7 +179,7 @@ namespace xna { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; RECT _destinationRect{}; @@ -191,14 +191,14 @@ namespace xna { const auto v4 = color.ToVector4(); const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W }; - _dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, _color); + _dxspriteBatch->Draw(texture.dxShaderResource, _destinationRect, _color); } void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; RECT _destinationRect{}; @@ -219,14 +219,14 @@ namespace xna { _sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height; }; - _dxspriteBatch->Draw(texture.dxShaderResourceView, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color); + _dxspriteBatch->Draw(texture.dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color); } void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) { if (!_dxspriteBatch) return; - if (!texture.dxShaderResourceView) + if (!texture.dxShaderResource) return; RECT _destinationRect{}; @@ -251,7 +251,7 @@ namespace xna { const auto _effects = static_cast(effects); _dxspriteBatch->Draw( - texture.dxShaderResourceView, + texture.dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color, diff --git a/framework/platform/texture-dx.cpp b/framework/platform/texture-dx.cpp index 8e2a5e0..e5b602d 100644 --- a/framework/platform/texture-dx.cpp +++ b/framework/platform/texture-dx.cpp @@ -1,7 +1,6 @@ #include "texture-dx.hpp" -#include "WICTextureLoader.h" #include "device-dx.hpp" -#include "../helpers.hpp" +#include "adapter-dx.hpp" namespace xna { sptr Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) @@ -15,7 +14,7 @@ namespace xna { device._context, wstr.c_str(), &resource, - &texture2d->dxShaderResourceView, + &texture2d->dxShaderResource, 0U); if (FAILED(result)) @@ -80,7 +79,7 @@ namespace xna { return false; } - hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDecription, &dxShaderResourceView); + hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource); if (resource) { resource->Release(); @@ -94,4 +93,233 @@ namespace xna { return true; } + + Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height) : GraphicsResource(device) { + setDefaultDesc(); + dxDescription.Width = static_cast(width); + dxDescription.Height = static_cast(height); + } + + Texture2D::Texture2D(GraphicsDevice* device) : GraphicsResource(device) { + setDefaultDesc(); + } + + Texture2D::Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format) : GraphicsResource(device) + { + setDefaultDesc(); + dxDescription.Width = static_cast(width); + dxDescription.Height = static_cast(height); + dxDescription.MipLevels = static_cast(mipMap); + dxDescription.Format = GraphicsAdapter::ConvertSurfaceToDXGIFORMAT(format); + } + + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + { + if (!m_device || !m_device->_device || !m_device->_context) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + internalSetData(data.data(), err); + } + + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + { + if (!m_device || !m_device->_device || !m_device->_context) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + std::vector finalData(elementCount / 4); + auto fIndex = 0; + + for (size_t i = startIndex; i < elementCount; ++i) { + const auto& r = data[i]; + const auto& g = data[++i]; + const auto& b = data[++i]; + const auto& a = data[++i]; + finalData[fIndex] = Color(r, g, b, a); + ++fIndex; + } + + internalSetData(finalData.data(), err); + } + + void Texture2D::SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + { + if (!m_device || !m_device->_device || !m_device->_context) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + std::vector finalData(elementCount / 4); + auto fIndex = 0; + + for (size_t i = startIndex; i < elementCount; ++i) { + const auto& r = data[i]; + const auto& g = data[++i]; + const auto& b = data[++i]; + const auto& a = data[++i]; + finalData[fIndex] = Color(r, g, b, a); + ++fIndex; + } + + if (!dxTexture2D) { + auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D); + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + } + + ID3D11Resource* resource = nullptr; + auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + + D3D11_BOX box{}; + + if (rect) { + box.left = rect->X; + box.right = rect->X + rect->Width; + box.top = rect->Y; + box.bottom = rect->Y + rect->Height; + box.back = level; + box.front = 0; + } + + m_device->_context->UpdateSubresource(resource, 0, rect ? &box : nullptr, finalData.data(), dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); + + if (dxShaderResource) { + dxShaderResource->Release(); + dxShaderResource = nullptr; + } + + dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels; + hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource); + + if (resource) { + resource->Release(); + resource = nullptr; + } + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + + dxTexture2D->GetDesc(&dxDescription); + } + + void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) + { + if (!m_device || !m_device->_device || !m_device->_context) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return; + } + + std::vector finalData(elementCount); + auto finalDataIndex = 0; + + for (size_t i = startIndex; i < elementCount; ++i) { + finalData[finalDataIndex] = static_cast(data[i]); + ++finalDataIndex; + } + + internalSetData(finalData.data(), err); + } + + sptr Texture2D::FromMemory(GraphicsDevice& device, std::vector const& data, xna_error_ptr_arg) + { + auto texture2d = New(&device); + ID3D11Resource* resource = nullptr; + + auto hr = DirectX::CreateWICTextureFromMemory( + device._device, + device._context, + data.data(), + data.size(), + &resource, + &texture2d->dxShaderResource); + + if (FAILED(hr)) + { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + + if (resource) { + resource->Release(); + resource = nullptr; + } + + return nullptr; + } + + hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->dxTexture2D); + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + + if (resource) { + resource->Release(); + resource = nullptr; + } + + return nullptr; + } + + D3D11_TEXTURE2D_DESC desc; + texture2d->dxTexture2D->GetDesc(&desc); + texture2d->dxDescription = desc; + + resource->Release(); + resource = nullptr; + + return texture2d; + } + + void Texture2D::internalSetData(UINT const* data, xna_error_ptr_arg) + { + if (!dxTexture2D) { + auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D); + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + } + + ID3D11Resource* resource = nullptr; + auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + + m_device->_context->UpdateSubresource(resource, 0, nullptr, data, dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); + + if (dxShaderResource) { + dxShaderResource->Release(); + dxShaderResource = nullptr; + } + + dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels; + hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDescription, &dxShaderResource); + + if (resource) { + resource->Release(); + resource = nullptr; + } + + if (FAILED(hr)) { + xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); + return; + } + + dxTexture2D->GetDesc(&dxDescription); + } } \ No newline at end of file diff --git a/framework/platform/texture-dx.hpp b/framework/platform/texture-dx.hpp index 1cbe9e0..faccacf 100644 --- a/framework/platform/texture-dx.hpp +++ b/framework/platform/texture-dx.hpp @@ -2,27 +2,17 @@ #define XNA_PLATFORM_TEXTURE_DX_HPP #include "../common/rectangle.hpp" -#include "../csharp/buffer.hpp" -#include "../graphics/texture.hpp" -#include "../xnaerror.hpp" -#include "dxheaders.hpp" -#include #include "../graphics/gresource.hpp" +#include "../graphics/texture.hpp" +#include "dxheaders.hpp" #include "device-dx.hpp" -#include namespace xna { class Texture2D : public ITexture2D, public GraphicsResource { public: - Texture2D(GraphicsDevice* device, size_t width, size_t height) : GraphicsResource(device) { - dxDescription.Width = static_cast(width); - dxDescription.Height = static_cast(height); - setDefaultDesc(); - } - - Texture2D(GraphicsDevice* device) : GraphicsResource(device) { - setDefaultDesc(); - } + Texture2D(GraphicsDevice* device); + Texture2D(GraphicsDevice* device, size_t width, size_t height); + Texture2D(GraphicsDevice* device, size_t width, size_t height, size_t mipMap, SurfaceFormat format); virtual ~Texture2D() override { if (dxTexture2D) { @@ -30,9 +20,9 @@ namespace xna { dxTexture2D = nullptr; } - if (dxShaderResourceView) { - dxShaderResourceView->Release(); - dxShaderResourceView = nullptr; + if (dxShaderResource) { + dxShaderResource->Release(); + dxShaderResource = nullptr; } } @@ -48,22 +38,23 @@ namespace xna { return { 0, 0, static_cast(dxDescription.Width), static_cast(dxDescription.Height) }; } - bool Initialize(xna_error_nullarg) override; - - template - void SetData(std::vector const& data, xna_error_ptr_arg); - - template - void SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_nullarg); + bool Initialize(xna_error_nullarg) override; + + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); + void SetData(std::vector const& data, size_t startIndex = 0, size_t elementCount = 0, xna_error_nullarg); + + void SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount, xna_error_nullarg); static sptr FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg); + static sptr FromMemory(GraphicsDevice& device, std::vector const& data, xna_error_nullarg); public: ID3D11Texture2D* dxTexture2D{ nullptr }; - ID3D11ShaderResourceView* dxShaderResourceView{ nullptr }; + ID3D11ShaderResourceView* dxShaderResource{ nullptr }; D3D11_SUBRESOURCE_DATA dxSubResource{}; D3D11_TEXTURE2D_DESC dxDescription{}; - D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDecription{}; + D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{}; private: static constexpr int R8G8B8A8U_BYTE_SIZE = 4; @@ -76,72 +67,14 @@ namespace xna { dxDescription.Usage = D3D11_USAGE_DEFAULT; dxDescription.BindFlags = D3D11_BIND_SHADER_RESOURCE; - dxShaderDecription.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - dxShaderDecription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - dxShaderDecription.Texture2D.MipLevels = dxDescription.MipLevels; - dxShaderDecription.Texture2D.MostDetailedMip = 0; - } - }; - - template - inline void Texture2D::SetData(std::vector const& data, xna_error_ptr_arg) { - SetData(data, 0, data.size(), err); - } - - template - inline void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount, xna_error_ptr_arg) { - if (!m_device || !m_device->_device || !m_device->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return; + dxShaderDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + dxShaderDescription.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + dxShaderDescription.Texture2D.MipLevels = dxDescription.MipLevels; + dxShaderDescription.Texture2D.MostDetailedMip = 0; } - std::vector finalData(elementCount); - auto finalDataIndex = 0; - - for (size_t i = startIndex; i < elementCount; ++i) { - finalData[finalDataIndex] = static_cast(data[i]); - ++finalDataIndex; - } - - if (!dxTexture2D) { - auto hr = m_device->_device->CreateTexture2D(&dxDescription, nullptr, &dxTexture2D); - - if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; - } - } - - ID3D11Resource* resource = nullptr; - auto hr = dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); - - if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; - } - - dxShaderDecription.Texture2D.MipLevels = dxDescription.MipLevels; - m_device->_context->UpdateSubresource(resource, 0, nullptr, finalData.data(), dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); - - if (dxShaderResourceView) { - dxShaderResourceView->Release(); - dxShaderResourceView = nullptr; - } - - hr = m_device->_device->CreateShaderResourceView(resource, &dxShaderDecription, &dxShaderResourceView); - - if (resource) { - resource->Release(); - resource = nullptr; - } - - if (FAILED(hr)) { - xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); - return; - } - - dxTexture2D->GetDesc(&dxDescription); - } + void internalSetData(UINT const* data, xna_error_nullarg); + }; } #endif \ No newline at end of file diff --git a/framework/xna.cpp b/framework/xna.cpp index 2746e92..db6b1ad 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -14,6 +14,7 @@ namespace xna { graphics = New(_game); graphics->PreferredBackBufferWidth(1280); graphics->PreferredBackBufferHeight(720); + contentManager = New("Content"); } void Initialize() override { @@ -26,11 +27,12 @@ namespace xna { XnaErrorCode err{0}; //texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err); - texture = New(_graphicsDevice.get(), 256, 256); - std::vector data(256 * 256, 4278190080U); + //texture = New(_graphicsDevice.get(), 256, 256); + //std::vector data(256 * 256, 4278190080U); //std::vector data(256 * 256, 0xffffffff); //std::vector data(256 * 256, 4278190080U); - texture->SetData(data, 0, data.size()); + //texture->SetData(data, 0, data.size()); + //Texture2D tx = contentManager->Load("Idle"); Game::LoadContent(); } @@ -46,7 +48,7 @@ namespace xna { _graphicsDevice->Clear(Colors::CornflowerBlue); spriteBatch->Begin(); - spriteBatch->Draw(*texture, position, Colors::White); + //spriteBatch->Draw(*texture, position, Colors::White); spriteBatch->End(); Game::Draw(gameTime);