aboutsummaryrefslogtreecommitdiff
path: root/src/buffer
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/vertex/fluid_cell_buffer.cc11
-rw-r--r--src/buffer/vertex/fluid_cell_buffer.h4
-rw-r--r--src/buffer/vertex/material_buffer.cc39
-rw-r--r--src/buffer/vertex/material_buffer.h20
4 files changed, 12 insertions, 62 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),
diff --git a/src/buffer/vertex/fluid_cell_buffer.h b/src/buffer/vertex/fluid_cell_buffer.h
index 9e535cb..8afb342 100644
--- a/src/buffer/vertex/fluid_cell_buffer.h
+++ b/src/buffer/vertex/fluid_cell_buffer.h
@@ -2,6 +2,8 @@
#include <GL/glew.h>
+#include <functional>
+
class FluidCellBuffer {
private:
const GLuint _nX;
@@ -11,7 +13,7 @@ private:
GLuint _buffer;
public:
- FluidCellBuffer(GLuint nX, GLuint nY);
+ FluidCellBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry);
~FluidCellBuffer();
GLuint getBuffer() const;
diff --git a/src/buffer/vertex/material_buffer.cc b/src/buffer/vertex/material_buffer.cc
deleted file mode 100644
index d193318..0000000
--- a/src/buffer/vertex/material_buffer.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "material_buffer.h"
-
-#include <vector>
-
-MaterialBuffer::MaterialBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry):
- _nX(nX), _nY(nY) {
- glGenVertexArrays(1, &_array);
- glGenBuffers(1, &_buffer);
-
- glBindVertexArray(_array);
- glBindBuffer(GL_ARRAY_BUFFER, _buffer);
-
- std::vector<GLint> data(nX*nY, GLint{1});
-
- for ( int x = 0; x < nX; ++x ) {
- for ( int y = 0; y < nY; ++y ) {
- data[y*nX + x] = geometry(x,y);
- }
- }
-
- glBufferData(
- GL_ARRAY_BUFFER,
- data.size() * sizeof(GLint),
- data.data(),
- GL_STATIC_DRAW
- );
-
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 1, GL_INT, GL_FALSE, 0, nullptr);
-}
-
-MaterialBuffer::~MaterialBuffer() {
- glDeleteBuffers(1, &_buffer);
- glDeleteVertexArrays(1, &_array);
-}
-
-GLuint MaterialBuffer::getBuffer() const {
- return _buffer;
-}
diff --git a/src/buffer/vertex/material_buffer.h b/src/buffer/vertex/material_buffer.h
deleted file mode 100644
index 4c61c55..0000000
--- a/src/buffer/vertex/material_buffer.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <GL/glew.h>
-
-#include <functional>
-
-class MaterialBuffer {
-private:
- const GLuint _nX;
- const GLuint _nY;
-
- GLuint _array;
- GLuint _buffer;
-
-public:
- MaterialBuffer(GLuint nX, GLuint nY, std::function<int(int,int)>&& geometry);
- ~MaterialBuffer();
-
- GLuint getBuffer() const;
-};