1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/inc/platform-dx/content-readers/texture2Dreader-dx.hpp

40 lines
1.2 KiB
C++
Raw Normal View History

2024-05-05 15:50:17 -03:00
#ifndef XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
#define XNA_PLATFORM_CONTENTREADERS_TEXTURE2D_HPP
2024-05-06 11:35:27 -03:00
#include "../../content/manager.hpp"
2024-05-07 17:27:04 -03:00
#include "../../content/reader.hpp"
2024-05-06 11:35:27 -03:00
#include "../../csharp/type.hpp"
2024-05-07 17:27:04 -03:00
#include "../texture-dx.hpp"
2024-05-05 15:50:17 -03:00
namespace xna {
2024-05-08 10:51:49 -03:00
class Texture2DReader : public ContentTypeReaderT<PTexture2D> {
public:
Texture2DReader() : ContentTypeReaderT(typeof<Texture2D>()){}
2024-05-08 10:51:49 -03:00
PTexture2D Read(ContentReader& input, PTexture2D& 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>());
2024-05-07 17:27:04 -03:00
sptr<GraphicsDevice> device = nullptr;
if(a_device.has_value())
device = std::any_cast<sptr<GraphicsDevice>>(a_device);
2024-05-06 11:35:27 -03:00
2024-05-06 15:57:09 -03:00
auto texture2D = New<Texture2D>(device, width, height, mipMaps, format);
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-07 17:27:04 -03:00
texture2D->SetData(static_cast<Int>(level), nullptr, data, 0, elementCount);
}
2024-05-05 15:50:17 -03:00
return texture2D;
}
};
}
#endif