Sun, 07 Sep 2014 22:55:44 +0300
- improved part downloader: now asks for the path instead of just directing the user to settings. auto-fix download now configurable and opt-in
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
844
11587d419d2f
- changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents:
784
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Teemu Piippo |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
736
0446af72b2ee
- use #pragma once for the gl compiler header
Santeri Piippo <crimsondusk64@gmail.com>
parents:
726
diff
changeset
|
19 | #pragma once |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "main.h" |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "glRenderer.h" |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "glShared.h" |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include <QMap> |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | // ============================================================================= |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | // |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
27 | class GLCompiler : protected QOpenGLFunctions |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | { |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
29 | public: |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
30 | struct ObjectVBOInfo |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
31 | { |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
32 | QVector<GLfloat> data[g_numVBOs]; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
33 | bool isChanged; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
34 | }; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
759
038985b4a154
- added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
736
diff
changeset
|
36 | GLCompiler (GLRenderer* renderer); |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
37 | ~GLCompiler(); |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
38 | void compileDocument (LDDocumentPtr doc); |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
759
diff
changeset
|
39 | void dropObject (LDObjectPtr obj); |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
40 | void initialize(); |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
759
diff
changeset
|
41 | QColor getColorForPolygon (LDPolygon& poly, LDObjectPtr topobj, |
726
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
721
diff
changeset
|
42 | EVBOComplement complement) const; |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
43 | QColor indexColorForID (int id) const; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
44 | void needMerge(); |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
45 | void prepareVBO (int vbonum); |
857
e62983881460
- fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
856
diff
changeset
|
46 | void setRenderer (GLRenderer* compiler); |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
759
diff
changeset
|
47 | void stageForCompilation (LDObjectPtr obj); |
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
759
diff
changeset
|
48 | void unstage (LDObjectPtr obj); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
50 | static uint32 colorToRGB (const QColor& color); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
52 | static inline int vboNumber (EVBOSurface surface, EVBOComplement complement) |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
53 | { |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
54 | return (surface * VBOCM_NumComplements) + complement; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
55 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
57 | inline GLuint vbo (int vbonum) const |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
58 | { |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
59 | return m_vbo[vbonum]; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
60 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
62 | inline int vboSize (int vbonum) const |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
63 | { |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
64 | return m_vboSizes[vbonum]; |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
65 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
713
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
67 | private: |
46377d340c23
- more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
68 | void compileStaged(); |
768
29e6c5552388
- initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
759
diff
changeset
|
69 | void compileObject (LDObjectPtr obj); |
857
e62983881460
- fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
856
diff
changeset
|
70 | void compilePolygon (LDPolygon& poly, LDObjectPtr topobj, ObjectVBOInfo* objinfo); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
784
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
72 | QMap<LDObjectWeakPtr, ObjectVBOInfo> m_objectInfo; |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
73 | LDObjectWeakList m_staged; // Objects that need to be compiled |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
74 | GLuint m_vbo[g_numVBOs]; |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
75 | bool m_vboChanged[g_numVBOs]; |
f82ab4d3c7b4
- made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
768
diff
changeset
|
76 | int m_vboSizes[g_numVBOs]; |
857
e62983881460
- fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
856
diff
changeset
|
77 | GLRenderer* m_renderer; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | }; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
80 | #define CHECK_GL_ERROR() { CheckGLErrorImpl (__FILE__, __LINE__); } |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
81 | void CheckGLErrorImpl (const char* file, int line); |