Tue, 09 Sep 2014 01:16:24 +0300
- backed out work done on bfc (re-committing later)
src/basics.h | file | annotate | diff | comparison | revisions | |
src/glCompiler.cc | file | annotate | diff | comparison | revisions | |
src/glShared.h | file | annotate | diff | comparison | revisions | |
src/ldDocument.cc | file | annotate | diff | comparison | revisions | |
src/ldDocument.h | file | annotate | diff | comparison | revisions | |
src/ldObject.cc | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Tue Sep 09 01:15:24 2014 +0300 +++ b/src/basics.h Tue Sep 09 01:16:24 2014 +0300 @@ -56,21 +56,6 @@ Z }; -enum class Winding -{ - CW, - CCW, - None -}; - -inline void invertWinding (Winding& winding) -{ - if (winding == Winding::CW) - winding = Winding::CCW; - elif (winding == Winding::CCW) - winding = Winding::CW; -} - // // Derivative of QVector3D: this class is used for the vertices. //
--- a/src/glCompiler.cc Tue Sep 09 01:15:24 2014 +0300 +++ b/src/glCompiler.cc Tue Sep 09 01:16:24 2014 +0300 @@ -49,6 +49,10 @@ EXTERN_CFGENTRY (Bool, BlackEdges) EXTERN_CFGENTRY (String, BackgroundColor) +static QList<int> g_warnedColors; +static const QColor g_BFCFrontColor (64, 192, 80); +static const QColor g_BFCBackColor (208, 64, 64); + // static QMap<LDObjectPtr, String> g_objectOrigins; // ============================================================================= @@ -131,12 +135,7 @@ QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObjectPtr topobj, EVBOComplement complement) const { - static const QColor bfcFrontColor (64, 192, 80); - static const QColor bfcBackColor (208, 64, 64); - static const QColor bfcDisabledColor (64, 64, 208); - static QList<int> warnedcolors; QColor qcol; - print ("Winding of %1 is %2", poly.id, (int) poly.winding); switch (complement) { @@ -145,11 +144,11 @@ return QColor(); case VBOCM_BFCFrontColors: - qcol = (poly.winding != Winding::None) ? bfcFrontColor : bfcDisabledColor; + qcol = g_BFCFrontColor; break; case VBOCM_BFCBackColors: - qcol = (poly.winding != Winding::None) ? bfcBackColor : bfcDisabledColor; + qcol = g_BFCBackColor; break; case VBOCM_PickColors: @@ -185,13 +184,16 @@ { // The color was unknown. Use main color to make the polygon at least // not appear pitch-black. - qcol = (poly.num != 2 and poly.num != 5) ? GLRenderer::getMainColor() : Qt::black; + if (poly.num != 2 and poly.num != 5) + qcol = GLRenderer::getMainColor(); + else + qcol = Qt::black; // Warn about the unknown color, but only once. - if (not warnedcolors.contains (poly.color)) + if (not g_warnedColors.contains (poly.color)) { print ("Unknown color %1!\n", poly.color); - warnedcolors << poly.color; + g_warnedColors << poly.color; } return qcol; @@ -390,9 +392,7 @@ QVector<GLfloat>& vbodata = objinfo->data[vbonum]; const QColor color = getColorForPolygon (poly, topobj, complement); - bool inverted = (poly.winding != Winding::CCW); - - auto func = [&](int vert) + for (int vert = 0; vert < numverts; ++vert) { if (complement == VBOCM_Surfaces) { @@ -408,17 +408,6 @@ << ((GLfloat) color.blue()) / 255.0f << ((GLfloat) color.alpha()) / 255.0f; } - }; - - if (not inverted) - { - for (int vert = 0; vert < numverts; ++vert) - func (vert); - } - else - { - for (int vert = numverts - 1; vert >= 0; --vert) - func (vert); } } }
--- a/src/glShared.h Tue Sep 09 01:15:24 2014 +0300 +++ b/src/glShared.h Tue Sep 09 01:16:24 2014 +0300 @@ -32,7 +32,6 @@ Vertex vertices[4]; int id; int color; - Winding winding; inline int numVertices() const {
--- a/src/ldDocument.cc Tue Sep 09 01:15:24 2014 +0300 +++ b/src/ldDocument.cc Tue Sep 09 01:16:24 2014 +0300 @@ -209,12 +209,6 @@ } } -LDObjectList const& LDDocument::objects() -{ - sweepBFC(); - return m_objects; -} - // ============================================================================= // QList<LDDocumentPtr> const& LDDocument::explicitDocuments() @@ -1153,7 +1147,6 @@ } // ============================================================================= -// Adds an object at the end of the file. // int LDDocument::addObject (LDObjectPtr obj) { @@ -1162,7 +1155,6 @@ addKnownVertices (obj); obj->setDocument (self()); g_win->R()->compileObject (obj); - requireBFCSweep(); return getObjectCount() - 1; } @@ -1175,8 +1167,6 @@ if (obj != null) addObject (obj); } - - requireBFCSweep(); } // ============================================================================= @@ -1187,8 +1177,8 @@ m_objects.insert (pos, obj); obj->setDocument (self()); g_win->R()->compileObject (obj); - requireBFCSweep(); + #ifdef DEBUG if (not isImplicit()) dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); @@ -1224,11 +1214,6 @@ m_objectVertices.remove (obj); } - // We only need a sweep if we got rid of a BFC object, no processing is required if a polygon - // just got removed. - if (obj->type() == OBJ_BFC) - requireBFCSweep(); - m_objects.removeAt (idx); obj->setDocument (LDDocumentPtr()); } @@ -1272,12 +1257,11 @@ // ============================================================================= // -LDObjectPtr LDDocument::getObject (int pos) +LDObjectPtr LDDocument::getObject (int pos) const { if (m_objects.size() <= pos) return LDObjectPtr(); - sweepBFC(); return m_objects[pos]; } @@ -1285,7 +1269,7 @@ // int LDDocument::getObjectCount() const { - return m_objects.size(); + return objects().size(); } // ============================================================================= @@ -1523,9 +1507,8 @@ // ============================================================================= // -const LDObjectList& LDDocument::getSelection() +const LDObjectList& LDDocument::getSelection() const { - sweepBFC(); return m_sel; } @@ -1539,7 +1522,6 @@ m_objects[b] = one; m_objects[a] = other; addToHistory (new SwapHistory (one->id(), other->id())); - requireBFCSweep(); } // ============================================================================= @@ -1572,72 +1554,3 @@ { m_needVertexMerge = true; } - -// -// Sweeps through the file and adjusts the block windings of all objects. -// -void LDDocument::sweepBFC() -{ - if (not m_needBFCSweep) - return; - - QTime t0 (QTime::currentTime()); - Winding winding (Winding::None); - Winding preclip (winding); - LDBFCPtr bfc; - bool invertnext (false); - - for (LDObjectPtr obj : m_objects) - { - if (obj->type() == OBJ_BFC) - { - switch (obj.staticCast<LDBFC>()->statement()) - { - case BFCStatement::CCW: - case BFCStatement::CertifyCCW: - winding = Winding::CCW; - break; - - case BFCStatement::CW: - case BFCStatement::CertifyCW: - winding = Winding::CW; - - case BFCStatement::NoCertify: - winding = Winding::None; - break; - - case BFCStatement::NoClip: - preclip = winding; - winding = Winding::None; - break; - - case BFCStatement::InvertNext: - invertnext = true; - break; - - case BFCStatement::Clip: - winding = preclip; - break; - - default: - break; - } - } - else - { - Winding objwinding (winding); - - if (invertnext) - { - invertWinding (objwinding); - invertnext = false; - } - - print ("%1: BFC sweep: set winding of %2 to %3", getDisplayName(), obj->id(), int (objwinding)); - obj->setBlockWinding (objwinding); - } - } - - print ("%1: BFC sweep done in %2ms", getDisplayName(), t0.msecsTo (QTime::currentTime())); - m_needBFCSweep = false; -}
--- a/src/ldDocument.h Tue Sep 09 01:15:24 2014 +0300 +++ b/src/ldDocument.h Tue Sep 09 01:16:24 2014 +0300 @@ -64,6 +64,7 @@ { public: PROPERTY (public, QString, name, setName, STOCK_WRITE) + PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE) PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE) PROPERTY (private, History*, history, setHistory, STOCK_WRITE) PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE) @@ -89,13 +90,13 @@ void clearSelection(); void forgetObject (LDObjectPtr obj); // Deletes the given object from the object chain. QString getDisplayName(); - const LDObjectList& getSelection(); + const LDObjectList& getSelection() const; bool hasUnsavedChanges() const; // Does this document have unsaved changes? void initializeCachedData(); LDObjectList inlineContents (bool deep, bool renderinline); void insertObj (int pos, LDObjectPtr obj); int getObjectCount() const; - LDObjectPtr getObject (int pos); + LDObjectPtr getObject (int pos) const; bool save (QString path = "", int64* sizeptr = null); // Saves this file to disk. void swapObjects (LDObjectPtr one, LDObjectPtr other); bool isSafeToClose(); // Perform safety checks. Do this before closing any files! @@ -108,8 +109,6 @@ void redoVertices(); void needVertexMerge(); void reloadAllSubfiles(); - void sweepBFC(); - LDObjectList const& objects(); inline LDDocument& operator<< (LDObjectPtr obj) { @@ -147,11 +146,6 @@ setImplicit (true); } - inline void requireBFCSweep() - { - m_needBFCSweep = true; - } - static LDDocumentPtr current(); static void setCurrent (LDDocumentPtr f); static void closeInitialFile(); @@ -176,16 +170,12 @@ friend class GLRenderer; private: - LDObjectList m_objects; LDObjectList m_sel; LDGLData* m_gldata; // If set to true, next polygon inline of this document discards the // stored polygon data and re-builds it. bool m_needsReCache; - - // If set to true, next object reference request causes BFC sweep. - bool m_needBFCSweep; }; inline LDDocumentPtr CurrentDocument()
--- a/src/ldObject.cc Tue Sep 09 01:15:24 2014 +0300 +++ b/src/ldObject.cc Tue Sep 09 01:16:24 2014 +0300 @@ -419,7 +419,6 @@ data->id = id(); data->num = num; data->color = color().index(); - data->winding = blockWinding(); for (int i = 0; i < data->numVertices(); ++i) data->vertices[i] = vertex (i); @@ -431,29 +430,14 @@ // QList<LDPolygon> LDSubfile::inlinePolygons() { - bool isInverted (false); - LDBFCPtr bfc (previous().dynamicCast<LDBFC>()); - - if ((bfc != null and bfc->statement() == BFCStatement::InvertNext) - or transform().getDeterminant() < 0) - { - isInverted = true; - } - - print ("inlining polygons of subfile-ref %1: inverted: %2", fileInfo()->name(), isInverted ? "true" : "false"); - QList<LDPolygon> data = fileInfo()->inlinePolygons(); for (LDPolygon& entry : data) { for (int i = 0; i < entry.numVertices(); ++i) entry.vertices[i].transform (transform(), position()); - - if (isInverted) - invertWinding (entry.winding); } - print ("Using winding: %1\n", (data[0].winding == Winding::CCW) ? "CCW" : (data[0].winding == Winding::CW) ? "CW" : "None"); return data; }
--- a/src/ldObject.h Tue Sep 09 01:15:24 2014 +0300 +++ b/src/ldObject.h Tue Sep 09 01:16:24 2014 +0300 @@ -101,11 +101,6 @@ PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) PROPERTY (private, LDObjectWeakPtr, self, setSelf, STOCK_WRITE) - // What winding the object is supposed to be wound in, depending on the BFC statements - // This is CW if the part is CW-certified at this object, and vice versa. Can also be - // Winding::None for NOCERTIFY parts. - PROPERTY (public, Winding, blockWinding, setBlockWinding, STOCK_WRITE) - public: LDObject (LDObjectPtr* selfptr);