diff --git a/Minecraft-Community-Edition/Graphics/Texture.cpp b/Minecraft-Community-Edition/Graphics/Texture.cpp new file mode 100644 index 0000000..b543748 --- /dev/null +++ b/Minecraft-Community-Edition/Graphics/Texture.cpp @@ -0,0 +1,27 @@ +#include "Texture.hpp" +#include + +namespace mce::gfx { + Texture::Texture(const bgfx::Memory* tag, bool& success) { + sf::Image img; + + if (img.loadFromMemory(tag->data, tag->size)) { + const bgfx::Memory* mem = bgfx::copy(img.getPixelsPtr(), img.getSize().x * img.getSize().y * 4); + Texture::size = img.getSize(); + Texture::texture = bgfx::createTexture2D(size.x, size.y, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_NONE, mem); + success = bgfx::isValid(Texture::texture); + } + else { + success = false; + } + } + Texture::~Texture() { + if (bgfx::isValid(Texture::texture)) { + bgfx::destroy(Texture::texture); + Texture::texture = BGFX_INVALID_HANDLE; + } + } + bgfx::TextureHandle Texture::getTextureHandle() const { + return Texture::texture; + } +}