# HG changeset patch # User Santeri Piippo # Date 1378552893 -10800 # Node ID 0ea49207a4ec33e4df998d8ea5b6325ec4603b5e # Parent a350c4b251339066fea736c87095d0af96f2d617 VAO rendering works now! woo! diff -r a350c4b25133 -r 0ea49207a4ec src/gldata.cpp --- a/src/gldata.cpp Sat Sep 07 13:23:09 2013 +0300 +++ b/src/gldata.cpp Sat Sep 07 14:21:33 2013 +0300 @@ -114,15 +114,13 @@ // the top level object's ID. This is crucial for picking to work. // ----------------------------------------------------------------------------- void VertexCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj) { + const QColor pickColor = getObjectColor (trueobj, PickColor); List& data = m_objArrays[trueobj]; + LDObject::Type type = drawobj->getType(); + List objs; - QColor normalColor = getObjectColor (trueobj, Normal), - pickColor = getObjectColor (trueobj, PickColor); - - LDObject::Type type = drawobj->getType(); assert (type != LDObject::Subfile); - List objs; if (type == LDObject::Quad) { for (LDTriangle* t : static_cast (drawobj)->splitToTriangles()) objs << t; @@ -133,16 +131,21 @@ const LDObject::Type objtype = obj->getType(); const bool isline = (objtype == LDObject::Line || objtype == LDObject::CndLine); const int verts = isline ? 2 : obj->vertices(); + QColor normalColor = getObjectColor (obj, Normal); + + assert (isline || objtype == LDObject::Triangle); CompiledTriangle a; a.rgb = normalColor.rgb(); a.pickrgb = pickColor.rgb(); a.numVerts = verts; a.obj = trueobj; + a.isCondLine = (objtype == LDObject::CndLine); for (int i = 0; i < verts; ++i) { a.verts[i] = obj->getVertex (i); a.verts[i].y() = -a.verts[i].y(); + a.verts[i].z() = -a.verts[i].z(); } data << a; @@ -152,11 +155,13 @@ // ============================================================================= // ----------------------------------------------------------------------------- void VertexCompiler::compileObject (LDObject* obj, LDObject* topobj) { - print ("compile %1 (%2)\n", obj->id(), topobj->id()); + print ("compile %1 (%2, %3)\n", obj->id(), obj->typeName(), topobj->id()); List objs; switch (obj->getType()) { case LDObject::Triangle: + case LDObject::Line: + case LDObject::CndLine: compilePolygon (obj, topobj); break; @@ -165,10 +170,6 @@ compilePolygon (triangle, topobj); break; - case LDObject::Line: - compilePolygon (obj, topobj); - break; - case LDObject::Subfile: objs = static_cast (obj)->inlineContents (LDSubfile::RendererInline | LDSubfile::DeepCacheInline); @@ -182,6 +183,8 @@ break; } + print ("-> %1\n", m_objArrays[obj].size()); + // Set all of m_changed to true memset (m_changed, 0xFF, sizeof m_changed); } @@ -214,25 +217,28 @@ m_changed[type] = false; m_mainArrays[type].clear(); - print ("merge array %1\n", (int) type); - for (LDObject* obj : m_file->objects()) { if (!obj->isScemantic()) continue; - const LDObject::Type objtype = obj->getType(); - const bool isline = (objtype == LDObject::Line || objtype == LDObject::CndLine); const bool islinearray = (type == EdgeArray || type == EdgePickArray); - - if ((isline && !islinearray) || (!isline && islinearray)) - continue; - auto it = m_objArrays.find (obj); if (it != m_objArrays.end()) { const List& data = *it; for (const CompiledTriangle& i : data) { + if (i.isCondLine) { + if (type != EdgePickArray && type != CondEdgeArray) + continue; + } else { + if ((i.numVerts == 2) ^ islinearray) + continue; + + if (type == CondEdgeArray) + continue; + } + Array* verts = postprocess (i, type); m_mainArrays[type].merge (verts); delete verts; @@ -240,7 +246,7 @@ } } - print ("merged array: %1 bytes\n", m_mainArrays[type].writtenSize()); + print ("merged array %1: %2 bytes\n", (int) type, m_mainArrays[type].writtenSize()); } return &m_mainArrays[type]; @@ -263,6 +269,7 @@ switch (type) { case MainArray: case EdgeArray: + case CondEdgeArray: v.color = triangle.rgb; break; diff -r a350c4b25133 -r 0ea49207a4ec src/gldata.h --- a/src/gldata.h Sat Sep 07 13:23:09 2013 +0300 +++ b/src/gldata.h Sat Sep 07 14:21:33 2013 +0300 @@ -48,6 +48,7 @@ enum ArrayType { MainArray, EdgeArray, + CondEdgeArray, BFCArray, PickArray, EdgePickArray, @@ -59,6 +60,7 @@ uint8 numVerts; QRgb rgb; QRgb pickrgb; + bool isCondLine; LDObject* obj; }; diff -r a350c4b25133 -r 0ea49207a4ec src/gldraw.cpp --- a/src/gldraw.cpp Sat Sep 07 13:23:09 2013 +0300 +++ b/src/gldraw.cpp Sat Sep 07 14:21:33 2013 +0300 @@ -196,6 +196,7 @@ setBackground(); glLineWidth (gl_linethickness); + glLineStipple (1, 0x6666); setAutoFillBackground (false); setMouseTracking (true); @@ -316,7 +317,9 @@ } else glDisable (GL_CULL_FACE); - const VertexCompiler::Array* array = g_vertexCompiler.getMergedBuffer ( + const VertexCompiler::Array* array; + + array = g_vertexCompiler.getMergedBuffer ( (m_picking) ? VertexCompiler::PickArray : (gl_colorbfc) ? VertexCompiler::BFCArray : VertexCompiler::MainArray); @@ -332,6 +335,18 @@ glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (VertexCompiler::Vertex), &array->data()[0].color); glDrawArrays (GL_LINES, 0, array->writtenSize() / sizeof (VertexCompiler::Vertex)); + // Draw conditional lines. Note that conditional lines are drawn into + // EdgePickArray in the picking scene, so when picking, don't do anything + // here. + if (!m_picking) { + array = g_vertexCompiler.getMergedBuffer (VertexCompiler::CondEdgeArray); + glEnable (GL_LINE_STIPPLE); + glVertexPointer (3, GL_FLOAT, sizeof (VertexCompiler::Vertex), &array->data()[0].x); + glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (VertexCompiler::Vertex), &array->data()[0].color); + glDrawArrays (GL_LINES, 0, array->writtenSize() / sizeof (VertexCompiler::Vertex)); + glDisable (GL_LINE_STIPPLE); + } + glPopMatrix(); glMatrixMode (GL_MODELVIEW); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);