Cleanup font on destruction
This commit is contained in:
parent
d38e19471e
commit
0beb844668
3 changed files with 32 additions and 6 deletions
|
@ -80,8 +80,8 @@ void Font::load(const shared_ptr<Texture> &texture) {
|
|||
}
|
||||
}
|
||||
|
||||
void Font::initGL() {
|
||||
if (_glInited) return;
|
||||
void Font::init() {
|
||||
if (_inited) return;
|
||||
|
||||
glGenBuffers(1, &_vertexBufferId);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferId);
|
||||
|
@ -107,7 +107,30 @@ void Font::initGL() {
|
|||
|
||||
glBindVertexArray(0);
|
||||
|
||||
_glInited = true;
|
||||
_inited = true;
|
||||
}
|
||||
|
||||
Font::~Font() {
|
||||
deinit();
|
||||
}
|
||||
|
||||
void Font::deinit() {
|
||||
if (!_inited) return;
|
||||
|
||||
if (_vertexArrayId) {
|
||||
glDeleteVertexArrays(1, &_vertexArrayId);
|
||||
_vertexArrayId = 0;
|
||||
}
|
||||
if (_vertexBufferId) {
|
||||
glDeleteBuffers(1, &_vertexBufferId);
|
||||
_vertexBufferId = 0;
|
||||
}
|
||||
if (_indexBufferId) {
|
||||
glDeleteBuffers(1, &_indexBufferId);
|
||||
_indexBufferId = 0;
|
||||
}
|
||||
|
||||
_inited = false;
|
||||
}
|
||||
|
||||
void Font::draw(const string &text, const glm::mat4 &transform, const glm::vec3 &color, TextGravity gravity) {
|
||||
|
|
|
@ -40,9 +40,12 @@ enum class TextGravity {
|
|||
class Font {
|
||||
public:
|
||||
Font() = default;
|
||||
~Font();
|
||||
|
||||
void init();
|
||||
void deinit();
|
||||
|
||||
void load(const std::shared_ptr<Texture> &texture);
|
||||
void initGL();
|
||||
|
||||
void draw(
|
||||
const std::string &text,
|
||||
|
@ -55,7 +58,7 @@ public:
|
|||
float height() const { return _height; }
|
||||
|
||||
private:
|
||||
bool _glInited { false };
|
||||
bool _inited { false };
|
||||
std::vector<float> _vertices;
|
||||
std::vector<uint16_t> _indices;
|
||||
int _glyphCount { 0 };
|
||||
|
|
|
@ -55,7 +55,7 @@ shared_ptr<Font> Fonts::doGet(string resRef) {
|
|||
auto font = make_shared<Font>();
|
||||
font->load(texture);
|
||||
if (font) {
|
||||
font->initGL();
|
||||
font->init();
|
||||
}
|
||||
|
||||
return move(font);
|
||||
|
|
Loading…
Reference in a new issue