From 44f5ac32a68a617f93704d44c4339f7db13b323e Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 15 Dec 2018 23:09:32 +0100 Subject: Hacky D2Q9 BGK LBM on GPU using GLSL compute shaders Improvised on top of computicles's scaffolding. Works in a world where _works_ is defined as "displays stuff on screen that invokes thoughts of fluid movement". --- src/buffer/vertex/fluid_cell_buffer.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/buffer/vertex/fluid_cell_buffer.cc (limited to 'src/buffer/vertex/fluid_cell_buffer.cc') diff --git a/src/buffer/vertex/fluid_cell_buffer.cc b/src/buffer/vertex/fluid_cell_buffer.cc new file mode 100644 index 0000000..5056569 --- /dev/null +++ b/src/buffer/vertex/fluid_cell_buffer.cc @@ -0,0 +1,33 @@ +#include "fluid_cell_buffer.h" + +FluidCellBuffer::FluidCellBuffer(): + _data(3*128*128, GLfloat{}) { + glGenVertexArrays(1, &_array); + glGenBuffers(1, &_buffer); + + glBindVertexArray(_array); + glBindBuffer(GL_ARRAY_BUFFER, _buffer); + glBufferData( + GL_ARRAY_BUFFER, + _data.size() * sizeof(GLfloat), + _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 { + return _buffer; +} + +void FluidCellBuffer::draw() const { + glBindVertexArray(_array); + glDrawArrays(GL_POINTS, 0, _data.size()); +} -- cgit v1.2.3