+#ifndef NDEBUG
+ if (buf.colors.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough colors!" << std::endl;
+ }
+#endif
+ glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_COLOR]);
+ glBufferData(GL_ARRAY_BUFFER, buf.colors.size() * sizeof(glm::vec3), buf.colors.data(), GL_STATIC_DRAW);
+ glEnableVertexAttribArray(ATTRIB_COLOR);
+ glVertexAttribPointer(
+ ATTRIB_COLOR, // location (for shader)
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized
+ 0, // stride
+ nullptr // offset
+ );
+
+#ifndef NDEBUG
+ if (buf.normals.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough normals!" << std::endl;
+ }
+#endif
+ glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_NORMAL]);
+ glBufferData(GL_ARRAY_BUFFER, buf.normals.size() * sizeof(glm::vec3), buf.normals.data(), GL_STATIC_DRAW);
+ glEnableVertexAttribArray(ATTRIB_NORMAL);
+ glVertexAttribPointer(
+ ATTRIB_NORMAL, // location (for shader)
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized
+ 0, // stride
+ nullptr // offset
+ );
+
+#ifndef NDEBUG
+ if (buf.lights.size() < buf.vertices.size()) {
+ std::cerr << "BlockModel: not enough lights!" << std::endl;
+ }
+#endif
+ glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_LIGHT]);
+ glBufferData(GL_ARRAY_BUFFER, buf.lights.size() * sizeof(float), buf.lights.data(), GL_STATIC_DRAW);
+ glEnableVertexAttribArray(ATTRIB_LIGHT);
+ glVertexAttribPointer(
+ ATTRIB_LIGHT, // location (for shader)
+ 1, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized
+ 0, // stride
+ nullptr // offset
+ );
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle[ATTRIB_INDEX]);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, buf.indices.size() * sizeof(Index), buf.indices.data(), GL_STATIC_DRAW);
+ count = buf.indices.size();
+}
+
+
+void BlockModel::Draw() const {
+ glBindVertexArray(va);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle[ATTRIB_INDEX]);
+ glDrawElements(
+ GL_TRIANGLES, // how
+ count, // count
+ GL_UNSIGNED_INT, // type
+ nullptr // offset
+ );
+}
+
+OutlineModel::OutlineModel()
+: vertices()
+, colors()
+, indices()
+, va(0)
+, handle{}
+, dirty(false) {
+ glGenVertexArrays(1, &va);
+ glGenBuffers(ATTRIB_COUNT, handle);
+}
+
+OutlineModel::~OutlineModel() {
+ glDeleteBuffers(ATTRIB_COUNT, handle);
+ glDeleteVertexArrays(1, &va);
+}
+
+
+void OutlineModel::Clear() {
+ vertices.clear();
+ colors.clear();
+ indices.clear();
+ Invalidate();
+}
+
+void OutlineModel::Reserve(int v, int i) {
+ vertices.reserve(v);
+ colors.reserve(v);
+ indices.reserve(i);
+}
+
+
+void OutlineModel::Update() {
+ glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]);
+ glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW);
+ glEnableVertexAttribArray(ATTRIB_VERTEX);
+ glVertexAttribPointer(
+ ATTRIB_VERTEX, // location (for shader)
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized
+ 0, // stride
+ nullptr // offset
+ );
+
+#ifndef NDEBUG
+ if (colors.size() < vertices.size()) {
+ std::cerr << "OutlineModel: not enough colors!" << std::endl;
+ colors.resize(vertices.size(), { 1, 0, 1 });
+ }
+#endif
+ glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_COLOR]);
+ glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec3), colors.data(), GL_STATIC_DRAW);
+ glEnableVertexAttribArray(ATTRIB_COLOR);
+ glVertexAttribPointer(
+ ATTRIB_COLOR, // location (for shader)
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized
+ 0, // stride
+ nullptr // offset
+ );
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle[ATTRIB_INDEX]);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(Index), indices.data(), GL_STATIC_DRAW);
+
+ dirty = false;