- the GL compiler now supports multiple documents

Mon, 10 Mar 2014 00:53:39 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 10 Mar 2014 00:53:39 +0200
changeset 694
3868f52da6b9
parent 693
8432b37034a9
child 695
4ace632e247b

- the GL compiler now supports multiple documents

src/Document.cc file | annotate | diff | comparison | revisions
src/Document.h file | annotate | diff | comparison | revisions
src/GLCompiler.cc file | annotate | diff | comparison | revisions
src/GLCompiler.h file | annotate | diff | comparison | revisions
src/GLRenderer.cc file | annotate | diff | comparison | revisions
src/GLRenderer.h file | annotate | diff | comparison | revisions
src/LDObject.cc file | annotate | diff | comparison | revisions
src/actions/EditActions.cc file | annotate | diff | comparison | revisions
--- a/src/Document.cc	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/Document.cc	Mon Mar 10 00:53:39 2014 +0200
@@ -30,6 +30,7 @@
 #include "Dialogs.h"
 #include "GLRenderer.h"
 #include "misc/InvokationDeferer.h"
+#include "GLCompiler.h"
 
 cfg (String, io_ldpath, "");
 cfg (List, io_recentfiles, {});
@@ -1298,6 +1299,7 @@
 		g_win->updateTitle();
 		g_win->R()->setDocument (f);
 		g_win->R()->repaint();
+		g_win->R()->compiler()->needMerge();
 		print ("Changed file to %1", f->getDisplayName());
 	}
 }
--- a/src/Document.h	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/Document.h	Mon Mar 10 00:53:39 2014 +0200
@@ -27,6 +27,7 @@
 class OpenProgressDialog;
 class LDDocumentPointer;
 struct LDGLData;
+class GLCompiler;
 
 namespace LDPaths
 {
--- a/src/GLCompiler.cc	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/GLCompiler.cc	Mon Mar 10 00:53:39 2014 +0200
@@ -72,10 +72,10 @@
 
 // =============================================================================
 //
-GLCompiler::GLCompiler() :
-	m_document (null)
+GLCompiler::GLCompiler()
 {
 	needMerge();
+	memset (mVBOSizes, 0, sizeof mVBOSizes);
 }
 
 // =============================================================================
@@ -196,12 +196,12 @@
 
 // =============================================================================
 //
-void GLCompiler::compileDocument()
+void GLCompiler::compileDocument (LDDocument* doc)
 {
-	if (document() == null)
+	if (doc == null)
 		return;
 
-	for (LDObject* obj : document()->objects())
+	for (LDObject* obj : doc->objects())
 		compileObject (obj);
 }
 
@@ -225,19 +225,20 @@
 	if (mChanged[vbonum] == false)
 		return;
 
-	mVBOData[vbonum].clear();
+	QVector<GLfloat> vbodata;
 
 	for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it)
-		mVBOData[vbonum] += it->data[vbonum];
+	{
+		if (it.key()->document() == getCurrentDocument())
+			vbodata += it->data[vbonum];
+	}
 
 	glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]);
-	checkGLError();
-	glBufferData (GL_ARRAY_BUFFER, mVBOData[vbonum].size() * sizeof(float),
-		mVBOData[vbonum].constData(), GL_DYNAMIC_DRAW);
-	checkGLError();
+	glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW);
 	glBindBuffer (GL_ARRAY_BUFFER, 0);
 	checkGLError();
 	mChanged[vbonum] = false;
+	mVBOSizes[vbonum] = vbodata.size();
 }
 
 // =============================================================================
