src/GLCompiler.cc

Tue, 11 Mar 2014 15:44:27 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 11 Mar 2014 15:44:27 +0200
changeset 702
8e3058cb9281
parent 701
25b7b4aa9916
child 703
ce2a76cebdbb
permissions
-rw-r--r--

- subfile coloring now works again

676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
1 #define GL_GLEXT_PROTOTYPES
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
2 #include <GL/glu.h>
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
3 #include <GL/glext.h>
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 #include "GLCompiler.h"
675
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 674
diff changeset
5 #include "LDObject.h"
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 674
diff changeset
6 #include "Colors.h"
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 674
diff changeset
7 #include "Document.h"
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 674
diff changeset
8 #include "Misc.h"
450827da2376 Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 674
diff changeset
9 #include "GLRenderer.h"
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
10 #include "Dialogs.h"
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
11
695
4ace632e247b - ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents: 694
diff changeset
12 cfg (String, gl_selectcolor, "#0080FF")
4ace632e247b - ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents: 694
diff changeset
13
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
14 struct GLErrorInfo
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
15 {
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
16 GLenum value;
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
17 QString text;
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
18 };
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
19
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
20 static const GLErrorInfo g_GLErrors[] =
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
21 {
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
22 { GL_NO_ERROR, "No error" },
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
23 { GL_INVALID_ENUM, "Unacceptable enumerator passed" },
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
24 { GL_INVALID_VALUE, "Numeric argument out of range" },
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
25 { 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
26 { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"},
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
27 { GL_OUT_OF_MEMORY, "Out of memory" },
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
28 { 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
29 { 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
30 };
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
32 #include <QTime>
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
33
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
34 #define CLOCK_INIT QTime t0;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
35
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
36 #define CLOCK_START \
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 t0 = QTime::currentTime(); \
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
39 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
40
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
41 #define CLOCK_TIME(A) \
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
42 { \
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
43 fprint (stderr, A ": %1ms\n", t0.msecsTo (QTime::currentTime())); \
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
44 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
45
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
46 #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__)
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 extern_cfg (Bool, gl_blackedges);
702
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
49 extern_cfg (String, gl_bgcolor);
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
50 static QList<short> g_warnedColors;
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
51 static const QColor g_BFCFrontColor (40, 192, 40);
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
52 static const QColor g_BFCBackColor (224, 40, 40);
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 // =============================================================================
673
8e6f5b3f9d38 - rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 672
diff changeset
55 //
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
56 void checkGLError_private (const char* file, int line)
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
57 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
58 QString errmsg;
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
59 GLenum errnum = glGetError();
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
60
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
61 if (errnum == GL_NO_ERROR)
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
62 return;
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
63
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
64 for (const GLErrorInfo& err : g_GLErrors)
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
65 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
66 if (err.value == errnum)
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
67 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
68 errmsg = err.text;
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
69 break;
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
70 }
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
71 }
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
72
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 689
diff changeset
73 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
74 }
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
75
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
76 // =============================================================================
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
77 //
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
78 GLCompiler::GLCompiler()
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 {
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
80 needMerge();
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
81 memset (m_vboSizes, 0, sizeof m_vboSizes);
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
82 }
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
83
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
84 // =============================================================================
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
85 //
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
86 void GLCompiler::initialize()
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
87 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
88 glGenBuffers (g_numVBOs, &m_vbo[0]);
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
89 checkGLError();
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
92 // =============================================================================
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
93 //
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
94 GLCompiler::~GLCompiler()
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
96 glDeleteBuffers (g_numVBOs, &m_vbo[0]);
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
97 checkGLError();
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // =============================================================================
673
8e6f5b3f9d38 - rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 672
diff changeset
101 //
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
102 uint32 GLCompiler::colorToRGB (const QColor& color)
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 {
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 return
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 (color.red() & 0xFF) << 0x00 |
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 (color.green() & 0xFF) << 0x08 |
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 (color.blue() & 0xFF) << 0x10 |
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 (color.alpha() & 0xFF) << 0x18;
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // =============================================================================
673
8e6f5b3f9d38 - rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 672
diff changeset
112 //
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
113 QColor GLCompiler::indexColorForID (int id) const
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
114 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
115 // 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
116 // 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
117 int r = (id / 0x10000) % 0x100,
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
118 g = (id / 0x100) % 0x100,
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
119 b = id % 0x100;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
120
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
121 return QColor (r, g, b);
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
122 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
123
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
124 // =============================================================================
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
125 //
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
126 QColor GLCompiler::polygonColor (LDPolygon& poly, LDObject* topobj) const
672
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 QColor qcol;
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
130 if (poly.color == maincolor)
702
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
131 {
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
132 if (topobj->color() == maincolor)
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
133 qcol = GLRenderer::getMainColor();
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
134 else
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
135 qcol = getColor (topobj->color())->faceColor;
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
136 }
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
137 elif (poly.color == edgecolor)
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
138 {
8e3058cb9281 - subfile coloring now works again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 701
diff changeset
139 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
140 }
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 else
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
143 LDColor* col = getColor (poly.color);
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
144
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
145 if (col)
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
146 qcol = col->faceColor;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
147 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
148
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
149 if (qcol.isValid() == false)
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
150 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
151 // 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
152 // not appear pitch-black.
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
153 if (poly.num != 2 && poly.num != 5)
674
3d8ab0f89102 - refactoring
Santeri Piippo <crimsondusk64@gmail.com>
parents: 673
diff changeset
154 qcol = GLRenderer::getMainColor();
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 else
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
156 qcol = Qt::black;
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
158 // Warn about the unknown color, but only once.
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
159 if (g_warnedColors.contains (poly.color) == false)
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
160 {
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
161 print ("Unknown color %1!\n", poly.color);
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
162 g_warnedColors << poly.color;
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
163 }
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
165 return qcol;
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
168 if (topobj->isSelected())
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 {
695
4ace632e247b - ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents: 694
diff changeset
170 // 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
171 QColor selcolor (gl_selectcolor);
4ace632e247b - ported over the selected color blend from master
Santeri Piippo <crimsondusk64@gmail.com>
parents: 694
diff changeset
172 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
173 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
174 qcol.setBlue ((qcol.blue() + selcolor.blue()) / 2);
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 return qcol;
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 // =============================================================================
673
8e6f5b3f9d38 - rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 672
diff changeset
181 //
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 void GLCompiler::needMerge()
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 {
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
184 for (int i = 0; i < countof (m_vboChanged); ++i)
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
185 m_vboChanged[i] = true;
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 }
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 // =============================================================================
673
8e6f5b3f9d38 - rename GLCompiler::Vertex to GLCompiler::VAO to avoid name conflicts
Santeri Piippo <crimsondusk64@gmail.com>
parents: 672
diff changeset
189 //
672
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 void GLCompiler::stageForCompilation (LDObject* obj)
0925d25ea32c - renamed VertexCompiler to GLCompiler
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
192 m_staged << obj;
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
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
195 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
196 //
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
197 void GLCompiler::compileDocument (LDDocument* doc)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
198 {
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
199 if (doc == null)
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
200 return;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
201
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
202 for (LDObject* obj : doc->objects())
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
203 compileObject (obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
204 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
205
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
206 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
207 //
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
208 void GLCompiler::compileStaged()
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
209 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
210 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
211
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
212 for (LDObject* obj : m_staged)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
213 compileObject (obj);
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
214
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
215 m_staged.clear();
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
216 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
217
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
218 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
219 //
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
220 void GLCompiler::prepareVBO (int vbonum)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
221 {
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
222 // Compile anything that still awaits it
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
223 compileStaged();
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
224
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
225 if (m_vboChanged[vbonum] == false)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
226 return;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
227
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
228 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
229
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
230 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
231 {
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
232 if (it.key()->document() == getCurrentDocument())
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
233 vbodata += it->data[vbonum];
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
234 }
684
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
235
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
236 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
237 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
238 glBindBuffer (GL_ARRAY_BUFFER, 0);
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
239 checkGLError();
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
240 m_vboChanged[vbonum] = false;
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
241 m_vboSizes[vbonum] = vbodata.size();
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
242 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
243
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
244 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
245 //
684
8a56b1d4d44d - greatly improved the GL compiler, now deals colors and object removal properly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 681
diff changeset
246 void GLCompiler::dropObject (LDObject* obj)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
247 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
248 auto it = m_objectInfo.find (obj);
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
249
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
250 if (it != m_objectInfo.end())
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
251 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
252 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
253 needMerge();
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
254 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
255 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
256
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
257 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
258 //
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
259 void GLCompiler::compileObject (LDObject* obj)
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
260 {
699
aca63a3cce36 - fixed zoom value not being initialized properly + some other minor things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 698
diff changeset
261 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
262 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
263 dropObject (obj);
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
264 compileSubObject (obj, obj, &info);
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
265 m_objectInfo[obj] = info;
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
266 needMerge();
699
aca63a3cce36 - fixed zoom value not being initialized properly + some other minor things
Santeri Piippo <crimsondusk64@gmail.com>
parents: 698
diff changeset
267 print ("#%1 compiled.\n", obj->id());
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
268 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
269
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
270 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
271 //
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
272 void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
273 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
274 EVBOSurface surface;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
275 int numverts;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
276
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
277 switch (poly.num)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
278 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
279 case 3: surface = vboTriangles; numverts = 3; break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
280 case 4: surface = vboQuads; numverts = 4; break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
281 case 2: surface = vboLines; numverts = 2; break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
282 case 5: surface = vboCondLines; numverts = 2; break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
283
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
284 default:
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 689
diff changeset
285 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
286 (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
287 assert (false);
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
288 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
289
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
290 for (int complement = 0; complement < vboNumComplements; ++complement)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
291 {
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
292 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
293 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
701
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
294 const QColor normalColor = polygonColor (poly, topobj);
25b7b4aa9916 - renamed several GLCompiler members and methods
Santeri Piippo <crimsondusk64@gmail.com>
parents: 700
diff changeset
295 const QColor pickColor = indexColorForID (topobj->id());
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
296
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
297 for (int vert = 0; vert < numverts; ++vert)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
298 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
299 switch ((EVBOComplement) complement)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
300 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
301 case vboSurfaces:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
302 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
303 // Write coordinates. Apparently Z must be flipped too?
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
304 vbodata << poly.vertices[vert].x()
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
305 << -poly.vertices[vert].y()
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
306 << -poly.vertices[vert].z();
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
307 break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
308 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
309
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
310 case vboNormalColors:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
311 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
312 writeColor (vbodata, normalColor);
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
313 break;
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
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
316 case vboPickColors:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
317 {
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
318 writeColor (vbodata, pickColor);
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
319 break;
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
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
322 case vboBFCFrontColors:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
323 {
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
324 writeColor (vbodata, g_BFCFrontColor);
681
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
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
328 case vboBFCBackColors:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
329 {
698
16e6d7d87982 - refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 695
diff changeset
330 writeColor (vbodata, g_BFCBackColor);
681
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
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
334 case vboNumComplements:
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
335 break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
336 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
337 }
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 }
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
340
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
341 // =============================================================================
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
342 //
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
343 void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, ObjectVBOInfo* objinfo)
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
344 {
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 689
diff changeset
345 switch (obj->type())
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
346 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
347 // 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
348 // wireframe view. Quads must go into separate vbos.
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
349 case LDObject::ETriangle:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
350 case LDObject::EQuad:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
351 case LDObject::ELine:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
352 case LDObject::ECondLine:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
353 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
354 LDPolygon* poly = obj->getPolygon();
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 689
diff changeset
355 poly->id = topobj->id();
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
356 compilePolygon (*poly, topobj, objinfo);
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
357 delete poly;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
358 break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
359 }
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
360
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
361 case LDObject::ESubfile:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
362 {
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
363 LDSubfile* ref = static_cast<LDSubfile*> (obj);
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
364 auto data = ref->inlinePolygons();
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
365
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
366 for (LDPolygon& poly : data)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
367 {
692
94feb28faffe - fixed build errors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 689
diff changeset
368 poly.id = topobj->id();
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
369 compilePolygon (poly, topobj, objinfo);
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
370 }
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
371 break;
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
372 }
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
373
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
374 default:
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
375 break;
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
376 }
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
377 }
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 // =============================================================================
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
380 //
679
dd7545e00a8f - now actually renders stuff correctly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 678
diff changeset
381 void GLCompiler::writeColor (QVector<GLfloat>& array, const QColor& color)
676
f7f965742fd5 - converted to VBO
Santeri Piippo <crimsondusk64@gmail.com>
parents: 675
diff changeset
382 {
681
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
383 array << ((float) color.red()) / 255.0f
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
384 << ((float) color.green()) / 255.0f
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
385 << ((float) color.blue()) / 255.0f
c1cc036c6e1f - work on improved rendering performance
Santeri Piippo <crimsondusk64@gmail.com>
parents: 679
diff changeset
386 << ((float) color.alpha()) / 255.0f;
694
3868f52da6b9 - the GL compiler now supports multiple documents
Santeri Piippo <crimsondusk64@gmail.com>
parents: 693
diff changeset
387 }

mercurial