Mon, 10 Mar 2014 01:02:51 +0200
- ported over the selected color blend from master
674 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013, 2014 Santeri Piippo | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
674 | 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. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
674 | 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. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
674 | 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/>. | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
674 | 19 | #ifndef LDFORGE_GLCOMPILER_H |
20 | #define LDFORGE_GLCOMPILER_H | |
21 | ||
675
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
22 | #include "Main.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
23 | #include "GLRenderer.h" |
674 | 24 | #include "GLShared.h" |
25 | #include <QMap> | |
26 | ||
27 | // ============================================================================= | |
28 | // | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | class GLCompiler |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | public: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
32 | struct ObjectVBOInfo |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | { |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
34 | QVector<GLfloat> data[gNumVBOs]; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | GLCompiler(); |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | ~GLCompiler(); |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
692
diff
changeset
|
39 | void compileDocument (LDDocument* doc); |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
40 | void dropObject (LDObject* obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
41 | void initialize(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
42 | QColor getPolygonColor (LDPolygon& poly, LDObject* topobj) const; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
43 | QColor getIndexColor (int id) const; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
44 | void needMerge(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
45 | void prepareVBO (int vbonum); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
46 | void stageForCompilation (LDObject* obj); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
47 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
48 | static uint32 getColorRGB (const QColor& color); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
50 | static inline int getVBONumber (EVBOSurface surface, EVBOComplement complement) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
51 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
52 | return (surface * vboNumComplements) + complement; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
53 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
54 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
55 | inline GLuint getVBO (int vbonum) const |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
56 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
57 | return mVBOs[vbonum]; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
58 | } |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
59 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
60 | inline int getVBOCount (int vbonum) const |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
61 | { |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
692
diff
changeset
|
62 | return mVBOSizes[vbonum] / 3; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
63 | } |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | private: |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
66 | void compileStaged(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
67 | void compileObject (LDObject* obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
68 | void compileSubObject (LDObject* obj, LDObject* topobj, GLCompiler::ObjectVBOInfo* objinfo); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
69 | void writeColor (QVector<float>& array, const QColor& color); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
70 | void compilePolygon (LDPolygon& poly, LDObject* topobj, GLCompiler::ObjectVBOInfo* objinfo); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
72 | QMap<LDObject*, ObjectVBOInfo> mObjectInfo; |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
692
diff
changeset
|
73 | LDObjectList mStaged; // Objects that need to be compiled |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
74 | GLuint mVBOs[gNumVBOs]; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
75 | bool mChanged[gNumVBOs]; |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
692
diff
changeset
|
76 | int mVBOSizes[gNumVBOs]; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | }; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
79 | #define checkGLError() { checkGLError_private (__FILE__, __LINE__); } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
80 | void checkGLError_private (const char* file, int line); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
674 | 82 | #endif // LDFORGE_GLCOMPILER_H |