Fri, 09 Aug 2013 04:29:37 +0300
Picking now works with the VAO setup
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | m_data = new DataType[64]; |
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 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | void VertexCompiler::Array::resizeToFit ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | VertexCompiler::Array::SizeType newSize |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | if (allocatedSize() >= newSize) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | return; |
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 | int32 cachedWriteSize = writtenSize(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | // 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
|
45 | newSize += 256; |
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 | const SizeType oldSize = allocatedSize(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | // We need to back up the data first |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | DataType* copy = new DataType[oldSize]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | memcpy (copy, m_data, oldSize); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // Re-create the buffer |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | delete[] m_data; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | m_data = new DataType[newSize]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | m_size = newSize; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | m_ptr = &m_data[cachedWriteSize / sizeof (DataType)]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // Copy the data back |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | memcpy (m_data, copy, oldSize); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | delete[] copy; |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | const VertexCompiler::Array::DataType* VertexCompiler::Array::data() const { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | return m_data; |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | const VertexCompiler::Array::SizeType& VertexCompiler::Array::allocatedSize() const { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | return m_size; |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | VertexCompiler::Array::SizeType VertexCompiler::Array::writtenSize() const { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | return (m_ptr - m_data) * sizeof (DataType); |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | void VertexCompiler::Array::write ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | VertexCompiler::Array::DataType f |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | // Ensure there's enoughspace for the new float |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | resizeToFit (writtenSize() + sizeof f); |
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 | // Write the float in |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | *m_ptr++ = f; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | |
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 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | void VertexCompiler::Array::merge ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | Array* other |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // Ensure there's room for both buffers |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | resizeToFit (writtenSize() + other->writtenSize()); |
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 | memcpy (m_ptr, other->data(), other->writtenSize()); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | m_ptr += other->writtenSize() / sizeof (DataType); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | VertexCompiler::VertexCompiler() : |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | m_file (null) |
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 | for (int i = 0; i < NumArrays; ++i) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | m_mainArrays[i] = new Array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | m_changed[i] = false; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
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 | VertexCompiler::~VertexCompiler() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | for (Array* array : m_mainArrays) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | delete array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | void VertexCompiler::compileVertex ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | vertex v, |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | QColor col, |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | Array* array |
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 | VertexCompiler::Vertex glvertex; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | glvertex.x = v.x(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | glvertex.y = v.y(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | glvertex.z = v.z(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | glvertex.color = |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | (col.red() & 0xFF) << 0x00 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | (col.green() & 0xFF) << 0x08 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | (col.blue() & 0xFF) << 0x10 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | (col.alpha() & 0xFF) << 0x18; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | array->write (glvertex); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | void VertexCompiler::compilePolygon ( |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
147 | LDObject* drawobj, |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
148 | LDObject* trueobj |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | ) { |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
150 | // Note: we use the true object's color but the draw object's vertices. This |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
151 | // is so that the index color is generated correctly - it has to reference |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
152 | // the true object's ID, this is crucial for picking to work. |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
153 | Array** arrays = m_objArrays[trueobj]; |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
154 | LDObject::Type objtype = drawobj->getType(); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | bool isline = (objtype == LDObject::Line || objtype == LDObject::CondLine); |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
156 | int verts = isline ? 2 : drawobj->vertices(); |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
157 | |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
158 | QColor normalColor = getObjectColor (trueobj, Normal), |
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
159 | pickColor = getObjectColor (trueobj, PickColor); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | 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
|
162 | 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
|
163 | 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
|
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 | // For non-lines, compile BFC data |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | if (!isline) { |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
168 | QColor col = getObjectColor (trueobj, BFCFront); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | 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
|
170 | 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
|
171 | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
172 | col = getObjectColor (trueobj, BFCBack); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | 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
|
174 | 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
|
175 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | |
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 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
180 | void VertexCompiler::compileObject ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
181 | LDObject* obj |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
182 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
183 | 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
|
184 | m_objArrays[obj] = new Array*[NumArrays]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
185 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
186 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | m_objArrays[obj][i] = new Array; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | } else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | m_objArrays[obj][i]->clear(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | switch (obj->getType()) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | case LDObject::Triangle: |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
195 | compilePolygon (obj, obj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | m_changed[MainArray] = true; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | case LDObject::Quad: |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | for (LDTriangleObject* triangle : static_cast<LDQuadObject*> (obj)->splitToTriangles()) |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
201 | compilePolygon (triangle, obj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | m_changed[MainArray] = true; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | case LDObject::Line: |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
206 | compilePolygon (obj, obj); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | break; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | default: |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | break; |
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 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | void VertexCompiler::compileFile() { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | for (LDObject* obj : *m_file) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | compileObject (obj); |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | void VertexCompiler::forgetObject ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | LDObject* obj |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | for (int i = 0; i < NumArrays; ++i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | delete m_objArrays[obj][i]; |
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 | delete m_objArrays[obj]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | m_objArrays.remove (obj); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | |
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 | void VertexCompiler::setFile ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | LDFile* file |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | m_file = file; |
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 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | VertexCompiler::Array* VertexCompiler::getMergedBuffer ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | VertexCompiler::MergedArrayType type |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | ) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | assert (type < NumArrays); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | if (m_changed) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | m_changed[type] = false; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | m_mainArrays[type]->clear(); |
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 | for (LDObject* obj : *m_file) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | auto it = m_objArrays.find (obj); |
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 | if (it != m_objArrays.end()) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | m_mainArrays[type]->merge ((*it)[type]); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | return m_mainArrays[type]; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | // ============================================================================= |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | // ----------------------------------------------------------------------------- |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | static List<short> g_warnedColors; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | QColor VertexCompiler::getObjectColor ( |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | LDObject* obj, |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | ColorType colotype |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | ) const { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | QColor qcol; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | if (!obj->isColored()) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | return QColor(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
275 | if (colotype == PickColor) { |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | // 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
|
277 | // 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
|
278 | // 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
|
279 | // to the subfile itself. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | long i = obj->topLevelParent()->id(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | // 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
|
283 | // 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
|
284 | // 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
|
285 | int r = (i / (256 * 256)) % 256, |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | g = (i / 256) % 256, |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | b = i % 256; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | |
442
4852e815df29
Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents:
441
diff
changeset
|
289 | return QColor (r, g, b); |
441
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
291 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | if ((colotype == BFCFront || colotype == BFCBack) && |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | obj->getType() != LDObject::Line && |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | obj->getType() != LDObject::CondLine) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | if (colotype == BFCFront) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | qcol = QColor (40, 192, 0); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | else |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | qcol = QColor (224, 0, 0); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | } else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | if (obj->color() == maincolor) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | qcol = GL::getMainColor(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | else { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | LDColor* col = getColor (obj->color()); |
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 | if (col) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | qcol = col->faceColor; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | |
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 = 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
|
312 | LDColor* col; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | 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
|
315 | qcol = col->edgeColor; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | } |
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 | if (qcol.isValid() == false) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
319 | // 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
|
320 | // not appear pitch-black. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
321 | if (obj->color() != edgecolor) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | qcol = GL::getMainColor(); |
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 | // 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
|
325 | for (short i : g_warnedColors) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | if (obj->color() == i) |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | return Qt::black; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | 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
|
330 | g_warnedColors << obj->color(); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
331 | return Qt::black; |
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 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | if (obj->topLevelParent()->selected()) { |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | // Brighten it up for the select list. |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | const uchar add = 51; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | qcol.setRed (min (qcol.red() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | qcol.setGreen (min (qcol.green() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | qcol.setBlue (min (qcol.blue() + add, 255)); |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | } |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | return qcol; |
a958f6925088
BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | } |