| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "vertexarrayobject.h" |
| 7 |
|
| 8 |
#include "avogadrogl.h" |
| 9 |
|
| 10 |
namespace Avogadro::Rendering { |
| 11 |
|
| 12 |
VertexArrayObject::VertexArrayObject() : m_handle(0) |
| 13 |
{ |
| 14 |
// Lazy initialization - VAO will be created on first bind() |
| 15 |
// This allows the object to be constructed before GL context exists |
| 16 |
} |
| 17 |
|
| 18 |
VertexArrayObject::~VertexArrayObject() |
| 19 |
{ |
| 20 |
if (m_handle != 0) |
| 21 |
glDeleteVertexArrays(1, &m_handle); |
| 22 |
} |
| 23 |
|
| 24 |
bool VertexArrayObject::bind() |
| 25 |
{ |
| 26 |
// Lazy initialization - create VAO on first bind when GL context exists |
| 27 |
if (m_handle == 0) |
| 28 |
glGenVertexArrays(1, &m_handle); |
| 29 |
if (m_handle == 0) |
| 30 |
return false; |
| 31 |
glBindVertexArray(m_handle); |
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
void VertexArrayObject::release() |
| 36 |
{ |
| 37 |
glBindVertexArray(0); |
| 38 |
} |
| 39 |
|
| 40 |
} // namespace Avogadro::Rendering |