Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use VAO #71

Open
wants to merge 2 commits into
base: Omega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 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,11 +187,14 @@ void CMyAddon::Stop()
SAFE_DELETE(m_timer);

#ifndef WIN32
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &m_vertexVBO);
m_vertexVBO = 0;

delete m_VertBuf;

#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