-Model &Model::operator =(Model &&other) noexcept {
- std::swap(va, other.va);
- for (int i = 0; i < ATTRIB_COUNT; ++i) {
- std::swap(handle[i], other.handle[i]);
- }
- count = other.count;
- return *this;
-}
-
-void Model::Update(const Buffer &buf) noexcept {
- glBindVertexArray(va);
- glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]);
- glBufferData(GL_ARRAY_BUFFER, buf.vertices.size() * sizeof(glm::vec3), buf.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 (buf.colors.size() < buf.vertices.size()) {
- std::cerr << "Model: 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 << "Model: 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
- );
-
- 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();