3 #include "nta/PrimitiveBatch.h"
8 PrimitiveBatch::~PrimitiveBatch() {
10 glDeleteBuffers(1, &m_vbo);
13 glDeleteVertexArrays(1, &
m_vao);
29 glGenBuffers(1, &m_vbo);
32 glGenVertexArrays(1, &
m_vao);
34 glBindVertexArray(
m_vao);
35 glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
36 for (
int i = 0; i < NUM_VERTEX_ATTRIBS; i++) {
37 auto& attrib = Vertex2D::attribs[i];
39 glEnableVertexAttribArray(i);
40 glVertexAttribPointer(i, attrib.size, attrib.type, attrib.normalized,
sizeof(
Vertex2D),
92 numVertices += p->vertices.size();
95 std::vector<Vertex2D> vertexData(numVertices);
99 for (
int i = 0; i <
m_primitives[0]->vertices.size(); i++) {
118 for (
int i = 0; i <
m_primitives[cp]->vertices.size(); i++) {
123 glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
124 glBufferData(GL_ARRAY_BUFFER, vertexData.size()*
sizeof(
Vertex2D),
nullptr, GL_DYNAMIC_DRAW);
125 glBufferSubData(GL_ARRAY_BUFFER, 0, vertexData.size()*
sizeof(
Vertex2D), vertexData.data());
126 glBindBuffer(GL_ARRAY_BUFFER, 0);
129 switch(numVertices) {
130 case 1:
return GL_POINTS;
break;
131 case 2:
return GL_LINES;
break;
132 case 3:
return GL_TRIANGLES;
break;
133 case 4:
return GL_QUADS;
break;
134 default:
return GL_POLYGON;
break;
141 GLuint textureID,
float depth) {
145 crvec4 color,
float orientation,
float depth) {
146 m_primitives.push_back(
new Primitive(numSides, center, sideLength, color, orientation, depth));
149 glBindVertexArray(
m_vao);
155 glBindVertexArray(0);