src/vertexcompiler.h

changeset 1385
2f18c0da749d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/vertexcompiler.h	Fri Apr 27 16:27:14 2018 +0300
@@ -0,0 +1,69 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2018 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "main.h"
+#include "glShared.h"
+
+class Model;
+class VertexSelection;
+
+/*
+ * Compiles a scene that contains a small sphere for every vertex.
+ */
+class VertexCompiler : public QObject, protected QOpenGLFunctions
+{
+	Q_OBJECT
+
+public:
+	enum Vbo { Surfaces, Normals, Colors, PickColors, VboCount };
+
+	VertexCompiler(Model* model, VertexSelection* selection, QObject* parent = nullptr);
+	~VertexCompiler();
+
+	void initialize();
+	GLuint vbo(Vbo vboIndex);
+	size_t vboSize(Vbo vboIndex) const;
+
+private:
+	bool initialized = false;
+	bool needCompile = true;
+	struct
+	{
+		GLuint buffer;
+		QVector<float> data;
+	} vbos[VboCount];
+	QMap<Vertex, unsigned int> vertices;
+	Model* model;
+
+	void addVertex(const Vertex& vertex);
+	void addVerticesFromObject(LDObject* object);
+	void clear();
+	void compile();
+	void compileVertex(const Vertex& vertex);
+	void removeVertex(const Vertex& vertex);
+	void removeVerticesFromObject(LDObject* object);
+	void upload();
+
+private slots:
+	void handleNewObject(const QModelIndex& index);
+	void handlePreModifiedObject();
+	void handleRemovedObject(const QModelIndex& index);
+	void handleModifiedObject();
+	void updateVertex(const Vertex& vertex);
+};

mercurial