src/GLCompiler.h

changeset 706
d79083b9f74d
parent 705
09150d027e8c
parent 655
b376645315ab
child 707
c89b58ba266b
equal deleted inserted replaced
705:09150d027e8c 706:d79083b9f74d
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 Santeri Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef LDFORGE_GLCOMPILER_H
20 #define LDFORGE_GLCOMPILER_H
21
22 #include "Main.h"
23 #include "GLRenderer.h"
24 #include "GLShared.h"
25 #include <QMap>
26
27 // =============================================================================
28 //
29 class GLCompiler
30 {
31 public:
32 struct ObjectVBOInfo
33 {
34 QVector<GLfloat> data[g_numVBOs];
35 };
36
37 GLCompiler();
38 ~GLCompiler();
39 void compileDocument (LDDocument* doc);
40 void dropObject (LDObject* obj);
41 void initialize();
42 QColor polygonColor (LDPolygon& poly, LDObject* topobj) const;
43 QColor indexColorForID (int id) const;
44 void needMerge();
45 void prepareVBO (int vbonum);
46 void stageForCompilation (LDObject* obj);
47
48 static uint32 colorToRGB (const QColor& color);
49
50 static inline int vboNumber (EVBOSurface surface, EVBOComplement complement)
51 {
52 return (surface * VBOCM_NumComplements) + complement;
53 }
54
55 inline GLuint vbo (int vbonum) const
56 {
57 return m_vbo[vbonum];
58 }
59
60 inline int vboCount (int vbonum) const
61 {
62 return m_vboSizes[vbonum] / 3;
63 }
64
65 private:
66 void compileStaged();
67 void compileObject (LDObject* obj);
68 void compileSubObject (LDObject* obj, LDObject* topobj, GLCompiler::ObjectVBOInfo* objinfo);
69 void writeColor (QVector<float>& array, const QColor& color);
70 void compilePolygon (LDPolygon& poly, LDObject* topobj, GLCompiler::ObjectVBOInfo* objinfo);
71
72 QMap<LDObject*, ObjectVBOInfo> m_objectInfo;
73 LDObjectList m_staged; // Objects that need to be compiled
74 GLuint m_vbo[g_numVBOs];
75 bool m_vboChanged[g_numVBOs];
76 int m_vboSizes[g_numVBOs];
77 };
78
79 #define checkGLError() { checkGLError_private (__FILE__, __LINE__); }
80 void checkGLError_private (const char* file, int line);
81
82 #endif // LDFORGE_GLCOMPILER_H

mercurial