75 // ============================================================================= |
75 // ============================================================================= |
76 // |
76 // |
77 GLCompiler::GLCompiler() |
77 GLCompiler::GLCompiler() |
78 { |
78 { |
79 needMerge(); |
79 needMerge(); |
80 memset (m_VBOSizes, 0, sizeof m_VBOSizes); |
80 memset (m_vboSizes, 0, sizeof m_vboSizes); |
81 } |
81 } |
82 |
82 |
83 // ============================================================================= |
83 // ============================================================================= |
84 // |
84 // |
85 void GLCompiler::initialize() |
85 void GLCompiler::initialize() |
86 { |
86 { |
87 glGenBuffers (g_numVBOs, &mVBOs[0]); |
87 glGenBuffers (g_numVBOs, &m_vbo[0]); |
88 checkGLError(); |
88 checkGLError(); |
89 } |
89 } |
90 |
90 |
91 // ============================================================================= |
91 // ============================================================================= |
92 // |
92 // |
93 GLCompiler::~GLCompiler() |
93 GLCompiler::~GLCompiler() |
94 { |
94 { |
95 glDeleteBuffers (g_numVBOs, &mVBOs[0]); |
95 glDeleteBuffers (g_numVBOs, &m_vbo[0]); |
96 checkGLError(); |
96 checkGLError(); |
97 } |
97 } |
98 |
98 |
99 // ============================================================================= |
99 // ============================================================================= |
100 // |
100 // |
101 uint32 GLCompiler::getColorRGB (const QColor& color) |
101 uint32 GLCompiler::colorToRGB (const QColor& color) |
102 { |
102 { |
103 return |
103 return |
104 (color.red() & 0xFF) << 0x00 | |
104 (color.red() & 0xFF) << 0x00 | |
105 (color.green() & 0xFF) << 0x08 | |
105 (color.green() & 0xFF) << 0x08 | |
106 (color.blue() & 0xFF) << 0x10 | |
106 (color.blue() & 0xFF) << 0x10 | |
107 (color.alpha() & 0xFF) << 0x18; |
107 (color.alpha() & 0xFF) << 0x18; |
108 } |
108 } |
109 |
109 |
110 // ============================================================================= |
110 // ============================================================================= |
111 // |
111 // |
112 QColor GLCompiler::getIndexColor (int id) const |
112 QColor GLCompiler::indexColorForID (int id) const |
113 { |
113 { |
114 // Calculate a color based from this index. This method caters for |
114 // Calculate a color based from this index. This method caters for |
115 // 16777216 objects. I don't think that will be exceeded anytime soon. :) |
115 // 16777216 objects. I don't think that will be exceeded anytime soon. :) |
116 int r = (id / 0x10000) % 0x100, |
116 int r = (id / 0x10000) % 0x100, |
117 g = (id / 0x100) % 0x100, |
117 g = (id / 0x100) % 0x100, |
120 return QColor (r, g, b); |
120 return QColor (r, g, b); |
121 } |
121 } |
122 |
122 |
123 // ============================================================================= |
123 // ============================================================================= |
124 // |
124 // |
125 QColor GLCompiler::getPolygonColor (LDPolygon& poly, LDObject* topobj) const |
125 QColor GLCompiler::polygonColor (LDPolygon& poly, LDObject* topobj) const |
126 { |
126 { |
127 QColor qcol; |
127 QColor qcol; |
128 |
128 |
129 if (poly.color == maincolor) |
129 if (poly.color == maincolor) |
130 qcol = GLRenderer::getMainColor(); |
130 qcol = GLRenderer::getMainColor(); |
205 |
205 |
206 // ============================================================================= |
206 // ============================================================================= |
207 // |
207 // |
208 void GLCompiler::compileStaged() |
208 void GLCompiler::compileStaged() |
209 { |
209 { |
210 removeDuplicates (mStaged); |
210 removeDuplicates (m_staged); |
211 |
211 |
212 for (LDObject* obj : mStaged) |
212 for (LDObject* obj : m_staged) |
213 compileObject (obj); |
213 compileObject (obj); |
214 |
214 |
215 mStaged.clear(); |
215 m_staged.clear(); |
216 } |
216 } |
217 |
217 |
218 // ============================================================================= |
218 // ============================================================================= |
219 // |
219 // |
220 void GLCompiler::prepareVBO (int vbonum) |
220 void GLCompiler::prepareVBO (int vbonum) |
225 if (m_vboChanged[vbonum] == false) |
225 if (m_vboChanged[vbonum] == false) |
226 return; |
226 return; |
227 |
227 |
228 QVector<GLfloat> vbodata; |
228 QVector<GLfloat> vbodata; |
229 |
229 |
230 for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it) |
230 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end(); ++it) |
231 { |
231 { |
232 if (it.key()->document() == getCurrentDocument()) |
232 if (it.key()->document() == getCurrentDocument()) |
233 vbodata += it->data[vbonum]; |
233 vbodata += it->data[vbonum]; |
234 } |
234 } |
235 |
235 |
236 glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]); |
236 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); |
237 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
237 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
238 glBindBuffer (GL_ARRAY_BUFFER, 0); |
238 glBindBuffer (GL_ARRAY_BUFFER, 0); |
239 checkGLError(); |
239 checkGLError(); |
240 m_vboChanged[vbonum] = false; |
240 m_vboChanged[vbonum] = false; |
241 m_VBOSizes[vbonum] = vbodata.size(); |
241 m_vboSizes[vbonum] = vbodata.size(); |
242 } |
242 } |
243 |
243 |
244 // ============================================================================= |
244 // ============================================================================= |
245 // |
245 // |
246 void GLCompiler::dropObject (LDObject* obj) |
246 void GLCompiler::dropObject (LDObject* obj) |
247 { |
247 { |
248 auto it = mObjectInfo.find (obj); |
248 auto it = m_objectInfo.find (obj); |
249 |
249 |
250 if (it != mObjectInfo.end()) |
250 if (it != m_objectInfo.end()) |
251 { |
251 { |
252 mObjectInfo.erase (it); |
252 m_objectInfo.erase (it); |
253 needMerge(); |
253 needMerge(); |
254 } |
254 } |
255 } |
255 } |
256 |
256 |
257 // ============================================================================= |
257 // ============================================================================= |
260 { |
260 { |
261 print ("compiling #%1 (%2, %3)\n", obj->id(), obj->typeName(), obj->origin()); |
261 print ("compiling #%1 (%2, %3)\n", obj->id(), obj->typeName(), obj->origin()); |
262 ObjectVBOInfo info; |
262 ObjectVBOInfo info; |
263 dropObject (obj); |
263 dropObject (obj); |
264 compileSubObject (obj, obj, &info); |
264 compileSubObject (obj, obj, &info); |
265 mObjectInfo[obj] = info; |
265 m_objectInfo[obj] = info; |
266 needMerge(); |
266 needMerge(); |
267 print ("#%1 compiled.\n", obj->id()); |
267 print ("#%1 compiled.\n", obj->id()); |
268 } |
268 } |
269 |
269 |
270 // ============================================================================= |
270 // ============================================================================= |
287 assert (false); |
287 assert (false); |
288 } |
288 } |
289 |
289 |
290 for (int complement = 0; complement < vboNumComplements; ++complement) |
290 for (int complement = 0; complement < vboNumComplements; ++complement) |
291 { |
291 { |
292 const int vbonum = getVBONumber (surface, (EVBOComplement) complement); |
292 const int vbonum = vboNumber (surface, (EVBOComplement) complement); |
293 QVector<GLfloat>& vbodata = objinfo->data[vbonum]; |
293 QVector<GLfloat>& vbodata = objinfo->data[vbonum]; |
294 const QColor normalColor = getPolygonColor (poly, topobj); |
294 const QColor normalColor = polygonColor (poly, topobj); |
295 const QColor pickColor = getIndexColor (topobj->id()); |
295 const QColor pickColor = indexColorForID (topobj->id()); |
296 |
296 |
297 for (int vert = 0; vert < numverts; ++vert) |
297 for (int vert = 0; vert < numverts; ++vert) |
298 { |
298 { |
299 switch ((EVBOComplement) complement) |
299 switch ((EVBOComplement) complement) |
300 { |
300 { |