src/gl/compiler.h

changeset 21
0133e565e072
parent 19
ed9685f44ab3
child 22
6da867fa5429
equal deleted inserted replaced
20:cef43609a374 21:0133e565e072
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #pragma once 19 #pragma once
20 #include "main.h" 20 #include "main.h"
21 #include "gl/partrenderer.h"
22 #include "gl/common.h" 21 #include "gl/common.h"
23 #include "types/boundingbox.h" 22 #include "types/boundingbox.h"
24 #include <QMap> 23 #include <QMap>
25 #include <QSet> 24 #include <QSet>
26 25
26 class Model;
27 class DocumentManager;
28
27 namespace gl 29 namespace gl
28 { 30 {
29 class Compiler; 31 class Compiler;
30 class Renderer; 32 class Renderer;
33 struct VboAddress
34 {
35 VboClass vboClass;
36 VboSubclass vboSubclass;
37 };
38 int vboIndex(const VboAddress vboAddress);
31 } 39 }
32 40
33 /*
34 * Compiles LDObjects into polygons for the GLRenderer to draw.
35 */
36 class gl::Compiler : public QObject, protected QOpenGLFunctions 41 class gl::Compiler : public QObject, protected QOpenGLFunctions
37 { 42 {
38 Q_OBJECT 43 Q_OBJECT
39 public: 44 public:
40 Compiler(Renderer* renderer); 45 Compiler(QObject* parent);
41 ~Compiler(); 46 ~Compiler();
42 void initialize(); 47 void build(Model* model, DocumentManager* context);
43 Point3D modelCenter(); 48 void buildPolygon(Polygon polygon, std::vector<GLfloat>* vboData);
44 void prepareVBO (int vbonum); 49 void upload(const int vboIndex, const std::vector<GLfloat>& data);
45 GLuint vbo (int vbonum) const; 50 GLuint vbo(const VboAddress vboAddress) const;
46 int vboSize (int vbonum) const; 51 int vboSize(const VboAddress vboAddress) const;
47 static int vboNumber (VboClass surface, VboSubclass complement); 52 QColor getColorForPolygon(const gl::Polygon& polygon, VboSubclass subclass);
53 void writeColor(std::vector<GLfloat>* data, const gl::Polygon& polygon, VboSubclass subclass);
48 private: 54 private:
49 struct ObjectVboData 55 void initializeVbo();
50 { 56 GLuint storedVbo[gl::numVbos];
51 QVector<GLfloat> data[gl::numVbos];
52 };
53 QMap<QPersistentModelIndex, ObjectVboData> m_objectInfo;
54 QSet<QPersistentModelIndex> m_staged; // Objects that need to be compiled
55 GLuint m_vbo[gl::numVbos];
56 bool m_vboChanged[gl::numVbos] = {true}; 57 bool m_vboChanged[gl::numVbos] = {true};
57 bool needBoundingBoxRebuild = true; 58 int storedVboSizes[gl::numVbos] = {0};
58 int m_vboSizes[gl::numVbos] = {0}; 59 bool initialized = false;
59 }; 60 };
60 61
61 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); } 62 #define CHECK_GL_ERROR() { checkGLError(__FILE__, __LINE__); }
62 void checkGLError (QString file, int line); 63 void checkGLError (QString file, int line);

mercurial