# HG changeset patch # User Santeri Piippo # Date 1515677430 -7200 # Node ID 7eb8b59577d0aadd14f280662526835b001477f8 # Parent ce0c9f2e6b9cc0a2e32da1d7b9cae1faeb24be70 renderer rework diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/documentmanager.cpp --- a/src/documentmanager.cpp Thu Jan 11 15:09:44 2018 +0200 +++ b/src/documentmanager.cpp Thu Jan 11 15:30:30 2018 +0200 @@ -152,6 +152,8 @@ dl.checkIfFinished(); file->reloadAllSubfiles(); } + + emit documentLoaded(file); } LDDocument* DocumentManager::findDocumentByName(QString name) diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/documentmanager.h --- a/src/documentmanager.h Thu Jan 11 15:09:44 2018 +0200 +++ b/src/documentmanager.h Thu Jan 11 15:30:30 2018 +0200 @@ -46,6 +46,9 @@ void openMainModel(QString path); bool preInline(LDDocument* doc, LDObjectList&, bool deep, bool renderinline); +signals: + void documentLoaded(LDDocument* document); + private: Documents m_documents; bool m_loadingMainFile; @@ -56,4 +59,4 @@ QString Basename(QString path); QString Dirname(QString path); -static const QStringList g_specialSubdirectories({ "s", "48", "8" }); \ No newline at end of file +static const QStringList g_specialSubdirectories({ "s", "48", "8" }); diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/glCompiler.cpp --- a/src/glCompiler.cpp Thu Jan 11 15:09:44 2018 +0200 +++ b/src/glCompiler.cpp Thu Jan 11 15:30:30 2018 +0200 @@ -107,14 +107,14 @@ QColor blend(QColor baseColor, QColor blendColor, double intensity) { - double red = baseColor.redF(); - red += blendColor.redF() * intensity; + double red = baseColor.red(); + red += blendColor.red() * intensity; red /= (intensity + 1.0); - double green = baseColor.greenF(); - green += blendColor.greenF() * intensity; + double green = baseColor.green(); + green += blendColor.green() * intensity; green /= (intensity + 1.0); - double blue = baseColor.blueF(); - blue += blendColor.blueF() * intensity; + double blue = baseColor.blue(); + blue += blendColor.blue() * intensity; blue /= (intensity + 1.0); return {int(round(red)), int(round(green)), int(round(blue))}; } @@ -221,13 +221,10 @@ } -void GLCompiler::compileDocument(LDDocument* document) +void GLCompiler::compileDocument() { - if (document) - { - for (LDObject* obj : document->objects()) - compileObject(obj); - } + for (LDObject* object : this->document->objects()) + compileObject(object); } @@ -245,9 +242,8 @@ // Compile anything that still awaits it compileStaged(); - if (not vboChanged[vbonum]) + if (vboChanged[vbonum]) { - print("Merging %1", vbonum); QVector vbodata; for (auto it = objectInfo.begin(); it != objectInfo.end();) @@ -295,7 +291,6 @@ return; ObjectVBOInfo info; - info.isChanged = true; dropObjectInfo(obj); switch(obj->type()) diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/glCompiler.h --- a/src/glCompiler.h Thu Jan 11 15:09:44 2018 +0200 +++ b/src/glCompiler.h Thu Jan 11 15:30:30 2018 +0200 @@ -26,7 +26,7 @@ public: GLCompiler(LDDocument* document, class GLRenderer* renderer); ~GLCompiler(); - void compileDocument(LDDocument* document); + void compileDocument(); void dropObjectInfo(LDObject* obj); QColor getColorForPolygon(LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const; QColor indexColorForID(int id) const; @@ -44,7 +44,7 @@ struct ObjectVBOInfo { QVector data[NumVbos]; - bool isChanged = false; + bool isChanged = true; }; void compileStaged(); diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/glRenderer.cpp --- a/src/glRenderer.cpp Thu Jan 11 15:09:44 2018 +0200 +++ b/src/glRenderer.cpp Thu Jan 11 15:30:30 2018 +0200 @@ -113,6 +113,7 @@ } calcCameraIcons(); + m_compiler.compileDocument(); } // ============================================================================= @@ -354,7 +355,7 @@ { if (m_initialized) { - compiler()->compileDocument(currentDocument()); + compiler()->compileDocument(); refresh(); } } diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/ldDocument.cpp --- a/src/ldDocument.cpp Thu Jan 11 15:09:44 2018 +0200 +++ b/src/ldDocument.cpp Thu Jan 11 15:30:30 2018 +0200 @@ -131,10 +131,6 @@ if (m_isCache) { m_isCache = false; - - // Cache files are not compiled by the GL renderer. Now that this file is open for editing, it needs to be - // compiled. - m_window->currentRenderer()->compiler()->compileDocument(this); m_window->updateDocumentList(); } } diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/mainwindow.cpp --- a/src/mainwindow.cpp Thu Jan 11 15:09:44 2018 +0200 +++ b/src/mainwindow.cpp Thu Jan 11 15:30:30 2018 +0200 @@ -87,6 +87,10 @@ connect(ui.objectList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(objectListDoubleClicked(QListWidgetItem*))); connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(tabSelected())); connect(m_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); + connect( + m_documents, SIGNAL(documentLoaded(LDDocument*)), + this, SLOT(documentLoaded(LDDocument*)) + ); if (ActivePrimitiveScanner()) connect(ActivePrimitiveScanner(), SIGNAL(workDone()), this, SLOT(updatePrimitives())); @@ -1222,16 +1226,13 @@ connect(document->history(), SIGNAL(stepAdded()), this, SLOT(updateActions())); connect(document, SIGNAL(closed()), this, SLOT(documentClosed())); - GLRenderer* renderer = new GLRenderer {document, this}; - m_renderers[document] = renderer; - ui.rendererStack->addWidget(renderer); - if (not cache) { changeDocument(document); document->openForEditing(); } + documentLoaded(document); return document; } @@ -1262,7 +1263,6 @@ buildObjectList(); updateTitle(); ui.rendererStack->setCurrentWidget(m_renderers[document]); - print("Changed document to %1", document->getDisplayName()); } } @@ -1290,8 +1290,15 @@ return m_currentDocument->getSelection(); } -// --------------------------------------------------------------------------------------------------------------------- -// + +void MainWindow::documentLoaded(LDDocument* document) +{ + GLRenderer* renderer = new GLRenderer {document, this}; + m_renderers[document] = renderer; + ui.rendererStack->addWidget(renderer); +} + + void MainWindow::documentClosed() { LDDocument* document = qobject_cast(sender()); diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/mainwindow.h --- a/src/mainwindow.h Thu Jan 11 15:09:44 2018 +0200 +++ b/src/mainwindow.h Thu Jan 11 15:30:30 2018 +0200 @@ -158,6 +158,7 @@ void recentFileClicked(); void quickColorClicked(); void objectListDoubleClicked(QListWidgetItem* listitem); + void documentLoaded(LDDocument* document); void documentClosed(); }; diff -r ce0c9f2e6b9c -r 7eb8b59577d0 src/mainwindow.ui --- a/src/mainwindow.ui Thu Jan 11 15:09:44 2018 +0200 +++ b/src/mainwindow.ui Thu Jan 11 15:30:30 2018 +0200 @@ -39,15 +39,12 @@ - - 1 - 0 0 - 465 + 310 371 @@ -179,7 +176,7 @@ 0 0 - 465 + 310 371