@@ -360,7 +361,6 @@
 		{
 			LDSubfile* ref = static_cast<LDSubfile*> (obj);
 			auto data = ref->inlinePolygons();
-			print ("inlinePolygons on %2 yielded %1 polys\n", data.size(), ref->fileInfo()->getDisplayName());
 
 			for (LDPolygon& poly : data)
 			{
@@ -383,4 +383,4 @@
 			<< ((float) color.green()) / 255.0f
 			<< ((float) color.blue()) / 255.0f
 			<< ((float) color.alpha()) / 255.0f;
-}
\ No newline at end of file
+}
--- a/src/GLCompiler.h	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/GLCompiler.h	Mon Mar 10 00:53:39 2014 +0200
@@ -28,8 +28,6 @@
 //
 class GLCompiler
 {
-	PROPERTY (public,	LDDocumentPointer,	document,	setDocument,	STOCK_WRITE)
-
 	public:
 		struct ObjectVBOInfo
 		{
@@ -38,7 +36,7 @@
 
 		GLCompiler();
 		~GLCompiler();
-		void				compileDocument();
+		void				compileDocument (LDDocument* doc);
 		void				dropObject (LDObject* obj);
 		void				initialize();
 		QColor				getPolygonColor (LDPolygon& poly, LDObject* topobj) const;
@@ -61,7 +59,7 @@
 
 		inline int			getVBOCount (int vbonum) const
 		{
-			return mVBOData[vbonum].size() / 3;
+			return mVBOSizes[vbonum] / 3;
 		}
 
 	private:
@@ -72,10 +70,10 @@
 		void			compilePolygon (LDPolygon& poly, LDObject* topobj, GLCompiler::ObjectVBOInfo* objinfo);
 
 		QMap<LDObject*, ObjectVBOInfo>		mObjectInfo;
-		QVector<GLfloat>					mVBOData[gNumVBOs];
+		LDObjectList						mStaged; // Objects that need to be compiled
 		GLuint								mVBOs[gNumVBOs];
 		bool								mChanged[gNumVBOs];
-		LDObjectList						mStaged; // Objects that need to be compiled
+		int									mVBOSizes[gNumVBOs];
 };
 
 #define checkGLError() { checkGLError_private (__FILE__, __LINE__); }
--- a/src/GLRenderer.cc	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/GLRenderer.cc	Mon Mar 10 00:53:39 2014 +0200
@@ -25,6 +25,7 @@
 #include <QContextMenuEvent>
 #include <QInputDialog>
 #include <QToolTip>
+#include <qtextdocument.h>
 #include <QTimer>
 #include "Main.h"
 #include "Configuration.h"
@@ -131,7 +132,7 @@
 	setMessageLog (null);
 	m_width = m_height = -1;
 	m_hoverpos = g_origin;
-
+	m_compiler = new GLCompiler;
 	m_toolTipTimer = new QTimer (this);
 	m_toolTipTimer->setSingleShot (true);
 	connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer()));
@@ -249,17 +250,12 @@
 void GLRenderer::initializeGL()
 {
 	setBackground();
-
 	glLineWidth (gl_linethickness);
 	glLineStipple (1, 0x6666);
-
 	setAutoFillBackground (false);
 	setMouseTracking (true);
 	setFocusPolicy (Qt::WheelFocus);
-
-	m_compiler->initialize();
-	m_compiler->compileDocument();
-
+	compiler()->initialize();
 	initializeAxes();
 }
 
@@ -334,13 +330,12 @@
 }
 
 // =============================================================================
-// -----------------------------------------------------------------------------
+//
 void GLRenderer::hardRefresh()
 {
-	m_compiler->compileDocument();
+	compiler()->compileDocument (getCurrentDocument());
 	refresh();
-
-	glLineWidth (gl_linethickness);
+	glLineWidth (gl_linethickness); // TODO: ...?
 }
 
 // =============================================================================
@@ -579,6 +574,18 @@
 	if (isDrawOnly())
 		return;
 
