diff options
Store material in fluid buffer and improve visualization
Replaces the density value which is actually not that useful for visualization.
Encoding integer values as floats by casting and comparing them using
exact floating point comparison is not very safe but works out for now.
Diffstat (limited to 'src/buffer/vertex/fluid_cell_buffer.cc')
-rw-r--r-- | src/buffer/vertex/fluid_cell_buffer.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/buffer/vertex/fluid_cell_buffer.cc b/src/buffer/vertex/fluid_cell_buffer.cc index a0bfcc3..4930d63 100644 --- a/src/buffer/vertex/fluid_cell_buffer.cc +++ b/src/buffer/vertex/fluid_cell_buffer.cc @@ -2,7 +2,7 @@ #include <vector> -FluidCellBuffer::FluidCellBuffer(GLuint nX, GLuint nY): +FluidCellBuffer::FluidCellBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry): _nX(nX), _nY(nY) { glGenVertexArrays(1, &_array); glGenBuffers(1, &_buffer); @@ -10,7 +10,14 @@ FluidCellBuffer::FluidCellBuffer(GLuint nX, GLuint nY): glBindVertexArray(_array); glBindBuffer(GL_ARRAY_BUFFER, _buffer); - const 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); + } + } + glBufferData( GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), |