Skip to content

Commit

Permalink
main: use vao
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Rusak <[email protected]>
  • Loading branch information
lrusak committed May 25, 2023
1 parent 3b67fc9 commit 2635dea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2635dea

Please sign in to comment.