2024-05-05 15:50:17 -03:00
|
|
|
#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
|
|
|
#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
|
|
|
|
|
|
|
|
#include "../../content/reader.hpp"
|
|
|
|
#include "../texture-dx.hpp"
|
2024-05-06 11:35:27 -03:00
|
|
|
#include "../../content/manager.hpp"
|
|
|
|
#include "../../csharp/type.hpp"
|
2024-05-05 15:50:17 -03:00
|
|
|
|
|
|
|
namespace xna {
|
|
|
|
class Texture2DReader : public ContentTypeReaderT<Texture2D> {
|
2024-05-06 09:58:40 -03:00
|
|
|
public:
|
|
|
|
Texture2DReader() : ContentTypeReaderT(typeof<Texture2D>()){}
|
|
|
|
|
2024-05-06 11:35:27 -03:00
|
|
|
sptr<Texture2D> Read(ContentReader& input, Texture2D& existingInstance) override{
|
2024-05-05 15:50:17 -03:00
|
|
|
const auto format = static_cast<SurfaceFormat>(input.ReadInt32());
|
|
|
|
const auto width = input.ReadInt32();
|
|
|
|
const auto height = input.ReadInt32();
|
|
|
|
const auto mipMaps = input.ReadInt32();
|
2024-05-06 11:35:27 -03:00
|
|
|
|
|
|
|
auto a_device = ContentManager::Services()->GetService(*typeof<GraphicsDevice>());
|
|
|
|
auto device = std::any_cast<sptr<GraphicsDevice>>(a_device);
|
|
|
|
|
|
|
|
auto texture2D = New<Texture2D>(device.get(), width, height, mipMaps, format);
|
2024-05-06 09:58:40 -03:00
|
|
|
|
2024-05-05 15:50:17 -03:00
|
|
|
for (size_t level = 0; level < mipMaps; ++level) {
|
|
|
|
auto elementCount = input.ReadInt32();
|
|
|
|
std::vector<Byte> data = input.ReadByteBuffer(elementCount);
|
|
|
|
|
2024-05-06 11:35:27 -03:00
|
|
|
texture2D->SetData(level, nullptr, data, 0, elementCount);
|
2024-05-06 09:58:40 -03:00
|
|
|
}
|
2024-05-05 15:50:17 -03:00
|
|
|
|
|
|
|
return texture2D;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|