feat: remove tower

This commit is contained in:
2021-12-08 15:34:20 +01:00
parent 78cf2d0f18
commit e4a9c5f763
16 changed files with 88 additions and 38 deletions

View File

@@ -5,46 +5,43 @@ namespace td {
namespace render {
void VertexCache::addData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors) {
ElementsIndex positionsIndexes;
positionsIndexes.first = m_Positions.end();
m_Positions.insert(m_Positions.end(), positions.begin(), positions.end());
positionsIndexes.second = m_Positions.end() - 1;
ElementsIndex colorsIndexes;
colorsIndexes.first = m_Colors.end();
m_Colors.insert(m_Colors.end(), colors.begin(), colors.end());
colorsIndexes.second = m_Colors.end() - 1;
m_Indexes.insert({ index, {positionsIndexes, colorsIndexes} });
m_Indexes.insert({ index, {positions, colors} });
m_VertexCount += colors.size(); // one color per vertex
}
void VertexCache::removeData(std::uint64_t index) {
auto it = m_Indexes.find(index);
if (it != m_Indexes.end()) {
DataIndex indexes = it->second;
ElementsIndex positionsIndexes = indexes.first;
ElementsIndex colorsIndexes = indexes.second;
m_Positions.erase(positionsIndexes.first, positionsIndexes.second);
m_Colors.erase(colorsIndexes.first, colorsIndexes.second);
m_Indexes.erase(it);
m_VertexCount -= it->second.color.size(); // one color per vertex
}
}
void VertexCache::clear() {
m_Positions.clear();
m_Colors.clear();
m_Indexes.clear();
m_VertexCount = 0;
}
void VertexCache::updateVertexArray() {
m_VertexArray = std::make_unique<GL::VertexArray>(m_Colors.size()); // one color per vertex
m_VertexArray = std::make_unique<GL::VertexArray>(m_VertexCount); // one color per vertex
GL::VertexBuffer positionsBuffer(m_Positions, 2);
Vector positions;
positions.reserve(m_VertexCount * 2);
Vector colors;
colors.reserve(m_VertexCount);
for (auto it = m_Indexes.begin(); it != m_Indexes.end(); it++) {
const DataIndex& data = it->second;
positions.insert(positions.end(), data.position.begin(), data.position.end());
colors.insert(colors.end(), data.color.begin(), data.color.end());
}
GL::VertexBuffer positionsBuffer(positions, 2);
positionsBuffer.addVertexAttribPointer(0, 2, 0);
GL::VertexBuffer colorsBuffer(m_Colors, 1);
GL::VertexBuffer colorsBuffer(colors, 1);
colorsBuffer.addVertexAttribPointer(1, 1, 0);
m_VertexArray->bind();