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"
|
|
|
|
|
|
|
|
namespace xna {
|
|
|
|
class Texture2DReader : public ContentTypeReaderT<Texture2D> {
|
2024-05-06 09:58:40 -03:00
|
|
|
public:
|
|
|
|
Texture2DReader() : ContentTypeReaderT(typeof<Texture2D>()){}
|
|
|
|
|
2024-05-05 15:50:17 -03:00
|
|
|
Texture2D Read(ContentReader& input, Texture2D& existingInstance) override{
|
|
|
|
const auto format = static_cast<SurfaceFormat>(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);
|
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);
|
|
|
|
|
|
|
|
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
|