src/gldata.cpp

Sat, 07 Sep 2013 14:21:33 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 07 Sep 2013 14:21:33 +0300
changeset 488
0ea49207a4ec
parent 487
a350c4b25133
child 489
0b32138fedcc
permissions
-rw-r--r--

VAO rendering works now! woo!

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
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
8 cfg (Bool, gl_blackedges, false);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
9 static List<short> g_warnedColors;
441
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 // -----------------------------------------------------------------------------
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 VertexCompiler::Array::Array() :
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 m_data (null)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 clear();
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 // -----------------------------------------------------------------------------
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 VertexCompiler::Array::~Array() {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 delete[] m_data;
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 // -----------------------------------------------------------------------------
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 void VertexCompiler::Array::clear() {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 delete[] m_data;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
30 m_data = new Vertex[64];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 m_size = 64;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 m_ptr = &m_data[0];
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
37 void VertexCompiler::Array::resizeToFit (Size newSize) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 if (allocatedSize() >= newSize)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 return;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 int32 cachedWriteSize = writtenSize();
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 // 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
44 newSize += 256;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
46 const Size oldSize = allocatedSize();
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 // We need to back up the data first
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
49 Vertex* copy = new Vertex[oldSize];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 memcpy (copy, m_data, oldSize);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 // Re-create the buffer
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 delete[] m_data;
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
54 m_data = new Vertex[newSize];
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 m_size = newSize;
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
56 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
57
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 // Copy the data back
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 memcpy (m_data, copy, oldSize);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 delete[] copy;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
65 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
66 return m_data;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
71 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
72 return m_size;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
77 VertexCompiler::Array::Size VertexCompiler::Array::writtenSize() const {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
78 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
79 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
83 void VertexCompiler::Array::write (const Vertex& f) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
84 // 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
85 resizeToFit (writtenSize() + sizeof 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 // Write the float in
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 *m_ptr++ = 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
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 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
93 void VertexCompiler::Array::merge (Array* other) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 // Ensure there's room for both buffers
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 resizeToFit (writtenSize() + other->writtenSize());
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 memcpy (m_ptr, other->data(), other->writtenSize());
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
98 m_ptr += other->writtenSize() / sizeof (Vertex);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
103 VertexCompiler::VertexCompiler() :
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
104 m_file (null)
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
105 {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
106 memset (m_changed, 0xFF, sizeof m_changed);
441
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
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
109 VertexCompiler::~VertexCompiler() {}
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
110
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 // =============================================================================
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
112 // 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
113 // 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
114 // 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
115 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
116 void VertexCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj) {
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
117 const QColor pickColor = getObjectColor (trueobj, PickColor);
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
118 List<CompiledTriangle>& data = m_objArrays[trueobj];
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
119 LDObject::Type type = drawobj->getType();
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
120 List<LDObject*> objs;
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
121
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
122 assert (type != LDObject::Subfile);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
124 if (type == LDObject::Quad) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
125 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
126 objs << t;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
127 } else
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
128 objs << drawobj;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
130 for (LDObject* obj : objs) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
131 const LDObject::Type objtype = obj->getType();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
132 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
133 const int verts = isline ? 2 : obj->vertices();
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
134 QColor normalColor = getObjectColor (obj, Normal);
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
135
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
136 assert (isline || objtype == LDObject::Triangle);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
138 CompiledTriangle a;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
139 a.rgb = normalColor.rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
140 a.pickrgb = pickColor.rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
141 a.numVerts = verts;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
142 a.obj = trueobj;
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
143 a.isCondLine = (objtype == LDObject::CndLine);
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
144
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
145 for (int i = 0; i < verts; ++i) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
146 a.verts[i] = obj->getVertex (i);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
147 a.verts[i].y() = -a.verts[i].y();
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
148 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
149 }
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 data << a;
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
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 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
157 void VertexCompiler::compileObject (LDObject* obj, LDObject* topobj) {
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
158 print ("compile %1 (%2, %3)\n", obj->id(), obj->typeName(), topobj->id());
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
159 List<LDObject*> objs;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
160
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 switch (obj->getType()) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 case LDObject::Triangle:
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
163 case LDObject::Line:
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
164 case LDObject::CndLine:
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
165 compilePolygon (obj, topobj);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 case LDObject::Quad:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
169 for (LDTriangle* triangle : static_cast<LDQuad*> (obj)->splitToTriangles())
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
170 compilePolygon (triangle, topobj);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
173 case LDObject::Subfile:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
174 objs = static_cast<LDSubfile*> (obj)->inlineContents (LDSubfile::RendererInline | LDSubfile::DeepCacheInline);
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
175
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
176 for (LDObject* obj : objs) {
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
177 compileObject (obj, topobj);
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
178 delete obj;
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
179 }
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 default:
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 break;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 }
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
185
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
186 print ("-> %1\n", m_objArrays[obj].size());
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
187
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
188 // Set all of m_changed to true
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
189 memset (m_changed, 0xFF, sizeof m_changed);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 }
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 // -----------------------------------------------------------------------------
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 void VertexCompiler::compileFile() {
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
195 for (LDObject* obj : m_file->objects())
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
196 compileObject (obj, obj);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 }
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 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
201 void VertexCompiler::forgetObject (LDObject* obj) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 m_objArrays.remove (obj);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
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 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
207 void VertexCompiler::setFile (LDFile* file) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 m_file = file;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
213 const VertexCompiler::Array* VertexCompiler::getMergedBuffer (ArrayType type) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 assert (type < NumArrays);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
216 if (m_changed[type]) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 m_changed[type] = false;
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
218 m_mainArrays[type].clear();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
219
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
220 for (LDObject* obj : m_file->objects()) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
221 if (!obj->isScemantic())
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
222 continue;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
223
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
224 const bool islinearray = (type == EdgeArray || type == EdgePickArray);
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 auto it = m_objArrays.find (obj);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
227 if (it != m_objArrays.end()) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
228 const List<CompiledTriangle>& data = *it;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
229
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
230 for (const CompiledTriangle& i : data) {
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
231 if (i.isCondLine) {
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
232 if (type != EdgePickArray && type != CondEdgeArray)
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
233 continue;
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
234 } else {
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
235 if ((i.numVerts == 2) ^ islinearray)
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
236 continue;
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
237
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
238 if (type == CondEdgeArray)
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
239 continue;
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
240 }
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
241
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
242 Array* verts = postprocess (i, type);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
243 m_mainArrays[type].merge (verts);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
244 delete verts;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
245 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
246 }
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 }
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
248
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
249 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
250 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
252 return &m_mainArrays[type];
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
253 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
254
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
255 // =============================================================================
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
256 // 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
257 // -----------------------------------------------------------------------------
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
258 VertexCompiler::Array* VertexCompiler::postprocess (const CompiledTriangle& triangle, ArrayType type) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
259 Array* va = new Array;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
260 List<Vertex> verts;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
261
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
262 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
263 alias v0 = triangle.verts[i];
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
264 Vertex v;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
265 v.x = v0.x();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
266 v.y = v0.y();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
267 v.z = v0.z();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
268
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
269 switch (type) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
270 case MainArray:
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
271 case EdgeArray:
488
0ea49207a4ec VAO rendering works now! woo!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 487
diff changeset
272 case CondEdgeArray:
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
273 v.color = triangle.rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
274 break;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
275
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
276 case PickArray:
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
277 case EdgePickArray:
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
278 v.color = triangle.pickrgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
279
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
280 case BFCArray:
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
281 break;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
282
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
283 case NumArrays:
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
284 assert (false);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
285 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
286
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
287 verts << v;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
288 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
289
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
290 if (type == BFCArray) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
291 int32 rgb = getObjectColor (triangle.obj, BFCFront).rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
292 for (Vertex v : verts) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
293 v.color = rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
294 va->write (v);
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
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
297 rgb = getObjectColor (triangle.obj, BFCBack).rgb();
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
298 for (Vertex v : c_rev<Vertex> (verts)) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
299 v.color = rgb;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
300 va->write (v);
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 } else {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
303 for (Vertex v : verts)
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
304 va->write (v);
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
305 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
306
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
307 return va;
441
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 // =============================================================================
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
311 // -----------------------------------------------------------------------------
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
312 uint32 VertexCompiler::getColorRGB (QColor& color) {
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
313 return
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
314 (color.red() & 0xFF) << 0x00 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
315 (color.green() & 0xFF) << 0x08 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
316 (color.blue() & 0xFF) << 0x10 |
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
317 (color.alpha() & 0xFF) << 0x18;
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
318 }
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
319
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
320 // =============================================================================
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
321 // -----------------------------------------------------------------------------
443
Santeri Piippo <crimsondusk64@gmail.com>
parents: 442
diff changeset
322 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
323 QColor qcol;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 if (!obj->isColored())
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 return QColor();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
328 if (colotype == PickColor) {
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 // 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
330 // 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
331 // 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
332 // to the subfile itself.
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 long i = obj->topLevelParent()->id();
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 // 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
336 // 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
337 // 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
338 int r = (i / (256 * 256)) % 256,
441
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 g = (i / 256) % 256,
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 b = i % 256;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341
442
4852e815df29 Picking now works with the VAO setup
Santeri Piippo <crimsondusk64@gmail.com>
parents: 441
diff changeset
342 return QColor (r, g, b);
441
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
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 if ((colotype == BFCFront || colotype == BFCBack) &&
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 obj->getType() != LDObject::Line &&
487
a350c4b25133 Merge branch 'master' into gl, reworked stuff
Santeri Piippo <crimsondusk64@gmail.com>
parents: 443
diff changeset
347 obj->getType() != LDObject::CndLine) {
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 if (colotype == BFCFront)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 qcol = QColor (40, 192, 0);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 else
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 qcol = QColor (224, 0, 0);
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 } else {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 if (obj->color() == maincolor)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 qcol = GL::getMainColor();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 else {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 LDColor* col = getColor (obj->color());
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 if (col)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 qcol = col->faceColor;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 if (obj->color() == edgecolor) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364 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
365 LDColor* col;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
367 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
368 qcol = col->edgeColor;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 if (qcol.isValid() == false) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 // 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
373 // not appear pitch-black.
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 if (obj->color() != edgecolor)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 qcol = GL::getMainColor();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 // 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
378 for (short i : g_warnedColors)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 if (obj->color() == i)
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 return Qt::black;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 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
383 g_warnedColors << obj->color();
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 return Qt::black;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 if (obj->topLevelParent()->selected()) {
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 // Brighten it up for the select list.
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 const uchar add = 51;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 qcol.setRed (min (qcol.red() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393 qcol.setGreen (min (qcol.green() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 qcol.setBlue (min (qcol.blue() + add, 255));
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 }
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 return qcol;
a958f6925088 BIG COMMIT -- Moving from display lists to VAOs.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 }

mercurial