Fri, 16 Aug 2013 11:05:21 +0300
rework
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include "gldata.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | #include "ldtypes.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | #include "colors.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | #include "file.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | #include "misc.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | #include "gldraw.h" |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | cfg (bool, gl_blackedges, true); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | VertexCompiler::Array::Array() : |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | m_data (null) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | clear(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | VertexCompiler::Array::~Array() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | delete[] m_data; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | void VertexCompiler::Array::clear() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | delete[] m_data; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
443 | 29 | m_data = new Vertex[64]; |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | m_size = 64; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | m_ptr = &m_data[0]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | // ----------------------------------------------------------------------------- |
443 | 36 | void VertexCompiler::Array::resizeToFit (Size newSize) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | if (allocatedSize() >= newSize) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | return; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | int32 cachedWriteSize = writtenSize(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // Add some lee-way space to reduce the amount of resizing. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | newSize += 256; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
443 | 45 | const Size oldSize = allocatedSize(); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | // We need to back up the data first |
443 | 48 | Vertex* copy = new Vertex[oldSize]; |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | memcpy (copy, m_data, oldSize); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // Re-create the buffer |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | delete[] m_data; |
443 | 53 | m_data = new Vertex[newSize]; |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | m_size = newSize; |
443 | 55 | m_ptr = &m_data[cachedWriteSize / sizeof (Vertex)]; |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // Copy the data back |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | memcpy (m_data, copy, oldSize); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | delete[] copy; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | // ----------------------------------------------------------------------------- |
443 | 64 | const VertexCompiler::Vertex* VertexCompiler::Array::data() const { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | return m_data; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | // ----------------------------------------------------------------------------- |
443 | 70 | const VertexCompiler::Array::Size& VertexCompiler::Array::allocatedSize() const { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | return m_size; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | // ----------------------------------------------------------------------------- |
443 | 76 | VertexCompiler::Array::Size VertexCompiler::Array::writtenSize() const { |
77 | return (m_ptr - m_data) * sizeof (Vertex); | |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | // ----------------------------------------------------------------------------- |
443 | 82 | void VertexCompiler::Array::write (const Vertex& f) { |
83 | // Ensure there's enoughspace for the new vertex | |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | resizeToFit (writtenSize() + sizeof f); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | // Write the float in |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | *m_ptr++ = f; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | void VertexCompiler::Array::merge ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | Array* other |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | // Ensure there's room for both buffers |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | resizeToFit (writtenSize() + other->writtenSize()); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | memcpy (m_ptr, other->data(), other->writtenSize()); |
443 | 99 | m_ptr += other->writtenSize() / sizeof (Vertex); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // ----------------------------------------------------------------------------- |
443 | 104 | VertexCompiler::VertexCompiler() : m_file (null) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | for (int i = 0; i < NumArrays; ++i) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | m_mainArrays[i] = new Array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | m_changed[i] = false; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | VertexCompiler::~VertexCompiler() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | for (Array* array : m_mainArrays) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | delete array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | // ----------------------------------------------------------------------------- |
443 | 120 | void VertexCompiler::compileVertex (::vertex v, QColor col, Array* array) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | VertexCompiler::Vertex glvertex; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | glvertex.x = v.x(); |
443 | 123 | glvertex.y = -v.y(); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | glvertex.z = v.z(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | glvertex.color = |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | (col.red() & 0xFF) << 0x00 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | (col.green() & 0xFF) << 0x08 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | (col.blue() & 0xFF) << 0x10 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | (col.alpha() & 0xFF) << 0x18; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | array->write (glvertex); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | // ----------------------------------------------------------------------------- |
443 | 136 | // Note: we use the true object's color but the draw object's vertices. This is |
137 | // so that the index color is generated correctly - it has to reference the true | |
138 | // object's ID. This is crucial for picking to work. | |
139 | void VertexCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj) { | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
140 | Array** arrays = m_objArrays[trueobj]; |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
141 | LDObject::Type objtype = drawobj->getType(); |
443 | 142 | const bool isline = (objtype == LDObject::Line || objtype == LDObject::CondLine); |
143 | const int verts = isline ? 2 : drawobj->vertices(); | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
144 | |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
145 | QColor normalColor = getObjectColor (trueobj, Normal), |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
146 | pickColor = getObjectColor (trueobj, PickColor); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | for (int i = 0; i < verts; ++i) { |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
149 | compileVertex (drawobj->getVertex (i), normalColor, arrays[isline ? EdgeArray : MainArray]); |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
150 | compileVertex (drawobj->getVertex (i), pickColor, arrays[isline ? EdgePickArray : PickArray]); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
443 | 153 | // For non-lines, compile BFC data. Note that the front objects are what get |
154 | // reversed here! This is because we invert the Y axis, which inverts the | |
155 | // entire part model, so we remedy that here. | |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | if (!isline) { |
443 | 157 | QColor col = getObjectColor (trueobj, BFCBack); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | for (int i = 0; i < verts; ++i) |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
159 | compileVertex (drawobj->getVertex(i), col, arrays[BFCArray]); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
443 | 161 | col = getObjectColor (trueobj, BFCFront); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | for (int i = verts - 1; i >= 0; --i) |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
163 | compileVertex (drawobj->getVertex(i), col, arrays[BFCArray]); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | // ----------------------------------------------------------------------------- |
443 | 169 | void VertexCompiler::compileObject (LDObject* obj, LDObject* topobj) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | if (m_objArrays.find (obj) == m_objArrays.end()) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | m_objArrays[obj] = new Array*[NumArrays]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | m_objArrays[obj][i] = new Array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | } else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | m_objArrays[obj][i]->clear(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
179 | |
443 | 180 | List<LDObject*> objs; |
181 | ||
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | switch (obj->getType()) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | case LDObject::Triangle: |
443 | 184 | compilePolygon (obj, topobj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | m_changed[MainArray] = true; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | case LDObject::Quad: |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | for (LDTriangleObject* triangle : static_cast<LDQuadObject*> (obj)->splitToTriangles()) |
443 | 190 | compilePolygon (triangle, topobj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | m_changed[MainArray] = true; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | case LDObject::Line: |
443 | 195 | compilePolygon (obj, topobj); |
196 | break; | |
197 | ||
198 | case LDObject::Subfile: | |
199 | objs = static_cast<LDSubfileObject*> (obj)->inlineContents (true, true); | |
200 | ||
201 | for (LDObject* obj : objs) { | |
202 | compileObject (obj, topobj); | |
203 | delete obj; | |
204 | } | |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | default: |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | void VertexCompiler::compileFile() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | for (LDObject* obj : *m_file) |
443 | 216 | compileObject (obj, obj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | // ----------------------------------------------------------------------------- |
443 | 221 | void VertexCompiler::forgetObject (LDObject* obj) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | delete m_objArrays[obj][i]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | delete m_objArrays[obj]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | m_objArrays.remove (obj); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | // ----------------------------------------------------------------------------- |
443 | 231 | void VertexCompiler::setFile (LDFile* file) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | m_file = file; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | // ----------------------------------------------------------------------------- |
443 | 237 | VertexCompiler::Array* VertexCompiler::getMergedBuffer (ArrayType type) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | assert (type < NumArrays); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | if (m_changed) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | m_changed[type] = false; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | m_mainArrays[type]->clear(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | for (LDObject* obj : *m_file) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | auto it = m_objArrays.find (obj); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | if (it != m_objArrays.end()) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | m_mainArrays[type]->merge ((*it)[type]); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | return m_mainArrays[type]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | static List<short> g_warnedColors; |
443 | 258 | QColor VertexCompiler::getObjectColor (LDObject* obj, ColorType colotype) const { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | QColor qcol; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | if (!obj->isColored()) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | return QColor(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
264 | if (colotype == PickColor) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | // Make the color by the object's ID if we're picking, so we can make the |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | // ID again from the color we get from the picking results. Be sure to use |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | // the top level parent's index since we want a subfile's children point |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | // to the subfile itself. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | long i = obj->topLevelParent()->id(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | // Calculate a color based from this index. This method caters for |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | // 16777216 objects. I don't think that'll be exceeded anytime soon. :) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | // ATM biggest is 53588.dat with 12600 lines. |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
274 | int r = (i / (256 * 256)) % 256, |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | g = (i / 256) % 256, |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | b = i % 256; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
278 | return QColor (r, g, b); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | if ((colotype == BFCFront || colotype == BFCBack) && |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | obj->getType() != LDObject::Line && |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
283 | obj->getType() != LDObject::CondLine) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
285 | if (colotype == BFCFront) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | qcol = QColor (40, 192, 0); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | else |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | qcol = QColor (224, 0, 0); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | } else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | if (obj->color() == maincolor) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | qcol = GL::getMainColor(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | LDColor* col = getColor (obj->color()); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | if (col) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | qcol = col->faceColor; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | if (obj->color() == edgecolor) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | qcol = QColor (32, 32, 32); // luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | LDColor* col; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | if (!gl_blackedges && obj->parent() && (col = getColor (obj->parent()->color()))) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | qcol = col->edgeColor; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | if (qcol.isValid() == false) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | // The color was unknown. Use main color to make the object at least |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | // not appear pitch-black. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | if (obj->color() != edgecolor) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | qcol = GL::getMainColor(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | // Warn about the unknown colors, but only once. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | for (short i : g_warnedColors) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | if (obj->color() == i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | return Qt::black; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | print ("%1: Unknown color %2!\n", __func__, obj->color()); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | g_warnedColors << obj->color(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | return Qt::black; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | if (obj->topLevelParent()->selected()) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | // Brighten it up for the select list. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | const uchar add = 51; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | qcol.setRed (min (qcol.red() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | qcol.setGreen (min (qcol.green() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | qcol.setBlue (min (qcol.blue() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | return qcol; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | } |