aboutsummaryrefslogtreecommitdiff
path: root/src/buffer
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-12-15 23:09:32 +0100
committerAdrian Kummerlaender2018-12-15 23:09:32 +0100
commit44f5ac32a68a617f93704d44c4339f7db13b323e (patch)
tree6c191524aca1c7dbf3329026a59cfa3bc0109d2f /src/buffer
downloadcompustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar.gz
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar.bz2
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar.lz
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar.xz
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.tar.zst
compustream-44f5ac32a68a617f93704d44c4339f7db13b323e.zip
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".
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/vertex/fluid_cell_buffer.cc33
-rw-r--r--src/buffer/vertex/fluid_cell_buffer.h21
-rw-r--r--src/buffer/vertex/lattice_cell_buffer.cc40
-rw-r--r--src/buffer/vertex/lattice_cell_buffer.h19
4 files changed, 113 insertions, 0 deletions
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());
+}
diff --git a/src/buffer/vertex/fluid_cell_buffer.h b/src/buffer/vertex/fluid_cell_buffer.h
new file mode 100644
index 0000000..b2b880a
--- /dev/null
+++ b/src/buffer/vertex/fluid_cell_buffer.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <vector>
+
+#include <GL/glew.h>
+
+class FluidCellBuffer {
+private:
+ std::vector<GLfloat> _data;
+
+ GLuint _array;
+ GLuint _buffer;
+
+public:
+ FluidCellBuffer();
+ ~FluidCellBuffer();
+
+ GLuint getBuffer() const;
+
+ void draw() const;
+};
diff --git a/src/buffer/vertex/lattice_cell_buffer.cc b/src/buffer/vertex/lattice_cell_buffer.cc
new file mode 100644
index 0000000..7fb51d8
--- /dev/null
+++ b/src/buffer/vertex/lattice_cell_buffer.cc
@@ -0,0 +1,40 @@
+#include "lattice_cell_buffer.h"
+
+#include <fstream>
+
+LatticeCellBuffer::LatticeCellBuffer():
+ _data(9*128*128, GLfloat{1./9.}) {
+ glGenVertexArrays(1, &_array);
+ glGenBuffers(1, &_buffer);
+
+ for (int x = 50; x < 128-50; x++) {
+ for (int y = 50; y < 128-50; y++) {
+ for ( int i = -1; i <= 1; ++i ) {
+ for ( int j = -1; j <= 1; ++j ) {
+ _data[9*128*y + 9*x + (i+1)*3 + j+1] = 1./128.;
+ }
+ }
+ }
+ }
+
+ glBindVertexArray(_array);
+ glBindBuffer(GL_ARRAY_BUFFER, _buffer);
+ glBufferData(
+ GL_ARRAY_BUFFER,
+ _data.size() * sizeof(GLfloat),
+ _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 {
+ return _buffer;
+}
diff --git a/src/buffer/vertex/lattice_cell_buffer.h b/src/buffer/vertex/lattice_cell_buffer.h
new file mode 100644
index 0000000..c28319e
--- /dev/null
+++ b/src/buffer/vertex/lattice_cell_buffer.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <vector>
+
+#include <GL/glew.h>
+
+class LatticeCellBuffer {
+private:
+ std::vector<GLfloat> _data;
+
+ GLuint _array;
+ GLuint _buffer;
+
+public:
+ LatticeCellBuffer();
+ ~LatticeCellBuffer();
+
+ GLuint getBuffer() const;
+};