35 lines
878 B
C++
35 lines
878 B
C++
#include <unordered_map>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
|
|
#include "render/loader/GLLoader.h"
|
|
|
|
|
|
namespace td {
|
|
namespace render {
|
|
|
|
|
|
class VertexCache {
|
|
|
|
typedef std::vector<float> Vector;
|
|
typedef std::pair<Vector::iterator, Vector::iterator> ElementsIndex;
|
|
typedef std::pair<ElementsIndex, ElementsIndex> DataIndex;
|
|
|
|
private:
|
|
Vector m_Positions;
|
|
Vector m_Colors;
|
|
std::unordered_map<std::uint64_t, DataIndex> m_Indexes;
|
|
std::unique_ptr<GL::VertexArray> m_VertexArray;
|
|
public:
|
|
void addData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
|
|
void removeData(std::uint64_t index);
|
|
void clear();
|
|
void updateVertexArray();
|
|
|
|
const GL::VertexArray& getVertexArray() const { return *m_VertexArray; }
|
|
bool isEmpty() const { return m_VertexArray == nullptr; }
|
|
};
|
|
|
|
} // namespace render
|
|
} // namespace td
|