+#ifndef RELEASE
+	if (isPicking() == false)
+	{
+		QString text = format ("Rotation: (%1, %2, %3)\nPanning: (%4, %5), Zoom: %6",
+			rot(X), rot(Y), rot(Z), pan(X), pan(Y), zoom());
+		QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text);
+
+		paint.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
+			textSize.height(), Qt::AlignCenter, text);
+	}
+#endif
+
 	if (camera() != EFreeCamera && !isPicking())
 	{
 		// Paint the overlay image if we have one
@@ -880,13 +887,6 @@
 
 // =============================================================================
 //
-void GLRenderer::compileAllObjects()
-{
-	m_compiler->compileDocument();
-}
-
-// =============================================================================
-//
 void GLRenderer::clampAngle (double& angle) const
 {
 	while (angle < 0)
@@ -1338,7 +1338,6 @@
 void GLRenderer::setDocument (LDDocument* const& a)
 {
 	m_document = a;
-	m_compiler->setDocument (a);
 
 	if (a != null)
 	{
@@ -1613,7 +1612,7 @@
 //
 void GLRenderer::compileObject (LDObject* obj)
 {
-	m_compiler->stageForCompilation (obj);
+	compiler()->stageForCompilation (obj);
 
 	// Mark in known vertices of this object
 	/*
@@ -1629,7 +1628,7 @@
 //
 void GLRenderer::forgetObject (LDObject* obj)
 {
-	m_compiler->dropObject (obj);
+	compiler()->dropObject (obj);
 }
 
 // =============================================================================
--- a/src/GLRenderer.h	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/GLRenderer.h	Mon Mar 10 00:53:39 2014 +0200
@@ -121,10 +121,10 @@
 		// and Qt doesn't like that.
 		struct CameraIcon
 		{
-			QPixmap*			img;
-			QRect				srcRect,
-								destRect,
-								selRect;
+			QPixmap*		img;
+			QRect			srcRect,
+							destRect,
+							selRect;
 			EFixedCamera	cam;
 		};
 
@@ -134,6 +134,7 @@
 		PROPERTY (private,	bool,				isPicking,	setPicking,		STOCK_WRITE)
 		PROPERTY (public,	LDDocument*,		document,	setDocument,	CUSTOM_WRITE)
 		PROPERTY (public,	EditMode,			editMode,	setEditMode,	CUSTOM_WRITE)
+		PROPERTY (private,	GLCompiler*,		compiler,	setCompiler,	STOCK_WRITE)
 
 	public:
 		GLRenderer (QWidget* parent = null);
@@ -146,7 +147,6 @@
 
 		void           clearOverlay();
 		void           compileObject (LDObject* obj);
-		void           compileAllObjects();
 		void           drawGLScene();
 		void           endDraw (bool accept);
 		void           forgetObject (LDObject* obj);
@@ -217,7 +217,6 @@
 		Vertex						m_rectverts[4];
 		QColor						m_bgcolor;
 		QList<Vertex>				m_knownVerts;
-		GLCompiler*					m_compiler;
 
 		void           addDrawnVertex (Vertex m_hoverpos);
 		LDOverlay*     findOverlayObject (EFixedCamera cam);
--- a/src/LDObject.cc	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/LDObject.cc	Mon Mar 10 00:53:39 2014 +0200
@@ -366,7 +366,6 @@
 QList<LDPolygon> LDSubfile::inlinePolygons()
 {
 	QList<LDPolygon> data = fileInfo()->inlinePolygons();
-	print ("LDSubfile::inlinePolygons: %1 has %2 polygons\n", fileInfo()->getDisplayName(), data.size());
 
 	for (LDPolygon& entry : data)
 		for (int i = 0; i < entry.numVertices(); ++i)
--- a/src/actions/EditActions.cc	Sun Mar 09 21:14:07 2014 +0200
+++ b/src/actions/EditActions.cc	Mon Mar 10 00:53:39 2014 +0200
@@ -384,15 +384,15 @@
 	vect[X] *= *currentGrid().confs[Grid::X];
 	vect[Y] *= *currentGrid().confs[Grid::Y];
 	vect[Z] *= *currentGrid().confs[Grid::Z];
+	QTime t0 = QTime::currentTime();
 
-	QTime t0 = QTime::currentTime();
 	for (LDObject* obj : selection())
 	{
 		obj->move (vect);
 		g_win->R()->compileObject (obj);
 	}
-	fprint (stderr, "Move: %1ms\n", t0.msecsTo (QTime::currentTime()));
 
+	dprint ("Move: %1ms\n", t0.msecsTo (QTime::currentTime()));
 	g_win->refresh();
 }
 

mercurial