aboutsummaryrefslogtreecommitdiff
path: root/src/buffer/vertex/particle_vertex_buffer.h
blob: 25855a27ad568aa1c950a48b3e4b37d20328eaa8 (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
43
44
#pragma once

#include <vector>

class ParticleVertexBuffer {
private:
	std::vector<GLfloat> _data;

	GLuint _array;
	GLuint _buffer;

public:
	ParticleVertexBuffer(std::vector<GLfloat>&& data):
		_data{ std::move(data) } {
		glGenVertexArrays(1, &_array);
		glGenBuffers(1, &_buffer);

		glBindVertexArray(_array);
		glBindBuffer(GL_ARRAY_BUFFER, _buffer);
		glBufferData(
			GL_ARRAY_BUFFER,
			_data.size() * sizeof(GLfloat),
			_data.data(),
			GL_STATIC_DRAW
		);

		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
	}

	~ParticleVertexBuffer() {
		glDeleteBuffers(1, &_buffer);
		glDeleteVertexArrays(1, &_array);
	}

	void draw() const {
		glBindVertexArray(_array);
		glDrawArrays(GL_POINTS, 0, 3*_data.size());
	}

	GLuint getBuffer() const {
		return _buffer;
	}
};