diff options
Diffstat (limited to 'src/buffer/vertex/fluid_cell_buffer.cc')
-rw-r--r-- | src/buffer/vertex/fluid_cell_buffer.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/buffer/vertex/fluid_cell_buffer.cc b/src/buffer/vertex/fluid_cell_buffer.cc index 4930d63..8fdc579 100644 --- a/src/buffer/vertex/fluid_cell_buffer.cc +++ b/src/buffer/vertex/fluid_cell_buffer.cc @@ -4,17 +4,27 @@ FluidCellBuffer::FluidCellBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry): _nX(nX), _nY(nY) { - glGenVertexArrays(1, &_array); glGenBuffers(1, &_buffer); - glBindVertexArray(_array); + init(std::forward<decltype(geometry)>(geometry)); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + +} + +FluidCellBuffer::~FluidCellBuffer() { + glDeleteBuffers(1, &_buffer); + glDeleteVertexArrays(1, &_array); +} + +void FluidCellBuffer::init(std::function<int(int,int)>&& geometry) { glBindBuffer(GL_ARRAY_BUFFER, _buffer); - std::vector<GLfloat> data(3*nX*nY, GLfloat{}); + std::vector<GLfloat> data(3*_nX*_nY, GLfloat{}); - for ( int x = 0; x < nX; ++x ) { - for ( int y = 0; y < nY; ++y ) { - data[3*nX*y + 3*x + 2] = geometry(x,y); + for ( int x = 0; x < _nX; ++x ) { + for ( int y = 0; y < _nY; ++y ) { + data[3*_nX*y + 3*x + 2] = geometry(x,y); } } @@ -24,14 +34,6 @@ FluidCellBuffer::FluidCellBuffer(GLuint nX, GLuint nY, std::function<int(int,int data.data(), GL_DYNAMIC_DRAW ); - - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); -} - -FluidCellBuffer::~FluidCellBuffer() { - glDeleteBuffers(1, &_buffer); - glDeleteVertexArrays(1, &_array); } GLuint FluidCellBuffer::getBuffer() const { |