aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/vertex/lattice_cell_buffer.cc
blob: c2b877b892be9b37db29e714142d1e8f94635561 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "lattice_cell_buffer.h"

#include <fstream>

LatticeCellBuffer::LatticeCellBuffer(GLuint nX, GLuint nY):
	_data(9*nX*nY, GLfloat{1./9.}) {
	glGenVertexArrays(1, &_array);
	glGenBuffers(1, &_buffer);

	const int inset = 0.4*nX;

	for (int x = inset; x < nX-inset; x++) {
		for (int y = inset; y < nY-inset; y++) {
			for ( int i = -1; i <= 1; ++i ) {
				for ( int j = -1; j <= 1; ++j ) {
					_data[9*nX*y + 9*x + (i+1)*3 + j+1] = 1./64.;
				}
			}
		}
	}

	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;
}