Tue, 11 Mar 2014 16:42:37 +0200
- fixed: an overlay that failed to load no longer attempts to reload it over and over again
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
1 | /* |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
4 | * |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
8 | * (at your option) any later version. |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
9 | * |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
13 | * GNU General Public License for more details. |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
14 | * |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
17 | */ |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
18 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
19 | #define GL_GLEXT_PROTOTYPES |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
20 | #include <GL/glu.h> |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
21 | #include <GL/glext.h> |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "GLCompiler.h" |
675
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
23 | #include "LDObject.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
24 | #include "Colors.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
25 | #include "Document.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
26 | #include "Misc.h" |
450827da2376
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
674
diff
changeset
|
27 | #include "GLRenderer.h" |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
28 | #include "Dialogs.h" |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
29 | |
695
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
30 | cfg (String, gl_selectcolor, "#0080FF") |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
31 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
32 | struct GLErrorInfo |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
33 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
34 | GLenum value; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
35 | QString text; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
36 | }; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
37 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
38 | static const GLErrorInfo g_GLErrors[] = |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
39 | { |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
40 | { GL_NO_ERROR, "No error" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
41 | { GL_INVALID_ENUM, "Unacceptable enumerator passed" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
42 | { GL_INVALID_VALUE, "Numeric argument out of range" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
43 | { GL_INVALID_OPERATION, "The operation is not allowed to be done in this state" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
44 | { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"}, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
45 | { GL_OUT_OF_MEMORY, "Out of memory" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
46 | { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
47 | { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
48 | }; |
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 | #include <QTime> |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
51 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
52 | #define CLOCK_INIT QTime t0; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
53 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
54 | #define CLOCK_START \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
55 | { \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
56 | t0 = QTime::currentTime(); \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
57 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
58 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
59 | #define CLOCK_TIME(A) \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
60 | { \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
61 | fprint (stderr, A ": %1ms\n", t0.msecsTo (QTime::currentTime())); \ |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
62 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
63 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
64 | #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | extern_cfg (Bool, gl_blackedges); |
702
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
67 | extern_cfg (String, gl_bgcolor); |
698 | 68 | static QList<short> g_warnedColors; |
69 | static const QColor g_BFCFrontColor (40, 192, 40); | |
70 | static const QColor g_BFCBackColor (224, 40, 40); | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
73 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
74 | void checkGLError_private (const char* file, int line) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
75 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
76 | QString errmsg; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
77 | GLenum errnum = glGetError(); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
78 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
79 | if (errnum == GL_NO_ERROR) |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
80 | return; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
81 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
82 | for (const GLErrorInfo& err : g_GLErrors) |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
83 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
84 | if (err.value == errnum) |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
85 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
86 | errmsg = err.text; |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
87 | break; |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
88 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
89 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
90 | |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
91 | print ("OpenGL ERROR: at %1:%2: %3", basename (QString (file)), line, errmsg); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
92 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
93 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
94 | // ============================================================================= |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
95 | // |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
96 | GLCompiler::GLCompiler() |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | { |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
98 | needMerge(); |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
99 | memset (m_vboSizes, 0, sizeof m_vboSizes); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
100 | } |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
101 | |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
102 | // ============================================================================= |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
103 | // |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
104 | void GLCompiler::initialize() |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
105 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
106 | glGenBuffers (g_numVBOs, &m_vbo[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
107 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
110 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
111 | // |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
112 | GLCompiler::~GLCompiler() |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
114 | glDeleteBuffers (g_numVBOs, &m_vbo[0]); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
115 | checkGLError(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
119 | // |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
120 | uint32 GLCompiler::colorToRGB (const QColor& color) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | return |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | (color.red() & 0xFF) << 0x00 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | (color.green() & 0xFF) << 0x08 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | (color.blue() & 0xFF) << 0x10 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | (color.alpha() & 0xFF) << 0x18; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
130 | // |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
131 | QColor GLCompiler::indexColorForID (int id) const |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
132 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
133 | // Calculate a color based from this index. This method caters for |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
134 | // 16777216 objects. I don't think that will be exceeded anytime soon. :) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
135 | int r = (id / 0x10000) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
136 | g = (id / 0x100) % 0x100, |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
137 | b = id % 0x100; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
138 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
139 | return QColor (r, g, b); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
140 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
141 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
142 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
143 | // |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
144 | QColor GLCompiler::polygonColor (LDPolygon& poly, LDObject* topobj) const |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | { |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | QColor qcol; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
148 | if (poly.color == maincolor) |
702
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
149 | { |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
150 | if (topobj->color() == maincolor) |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
151 | qcol = GLRenderer::getMainColor(); |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
152 | else |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
153 | qcol = getColor (topobj->color())->faceColor; |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
154 | } |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
155 | elif (poly.color == edgecolor) |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
156 | { |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
157 | qcol = luma (QColor (gl_bgcolor)) > 40 ? Qt::black : Qt::white; |
8e3058cb9281
- subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
701
diff
changeset
|
158 | } |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | else |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
161 | LDColor* col = getColor (poly.color); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
162 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
163 | if (col) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
164 | qcol = col->faceColor; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
165 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
166 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
167 | if (qcol.isValid() == false) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
168 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
169 | // The color was unknown. Use main color to make the poly.object at least |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
170 | // not appear pitch-black. |
698 | 171 | if (poly.num != 2 && poly.num != 5) |
674 | 172 | qcol = GLRenderer::getMainColor(); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | else |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
174 | qcol = Qt::black; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
176 | // Warn about the unknown color, but only once. |
698 | 177 | if (g_warnedColors.contains (poly.color) == false) |
178 | { | |
179 | print ("Unknown color %1!\n", poly.color); | |
180 | g_warnedColors << poly.color; | |
181 | } | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
183 | return qcol; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
186 | if (topobj->isSelected()) |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | { |
695
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
188 | // Brighten it up for the select list. |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
189 | QColor selcolor (gl_selectcolor); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
190 | qcol.setRed ((qcol.red() + selcolor.red()) / 2); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
191 | qcol.setGreen ((qcol.green() + selcolor.green()) / 2); |
4ace632e247b
- ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents:
694
diff
changeset
|
192 | qcol.setBlue ((qcol.blue() + selcolor.blue()) / 2); |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | return qcol; |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
199 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | void GLCompiler::needMerge() |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | { |
698 | 202 | for (int i = 0; i < countof (m_vboChanged); ++i) |
203 | m_vboChanged[i] = true; | |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | // ============================================================================= |
673
8e6f5b3f9d38
- rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents:
672
diff
changeset
|
207 | // |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | void GLCompiler::stageForCompilation (LDObject* obj) |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
210 | m_staged << obj; |
672
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | } |
0925d25ea32c
- renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
213 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
214 | // |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
215 | void GLCompiler::compileDocument (LDDocument* doc) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
216 | { |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
217 | if (doc == null) |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
218 | return; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
219 | |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
220 | for (LDObject* obj : doc->objects()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
221 | compileObject (obj); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
222 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
223 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
224 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
225 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
226 | void GLCompiler::compileStaged() |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
227 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
228 | removeDuplicates (m_staged); |
700
d2c6592178f9
- only sort and strip duplicates from the objects-staged-to-compile list when actually compiling staged objects, this eliminates needless calls which slowed file loading down a ton.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
699
diff
changeset
|
229 | |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
230 | for (LDObject* obj : m_staged) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
231 | compileObject (obj); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
232 | |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
233 | m_staged.clear(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
234 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
235 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
236 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
237 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
238 | void GLCompiler::prepareVBO (int vbonum) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
239 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
240 | // Compile anything that still awaits it |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
241 | compileStaged(); |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
242 | |
698 | 243 | if (m_vboChanged[vbonum] == false) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
244 | return; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
245 | |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
246 | QVector<GLfloat> vbodata; |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
247 | |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
248 | for (auto it = m_objectInfo.begin(); it != m_objectInfo.end(); ++it) |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
249 | { |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
250 | if (it.key()->document() == getCurrentDocument()) |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
251 | vbodata += it->data[vbonum]; |
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
252 | } |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
253 | |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
254 | glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
255 | glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
256 | glBindBuffer (GL_ARRAY_BUFFER, 0); |
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
257 | checkGLError(); |
698 | 258 | m_vboChanged[vbonum] = false; |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
259 | m_vboSizes[vbonum] = vbodata.size(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
260 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
261 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
262 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
263 | // |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
264 | void GLCompiler::dropObject (LDObject* obj) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
265 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
266 | auto it = m_objectInfo.find (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
267 | |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
268 | if (it != m_objectInfo.end()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
269 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
270 | m_objectInfo.erase (it); |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
271 | needMerge(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
272 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
273 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
274 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
275 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
276 | // |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
277 | void GLCompiler::compileObject (LDObject* obj) |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
278 | { |
699
aca63a3cce36
- fixed zoom value not being initialized properly + some other minor things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
698
diff
changeset
|
279 | print ("compiling #%1 (%2, %3)\n", obj->id(), obj->typeName(), obj->origin()); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
280 | ObjectVBOInfo info; |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
281 | dropObject (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
282 | compileSubObject (obj, obj, &info); |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
283 | m_objectInfo[obj] = info; |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
284 | needMerge(); |
699
aca63a3cce36
- fixed zoom value not being initialized properly + some other minor things
Santeri Piippo <crimsondusk64@gmail.com>
parents:
698
diff
changeset
|
285 | print ("#%1 compiled.\n", obj->id()); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
286 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
287 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
288 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
289 | // |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
290 | void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
291 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
292 | EVBOSurface surface; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
293 | int numverts; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
294 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
295 | switch (poly.num) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
296 | { |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
297 | case 3: surface = VBOSF_Triangles; numverts = 3; break; |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
298 | case 4: surface = VBOSF_Quads; numverts = 4; break; |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
299 | case 2: surface = VBOSF_Lines; numverts = 2; break; |
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
300 | case 5: surface = VBOSF_CondLines; numverts = 2; break; |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
301 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
302 | default: |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
303 | print ("OMGWTFBBQ weird polygon with number %1 (topobj: #%2, %3), origin: %4", |
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
304 | (int) poly.num, topobj->id(), topobj->typeName(), poly.origin); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
305 | assert (false); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
306 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
307 | |
704
d19213bec2f9
- fixed: an overlay that failed to load no longer attempts to reload it over and over again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
703
diff
changeset
|
308 | for (int complement = 0; complement < VBOCM_NumComplements; ++complement) |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
309 | { |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
310 | const int vbonum = vboNumber (surface, (EVBOComplement) complement); |
684
8a56b1d4d44d
- greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
681
diff
changeset
|
311 | QVector<GLfloat>& vbodata = objinfo->data[vbonum]; |
701
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
312 | const QColor normalColor = polygonColor (poly, topobj); |
25b7b4aa9916
- renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents:
700
diff
changeset
|
313 | const QColor pickColor = indexColorForID (topobj->id()); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
314 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
315 | for (int vert = 0; vert < numverts; ++vert) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
316 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
317 | switch ((EVBOComplement) complement) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
318 | { |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
319 | case VBOCM_Surfaces: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
320 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
321 | // Write coordinates. Apparently Z must be flipped too? |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
322 | vbodata << poly.vertices[vert].x() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
323 | << -poly.vertices[vert].y() |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
324 | << -poly.vertices[vert].z(); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
325 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
326 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
327 | |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
328 | case VBOCM_NormalColors: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
329 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
330 | writeColor (vbodata, normalColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
331 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
332 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
333 | |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
334 | case VBOCM_PickColors: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
335 | { |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
336 | writeColor (vbodata, pickColor); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
337 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
338 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
339 | |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
340 | case VBOCM_BFCFrontColors: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
341 | { |
698 | 342 | writeColor (vbodata, g_BFCFrontColor); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
343 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
344 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
345 | |
703
ce2a76cebdbb
- renamed some enumerators, added license header to glcompiler.cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
702
diff
changeset
|
346 | case VBOCM_BFCBackColors: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
347 | { |
698 | 348 | writeColor (vbodata, g_BFCBackColor); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
349 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
350 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
351 | |
704
d19213bec2f9
- fixed: an overlay that failed to load no longer attempts to reload it over and over again
Santeri Piippo <crimsondusk64@gmail.com>
parents:
703
diff
changeset
|
352 | case VBOCM_NumComplements: |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
353 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
354 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
355 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
356 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
357 | } |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
358 | |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
359 | // ============================================================================= |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
360 | // |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
361 | void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, ObjectVBOInfo* objinfo) |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
362 | { |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
363 | switch (obj->type()) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
364 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
365 | // Note: We cannot split quads into triangles here, it would mess up the |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
366 | // wireframe view. Quads must go into separate vbos. |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
367 | case LDObject::ETriangle: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
368 | case LDObject::EQuad: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
369 | case LDObject::ELine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
370 | case LDObject::ECondLine: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
371 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
372 | LDPolygon* poly = obj->getPolygon(); |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
373 | poly->id = topobj->id(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
374 | compilePolygon (*poly, topobj, objinfo); |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
375 | delete poly; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
376 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
377 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
378 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
379 | case LDObject::ESubfile: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
380 | { |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
381 | LDSubfile* ref = static_cast<LDSubfile*> (obj); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
382 | auto data = ref->inlinePolygons(); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
383 | |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
384 | for (LDPolygon& poly : data) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
385 | { |
692
94feb28faffe
- fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
689
diff
changeset
|
386 | poly.id = topobj->id(); |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
387 | compilePolygon (poly, topobj, objinfo); |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
388 | } |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
389 | break; |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
390 | } |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
391 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
392 | default: |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
393 | break; |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
394 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
395 | } |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
396 | |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
397 | // ============================================================================= |
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
398 | // |
679
dd7545e00a8f
- now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents:
678
diff
changeset
|
399 | void GLCompiler::writeColor (QVector<GLfloat>& array, const QColor& color) |
676
f7f965742fd5
- converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents:
675
diff
changeset
|
400 | { |
681
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
401 | array << ((float) color.red()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
402 | << ((float) color.green()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
403 | << ((float) color.blue()) / 255.0f |
c1cc036c6e1f
- work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents:
679
diff
changeset
|
404 | << ((float) color.alpha()) / 255.0f; |
694
3868f52da6b9
- the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents:
693
diff
changeset
|
405 | } |