2024-05-30 17:37:40 -03:00
|
|
|
#ifndef XNA_CONTENT_READERS_GRAPHICS_HPP
|
|
|
|
#define XNA_CONTENT_READERS_GRAPHICS_HPP
|
|
|
|
|
2024-06-03 21:55:09 -03:00
|
|
|
#include "../../common/numerics.hpp"
|
|
|
|
#include "../../csharp/timespan.hpp"
|
|
|
|
#include "../../csharp/type.hpp"
|
|
|
|
#include "../../graphics/sprite.hpp"
|
|
|
|
#include "../../graphics/texture.hpp"
|
|
|
|
#include "../manager.hpp"
|
|
|
|
#include "../reader.hpp"
|
2024-11-15 12:33:06 -03:00
|
|
|
#include "../../graphics/shared.hpp"
|
2024-05-30 17:37:40 -03:00
|
|
|
|
|
|
|
namespace xna {
|
2024-11-16 12:15:40 -03:00
|
|
|
using PTexture2D = std::shared_ptr<Texture2D>;
|
|
|
|
|
2024-05-30 17:37:40 -03:00
|
|
|
class Texture2DReader : public ContentTypeReaderT<PTexture2D> {
|
|
|
|
public:
|
2024-05-31 22:30:45 -03:00
|
|
|
Texture2DReader() : ContentTypeReaderT(typeof<PTexture2D>()) {
|
|
|
|
ContentTypeReader::TargetIsValueType = false;
|
|
|
|
}
|
2024-05-30 17:37:40 -03:00
|
|
|
|
|
|
|
PTexture2D Read(ContentReader& input, PTexture2D& 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();
|
|
|
|
|
2024-06-02 20:36:41 -03:00
|
|
|
auto a_device = ContentManager::GameServiceProvider()->GetService(*typeof<GraphicsDevice>());
|
2024-05-30 17:37:40 -03:00
|
|
|
sptr<GraphicsDevice> device = nullptr;
|
|
|
|
|
|
|
|
if (a_device.has_value())
|
|
|
|
device = std::any_cast<sptr<GraphicsDevice>>(a_device);
|
|
|
|
|
2024-06-22 11:52:21 -03:00
|
|
|
auto texture2D = snew<Texture2D>(device, width, height, mipMaps, format);
|
2024-05-30 17:37:40 -03:00
|
|
|
|
|
|
|
for (size_t level = 0; level < mipMaps; ++level) {
|
|
|
|
auto elementCount = input.ReadInt32();
|
|
|
|
std::vector<Byte> data = input.ReadByteBuffer(elementCount);
|
|
|
|
|
|
|
|
texture2D->SetData(static_cast<Int>(level), nullptr, data, 0, elementCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture2D;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-15 14:15:35 -03:00
|
|
|
using PSpriteFont = std::shared_ptr<SpriteFont>;
|
2024-05-30 17:37:40 -03:00
|
|
|
class SpriteFontReader : public ContentTypeReaderT<PSpriteFont> {
|
|
|
|
public:
|
2024-05-31 22:30:45 -03:00
|
|
|
SpriteFontReader() : ContentTypeReaderT(typeof<PSpriteFont>()) {
|
|
|
|
ContentTypeReader::TargetIsValueType = false;
|
|
|
|
}
|
2024-05-30 17:37:40 -03:00
|
|
|
|
|
|
|
PSpriteFont Read(ContentReader& input, PSpriteFont& existingInstance) override {
|
2024-06-03 21:20:18 -03:00
|
|
|
const auto texture = input.ReadObject<PTexture2D>();
|
|
|
|
const auto glyphs = input.ReadObject<std::vector<Rectangle>>();
|
|
|
|
const auto cropping = input.ReadObject<std::vector<Rectangle>>();
|
|
|
|
const auto charMap = input.ReadObject<std::vector<Char>>();
|
|
|
|
const auto lineSpacing = input.ReadInt32();
|
|
|
|
const auto spacing = input.ReadSingle();
|
|
|
|
const auto kerning = input.ReadObject<std::vector<Vector3>>();
|
2024-05-30 17:37:40 -03:00
|
|
|
std::optional<Char> defaultCharacter;
|
|
|
|
|
|
|
|
if (input.ReadBoolean())
|
|
|
|
defaultCharacter = std::optional<Char>(input.ReadChar());
|
|
|
|
|
|
|
|
auto font = snew<SpriteFont>(texture, glyphs, cropping, charMap, lineSpacing, spacing, kerning, defaultCharacter);
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|