src/gldata.cpp

Mon, 09 Sep 2013 23:35:32 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 09 Sep 2013 23:35:32 +0300
changeset 490
fff86085017e
parent 489
0b32138fedcc
child 666
c595cfb4791c
permissions
-rw-r--r--

Stuff

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"
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
7 #include <QDate>
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
9 cfg (Bool, gl_blackedges, false);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
10 static List<short> g_warnedColors;
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
11 VertexCompiler g_vertexCompiler;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 // =============================================================================
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 VertexCompiler::Array::Array() :
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 m_data (null)
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 clear();
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
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 // =============================================================================
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 VertexCompiler::Array::~Array() {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 delete[] m_data;
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
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 // =============================================================================
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 void VertexCompiler::Array::clear() {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 delete[] m_data;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
32 m_data = new Vertex[64];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 m_size = 64;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 m_ptr = &m_data[0];
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
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
39 void VertexCompiler::Array::resizeToFit (Size newSize) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 if (allocatedSize() >= newSize)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 return;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 int32 cachedWriteSize = writtenSize();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 // 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
46 newSize += 256;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
48 const Size oldSize = allocatedSize();
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // We need to back up the data first
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
51 Vertex* copy = new Vertex[oldSize];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 memcpy (copy, m_data, oldSize);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 // Re-create the buffer
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 delete[] m_data;
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
56 m_data = new Vertex[newSize];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 m_size = newSize;
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
58 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
59
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 // Copy the data back
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 memcpy (m_data, copy, oldSize);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 delete[] copy;
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
67 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
68 return m_data;
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
73 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
74 return m_size;
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
79 VertexCompiler::Array::Size VertexCompiler::Array::writtenSize() const {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
80 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
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
85 void VertexCompiler::Array::write (const Vertex& f) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
86 // 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
87 resizeToFit (writtenSize() + sizeof 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 // Write the float in
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 *m_ptr++ = f;
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
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 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
95 void VertexCompiler::Array::merge (Array* other) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 // Ensure there's room for both buffers
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 resizeToFit (writtenSize() + other->writtenSize());
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 memcpy (m_ptr, other->data(), other->writtenSize());
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
100 m_ptr += other->writtenSize() / sizeof (Vertex);
441
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 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
105 VertexCompiler::VertexCompiler() :
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
106 m_file (null)
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
107 {
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
108 needMerge();
441
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
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
111 VertexCompiler::~VertexCompiler() {}
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
112
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // =============================================================================
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
114 // Note: we use the top level object's color but the draw object's vertices.
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
115 // This is so that the index color is generated correctly - it has to reference
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
116 // the top level object's ID. This is crucial for picking to work.
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 // -----------------------------------------------------------------------------
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
118 void VertexCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj, List<CompiledTriangle>& data) {
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
119 const QColor pickColor = getObjectColor (trueobj, PickColor);
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
120 LDObject::Type type = drawobj->getType();
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
121 List<LDObject*> objs;
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
122
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
123 assert (type != LDObject::Subfile);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
125 if (type == LDObject::Quad) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
126 for (LDTriangle* t : static_cast<LDQuad*> (drawobj)->splitToTriangles())
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
127 objs << t;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
128 } else
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
129 objs << drawobj;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
131 for (LDObject* obj : objs) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
132 const LDObject::Type objtype = obj->getType();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
133 const bool isline = (objtype == LDObject::Line || objtype == LDObject::CndLine);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
134 const int verts = isline ? 2 : obj->vertices();
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
135 QColor normalColor = getObjectColor (obj, Normal);
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
136
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
137 assert (isline || objtype == LDObject::Triangle);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
139 CompiledTriangle a;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
140 a.rgb = normalColor.rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
141 a.pickrgb = pickColor.rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
142 a.numVerts = verts;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
143 a.obj = trueobj;
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
144 a.isCondLine = (objtype == LDObject::CndLine);
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
145
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
146 for (int i = 0; i < verts; ++i) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
147 a.verts[i] = obj->getVertex (i);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
148 a.verts[i].y() = -a.verts[i].y();
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
149 a.verts[i].z() = -a.verts[i].z();
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
150 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
151
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
152 data << a;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 // -----------------------------------------------------------------------------
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
158 void VertexCompiler::compileObject (LDObject* obj) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
159 initObject (obj);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
160 List<CompiledTriangle> data;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
161 QTime t0;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
162
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
163 for (int i = 0; i < GL::NumArrays; ++i)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
164 m_objArrays[obj][i].clear();
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
165
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
166 t0 = QTime::currentTime();
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
167 compileSubObject (obj, obj, data);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
168 print ("COMPILATION: %1ms\n", t0.msecsTo (QTime::currentTime()));
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
169
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
170 t0 = QTime::currentTime();
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
171 for (int i = 0; i < GL::NumArrays; ++i) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
172 GL::VAOType type = (GL::VAOType) i;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
173 const bool islinearray = (type == GL::EdgeArray || type == GL::EdgePickArray);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
174
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
175 for (const CompiledTriangle& poly : data) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
176 if (poly.isCondLine) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
177 // Conditional lines go to the edge pick array and the array
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
178 // specifically designated for conditional lines and nowhere else.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
179 if (type != GL::EdgePickArray && type != GL::CondEdgeArray)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
180 continue;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
181 } else {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
182 // Lines and only lines go to the line array and only to the line array.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
183 if ((poly.numVerts == 2) ^ islinearray)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
184 continue;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
185
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
186 // Only conditional lines go into the conditional line array
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
187 if (type == GL::CondEdgeArray)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
188 continue;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
189 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
190
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
191 Array* verts = postprocess (poly, type);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
192 m_objArrays[obj][type].merge (verts);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
193 delete verts;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
194 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
195 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
196 print ("POST-PROCESS: %1ms\n", t0.msecsTo (QTime::currentTime()));
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
197
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
198 needMerge();
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
199 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
200
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
201 // =============================================================================
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
202 // -----------------------------------------------------------------------------
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
203 void VertexCompiler::compileSubObject (LDObject* obj, LDObject* topobj, List<CompiledTriangle>& data) {
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
204 List<LDObject*> objs;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
205
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 switch (obj->getType()) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 case LDObject::Triangle:
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
208 case LDObject::Line:
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
209 case LDObject::CndLine:
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
210 compilePolygon (obj, topobj, data);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 break;
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 case LDObject::Quad:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
214 for (LDTriangle* triangle : static_cast<LDQuad*> (obj)->splitToTriangles())
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
215 compilePolygon (triangle, topobj, data);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
218 case LDObject::Subfile:
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
219 {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
220 QTime t0 = QTime::currentTime();
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
221 objs = static_cast<LDSubfile*> (obj)->inlineContents (LDSubfile::RendererInline | LDSubfile::DeepCacheInline);
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
222 print ("\t- INLINE: %1ms\n", t0.msecsTo (QTime::currentTime()));
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
223 print ("\t- %1 objects\n", objs.size());
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
224
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
225 t0 = QTime::currentTime();
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
226 for (LDObject* obj : objs) {
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
227 compileSubObject (obj, topobj, data);
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
228 delete obj;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
229 }
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
230 print ("\t- SUB-COMPILATION: %1ms\n", t0.msecsTo (QTime::currentTime()));
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
231 }
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 break;
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 default:
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 }
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
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 void VertexCompiler::compileFile() {
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
242 for (LDObject* obj : m_file->objects())
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
243 compileObject (obj);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 }
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 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
248 void VertexCompiler::forgetObject (LDObject* obj) {
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
249 auto it = m_objArrays.find (obj);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
250 if (it != m_objArrays.end())
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
251 delete *it;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
252
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 m_objArrays.remove (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
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
258 void VertexCompiler::setFile (LDFile* file) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 m_file = file;
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
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 // -----------------------------------------------------------------------------
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
264 const VertexCompiler::Array* VertexCompiler::getMergedBuffer (GL::VAOType type) {
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
265 // If there are objects staged for compilation, compile them now.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
266 if (m_staged.size() > 0) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
267 for (LDObject* obj : m_staged)
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
268 compileObject (obj);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
269
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
270 m_staged.clear();
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
271 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
272
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
273 assert (type < GL::NumArrays);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
275 if (m_changed[type]) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 m_changed[type] = false;
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
277 m_mainArrays[type].clear();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
278
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
279 for (LDObject* obj : m_file->objects()) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
280 if (!obj->isScemantic())
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
281 continue;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
282
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 auto it = m_objArrays.find (obj);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
285 if (it != m_objArrays.end())
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
286 m_mainArrays[type].merge (&(*it)[type]);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 }
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
288
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
289 print ("merged array %1: %2 bytes\n", (int) type, m_mainArrays[type].writtenSize());
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
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
292 return &m_mainArrays[type];
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
293 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
294
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
295 // =============================================================================
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
296 // This turns a compiled triangle into usable VAO vertices
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
297 // -----------------------------------------------------------------------------
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
298 VertexCompiler::Array* VertexCompiler::postprocess (const CompiledTriangle& triangle, GL::VAOType type) {
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
299 Array* va = new Array;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
300 List<Vertex> verts;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
301
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
302 for (int i = 0; i < triangle.numVerts; ++i) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
303 alias v0 = triangle.verts[i];
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
304 Vertex v;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
305 v.x = v0.x();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
306 v.y = v0.y();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
307 v.z = v0.z();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
308
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
309 switch (type) {
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
310 case GL::MainArray:
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
311 case GL::EdgeArray:
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
312 case GL::CondEdgeArray:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
313 v.color = triangle.rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
314 break;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
315
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
316 case GL::PickArray:
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
317 case GL::EdgePickArray:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
318 v.color = triangle.pickrgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
319
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
320 case GL::BFCArray:
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
321 break; // handled separately
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
322
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
323 case GL::NumArrays:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
324 assert (false);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
325 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
326
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
327 verts << v;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
328 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
329
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
330 if (type == GL::BFCArray) {
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
331 int32 rgb = getObjectColor (triangle.obj, BFCFront).rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
332 for (Vertex v : verts) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
333 v.color = rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
334 va->write (v);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
335 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
336
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
337 rgb = getObjectColor (triangle.obj, BFCBack).rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
338 for (Vertex v : c_rev<Vertex> (verts)) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
339 v.color = rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
340 va->write (v);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
341 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
342 } else {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
343 for (Vertex v : verts)
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
344 va->write (v);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
345 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
346
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
347 return va;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
352 uint32 VertexCompiler::getColorRGB (QColor& color) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
353 return
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
354 (color.red() & 0xFF) << 0x00 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
355 (color.green() & 0xFF) << 0x08 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
356 (color.blue() & 0xFF) << 0x10 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
357 (color.alpha() & 0xFF) << 0x18;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
358 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
359
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
360 // =============================================================================
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
361 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
362 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
363 QColor qcol;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 if (!obj->isColored())
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 return QColor();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
368 if (colotype == PickColor) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 // 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
370 // 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
371 // 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
372 // to the subfile itself.
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 long i = obj->topLevelParent()->id();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 // 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
376 // 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
377 // 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
378 int r = (i / (256 * 256)) % 256,
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 g = (i / 256) % 256,
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 b = i % 256;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
382 return QColor (r, g, b);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 if ((colotype == BFCFront || colotype == BFCBack) &&
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 obj->getType() != LDObject::Line &&
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
387 obj->getType() != LDObject::CndLine) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 if (colotype == BFCFront)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 qcol = QColor (40, 192, 0);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 else
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 qcol = QColor (224, 0, 0);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 } else {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 if (obj->color() == maincolor)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 qcol = GL::getMainColor();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 else {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 LDColor* col = getColor (obj->color());
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 if (col)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 qcol = col->faceColor;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 if (obj->color() == edgecolor) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 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
405 LDColor* col;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
407 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
408 qcol = col->edgeColor;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
410
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411 if (qcol.isValid() == false) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 // 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
413 // not appear pitch-black.
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
414 if (obj->color() != edgecolor)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 qcol = GL::getMainColor();
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
416 else
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
417 qcol = Qt::black;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
419 // Warn about the unknown color, but only once.
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
420 for (short i : g_warnedColors)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
421 if (obj->color() == i)
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
422 return qcol;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
423
489
0b32138fedcc Further work on VAO rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 488
diff changeset
424 log ("%1: Unknown color %2!\n", __func__, obj->color());
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
425 g_warnedColors << obj->color();
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
426 return qcol;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
428 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
429
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
430 if (obj->topLevelParent()->selected()) {
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
431 // Brighten it up if selected.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
432 const int add = 51;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
434 qcol.setRed (min (qcol.red() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
435 qcol.setGreen (min (qcol.green() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
436 qcol.setBlue (min (qcol.blue() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
438
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
439 return qcol;
490
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
440 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
441
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
442 // =============================================================================
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
443 // -----------------------------------------------------------------------------
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
444 void VertexCompiler::needMerge() {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
445 // Set all of m_changed to true
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
446 memset (m_changed, 0xFF, sizeof m_changed);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
447 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
448
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
449 // =============================================================================
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
450 // -----------------------------------------------------------------------------
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
451 void VertexCompiler::initObject (LDObject* obj) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
452 if (m_objArrays.find (obj) == m_objArrays.end())
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
453 m_objArrays[obj] = new Array[GL::NumArrays];
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
454 }
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
455
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
456 // =============================================================================
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
457 // -----------------------------------------------------------------------------
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
458 void VertexCompiler::stageForCompilation (LDObject* obj) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
459 m_staged << obj;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 489
diff changeset
460 m_staged.makeUnique();
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
461 }

mercurial