From 3b67fc9e28d1c8b43084f64bddc05a5128f962de Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 25 May 2023 13:27:48 -0700 Subject: [PATCH 1/2] use delete[] for array Signed-off-by: Lukas Rusak --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 85e4701..809dbea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,7 +187,7 @@ void CMyAddon::Stop() glDeleteBuffers(1, &m_vertexVBO); m_vertexVBO = 0; - delete m_VertBuf; + delete[] m_VertBuf; m_VertBuf = nullptr; #endif } From 2635dea8441992a2bb787f3dc9ed2e91d7d12ef1 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 20 Apr 2023 11:06:48 -0700 Subject: [PATCH 2/2] main: use vao Signed-off-by: Lukas Rusak --- src/main.cpp | 23 +++++++++++++++++++++-- src/main.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 809dbea..08c4359 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -108,6 +108,10 @@ bool CMyAddon::Start() if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink()) return false; +#if defined(HAS_GL) + glGenVertexArrays(1, &m_vao); +#endif + glGenBuffers(1, &m_vertexVBO); m_VertBuf = new TRenderVertex[10000]; @@ -183,10 +187,13 @@ void CMyAddon::Stop() SAFE_DELETE(m_timer); #ifndef WIN32 - glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &m_vertexVBO); m_vertexVBO = 0; - + +#if defined(HAS_GL) + glDeleteVertexArrays(1, &m_vao); +#endif + delete[] m_VertBuf; m_VertBuf = nullptr; #endif @@ -212,6 +219,10 @@ bool CMyAddon::Draw() return true; #ifndef WIN32 +#if defined(HAS_GL) + glBindVertexArray(m_vao); +#endif + glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(TRenderVertex)*m_NumLines * 2, m_VertBuf, GL_STATIC_DRAW); @@ -226,6 +237,14 @@ bool CMyAddon::Draw() glDrawArrays(GL_LINES, 0, m_NumLines * 2); DisableShader(); + glDisableVertexAttribArray(m_aColor); + glDisableVertexAttribArray(m_aPosition); + glBindBuffer(GL_ARRAY_BUFFER, 0); + +#if defined(HAS_GL) + glBindVertexArray(0); +#endif + m_Verts = m_VertBuf; #else m_pContext->Unmap(m_pVBuffer, 0); diff --git a/src/main.h b/src/main.h index 94e42f3..04abcb2 100644 --- a/src/main.h +++ b/src/main.h @@ -73,6 +73,7 @@ class ATTR_DLL_LOCAL CMyAddon glm::mat4 m_projMat; GLuint m_vertexVBO = 0; + GLuint m_vao = 0; GLint m_uProjMatrix = -1; GLint m_aPosition = -1;