#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP #define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP #include "../../content/manager.hpp" #include "../../content/reader.hpp" #include "../../csharp/type.hpp" #include "graphics/texture.hpp" #include "platform-dx/implementations.hpp" namespace xna { class Texture2DReader : public ContentTypeReaderT { public: Texture2DReader() : ContentTypeReaderT(typeof()){} PTexture2D Read(ContentReader& input, PTexture2D& 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 a_device = ContentManager::Services()->GetService(*typeof()); sptr device = nullptr; if(a_device.has_value()) device = std::any_cast>(a_device); auto texture2D = New(device, width, height, mipMaps, format); for (size_t level = 0; level < mipMaps; ++level) { auto elementCount = input.ReadInt32(); std::vector data = input.ReadByteBuffer(elementCount); texture2D->SetData(static_cast(level), nullptr, data, 0, elementCount); } return texture2D; } }; } #endif