From a92ca606affd502e85817bf2361e8b5ad9a92fce Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 24 Apr 2026 19:01:02 +0300 Subject: [PATCH 1/3] deleting shader program upon destruction --- shader.cpp | 4 ++++ shader.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/shader.cpp b/shader.cpp index 4a63f0c..6779cd2 100755 --- a/shader.cpp +++ b/shader.cpp @@ -33,6 +33,10 @@ namespace vb01{ loadShaders(); } + Shader::~Shader(){ + glDeleteProgram(id); + } + string Shader::getName(){ int dirId = vString->path.find_last_of('/'); string name = (dirId != -1 ? vString->path.substr(dirId + 1) : vString->path); diff --git a/shader.h b/shader.h index 15ea0a0..1047b07 100755 --- a/shader.h +++ b/shader.h @@ -18,7 +18,7 @@ namespace vb01{ Shader(std::string, bool = false); Shader(std::string, std::string); Shader(std::string, std::string, std::string); - ~Shader(){} + ~Shader(); std::string getName(); void use(); void loadShaders(); From 6c5e0b27372167f92d97c458fcf8c3cd9efe6bfb Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 24 Apr 2026 19:08:26 +0300 Subject: [PATCH 2/3] generating VAO and VBO only once --- text.cpp | 33 +++++++++++++++++---------------- text.h | 3 ++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/text.cpp b/text.cpp index 6e12df8..2d0c334 100755 --- a/text.cpp +++ b/text.cpp @@ -16,9 +16,9 @@ using namespace std; namespace vb01{ - Text::Text(string fontPath, wstring entry, u16 firstChar, u16 lastChar){ + Text::Text(string fontPath, wstring e, u16 firstChar, u16 lastChar) : entry(e){ + init(); applyFont(fontPath, firstChar, lastChar); - setText(entry); } Text::~Text(){ @@ -26,6 +26,21 @@ namespace vb01{ glDeleteBuffers(1, &VBO); } + void Text::init(){ + glGenVertexArrays(1, &VAO); + glGenBuffers(1, &VBO); + + glBindVertexArray(VAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6 * 4, NULL, GL_DYNAMIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + } + //TODO ensure destruction of textures when unloading the asset void Text::applyFont(string fontPath, u16 firstChar, u16 lastChar){ characters.clear(); @@ -120,20 +135,6 @@ namespace vb01{ glDrawArrays(GL_TRIANGLES, 0, 6); } - void Text::setText(wstring text){ - this->entry = text; - - glGenVertexArrays(1, &VAO); - glGenBuffers(1, &VBO); - glBindVertexArray(VAO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6 * 4, NULL, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); - } - Text::Glyph* Text::getGlyph(u16 ch){ Glyph *glyph = nullptr; diff --git a/text.h b/text.h index 9d1780d..e19a481 100755 --- a/text.h +++ b/text.h @@ -26,7 +26,7 @@ namespace vb01{ Text(std::string, std::wstring, u16 = 0, u16 = 256); ~Text(); void update(); - void setText(std::wstring); + void setText(std::wstring e){this->entry = e;} inline void setScale(float s){this->scale = s;} inline float getScale(){return scale;} inline int getLength(){return entry.length();} @@ -39,6 +39,7 @@ namespace vb01{ inline void setMaterial(Material *mat){this->material = mat;} Glyph* getGlyph(u16); private: + void init(); void applyFont(std::string, u16, u16 = 256); void clearFont(); void prepareGlyphs(Glyph, int, Vector2); From 7f8b6fe03a48a8579286fb75404d96dcb2b9bdea Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 24 Apr 2026 19:08:59 +0300 Subject: [PATCH 3/3] added missing commit --- model.h | 1 + 1 file changed, 1 insertion(+) diff --git a/model.h b/model.h index b889925..d6273f4 100755 --- a/model.h +++ b/model.h @@ -21,6 +21,7 @@ namespace vb01{ Model(std::string); ~Model(); inline Material* getMaterial(){return material;} + inline bool isWireframe(){return wireframe;} void update(); void setMaterial(Material*); void setCastShadow(bool);