mirror of
https://github.com/CDevJoud/Minecraft-Community-Edition.git
synced 2026-07-16 08:51:13 +00:00
added texture
This commit is contained in:
27
Minecraft-Community-Edition/Graphics/Texture.cpp
Normal file
27
Minecraft-Community-Edition/Graphics/Texture.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user