diff options
author | Adrian Kummerlaender | 2019-04-18 22:15:39 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2019-04-18 22:15:39 +0200 |
commit | 34566b28a82869cbf004d91c6d658ba71d40ed97 (patch) | |
tree | 5322ec9bf7f48a96390d638d410aff0abfe21348 /src/buffer | |
parent | 1ad4daa0289c56e3d6b896d5037002aa6b461674 (diff) | |
download | compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar.gz compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar.bz2 compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar.lz compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar.xz compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.tar.zst compustream-34566b28a82869cbf004d91c6d658ba71d40ed97.zip |
Bind key to reset lattice buffers
i.e. restarting the simulation without clearing the geometry
Diffstat (limited to 'src/buffer')
-rw-r--r-- | src/buffer/vertex/fluid_cell_buffer.cc | 30 | ||||
-rw-r--r-- | src/buffer/vertex/fluid_cell_buffer.h | 2 | ||||
-rw-r--r-- | src/buffer/vertex/lattice_cell_buffer.cc | 14 | ||||
-rw-r--r-- | src/buffer/vertex/lattice_cell_buffer.h | 4 |
4 files changed, 28 insertions, 22 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 { diff --git a/src/buffer/vertex/fluid_cell_buffer.h b/src/buffer/vertex/fluid_cell_buffer.h index 8afb342..791ebea 100644 --- a/src/buffer/vertex/fluid_cell_buffer.h +++ b/src/buffer/vertex/fluid_cell_buffer.h @@ -16,6 +16,8 @@ public: FluidCellBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry); ~FluidCellBuffer(); + void init(std::function<int(int,int)>&& geometry); + GLuint getBuffer() const; void draw() const; diff --git a/src/buffer/vertex/lattice_cell_buffer.cc b/src/buffer/vertex/lattice_cell_buffer.cc index 2011b14..f3ef47d 100644 --- a/src/buffer/vertex/lattice_cell_buffer.cc +++ b/src/buffer/vertex/lattice_cell_buffer.cc @@ -20,13 +20,15 @@ std::vector<GLfloat> makeLattice(GLuint nX, GLuint nY) { return data; } -LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY) { - glGenVertexArrays(1, &_array); +LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY): + _nX(nX), _nY(nY) { glGenBuffers(1, &_buffer); + init(); +} - const std::vector<GLfloat> data = makeLattice(nX, nY); +void LatticeCellBuffer::init() { + const std::vector<GLfloat> data = makeLattice(_nX, _nY); - glBindVertexArray(_array); glBindBuffer(GL_ARRAY_BUFFER, _buffer); glBufferData( GL_ARRAY_BUFFER, @@ -34,14 +36,10 @@ LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY) { data.data(), GL_DYNAMIC_DRAW ); - - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr); } LatticeCellBuffer::~LatticeCellBuffer() { glDeleteBuffers(1, &_buffer); - glDeleteVertexArrays(1, &_array); } GLuint LatticeCellBuffer::getBuffer() const { diff --git a/src/buffer/vertex/lattice_cell_buffer.h b/src/buffer/vertex/lattice_cell_buffer.h index e5e00a4..cabff67 100644 --- a/src/buffer/vertex/lattice_cell_buffer.h +++ b/src/buffer/vertex/lattice_cell_buffer.h @@ -4,6 +4,8 @@ class LatticeCellBuffer { private: + GLuint _nX; + GLuint _nY; GLuint _array; GLuint _buffer; @@ -11,5 +13,7 @@ public: LatticeCellBuffer(GLuint nX, GLuint nY); ~LatticeCellBuffer(); + void init(); + GLuint getBuffer() const; }; |