added texture

This commit is contained in:
Joud Kandeel
2026-04-20 21:49:09 +02:00
parent b2bdc37f0e
commit 3a74f8a17a

View File

@@ -0,0 +1,27 @@
#include "Texture.hpp"
#include <SFML/Graphics/Image.hpp>
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;
}
}