--- a/src/gl/compiler.h Sun Jan 19 14:25:57 2020 +0200 +++ b/src/gl/compiler.h Wed Jan 22 00:23:29 2020 +0200 @@ -22,6 +22,9 @@ #include "types/boundingbox.h" #include <QMap> #include <QSet> +#include <QOpenGLVertexArrayObject> +#include <QOpenGLBuffer> +#include <QOpenGLShaderProgram> class Model; class DocumentManager; @@ -32,7 +35,7 @@ class Renderer; struct VboAddress { - VboClass vboClass; + ArrayClass vboClass; VboSubclass vboSubclass; }; int vboIndex(const VboAddress vboAddress); @@ -42,24 +45,34 @@ { Q_OBJECT public: - Compiler(QObject* parent); + Compiler(const ColorTable& colorTable, QObject* parent); ~Compiler(); void build(Model* model, DocumentManager* context); void buildPolygon(Polygon polygon, std::vector<GLfloat>* vboData); void upload(const int vboIndex, const std::vector<GLfloat>& data); GLuint vbo(const VboAddress vboAddress) const; std::size_t vboSize(const VboAddress vboAddress) const; - QColor getColorForPolygon(const gl::Polygon& polygon, VboSubclass subclass); - void writeColor(std::vector<GLfloat>* data, const gl::Polygon& polygon, VboSubclass subclass); + QColor getColorForPolygon(const gl::Polygon& polygon); Point3D modelCenter() const; double modelDistance() const; + void initialize(); + void bindVertexArray(gl::ArrayClass arrayClass); + void releaseVertexArray(gl::ArrayClass arrayClass); + void buildShaders(int arrayId); private: - void initializeVbo(); - GLuint storedVbo[gl::numVbos]; + QOpenGLVertexArrayObject vertexArrays[gl::NUM_ARRAY_CLASSES]; + //GLuint storedVbo[gl::numVbos]; bool m_vboChanged[gl::numVbos] = {true}; std::size_t storedVboSizes[gl::numVbos] = {0_z}; bool initialized = false; BoundingBox boundingBox; + const ColorTable& colorTable; + struct + { + QOpenGLShaderProgram* program = nullptr; + QOpenGLBuffer buffer{QOpenGLBuffer::VertexBuffer}; + QOpenGLVertexArrayObject vertexArray; + } glObjects[gl::NUM_ARRAY_CLASSES]; }; #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }