- greatly improved the GL compiler, now deals colors and object removal properly

Sun, 23 Feb 2014 18:49:24 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 23 Feb 2014 18:49:24 +0200
changeset 684
8a56b1d4d44d
parent 683
b7460d693f63
child 685
2e74d99ee7ec

- greatly improved the GL compiler, now deals colors and object removal properly

CMakeLists.txt 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/Main.cc file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Feb 22 16:41:03 2014 +0200
+++ b/CMakeLists.txt	Sun Feb 23 18:49:24 2014 +0200
@@ -31,6 +31,7 @@
 	src/EditHistory.cc
 	src/ExternalPrograms.cc
 	src/GLRenderer.cc
+	src/GLCompiler.cc
 	src/LDConfig.cc
 	src/LDObject.cc
 	src/Main.cc
--- a/src/GLCompiler.cc	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/GLCompiler.cc	Sun Feb 23 18:49:24 2014 +0200
@@ -137,7 +137,6 @@
 	if (poly.color == edgecolor)
 	{
 		qcol = QColor (32, 32, 32); // luma (m_bgcolor) < 40 ? QColor (64, 64, 64) : Qt::black;
-		LDColor* col;
 
 		/*
 		if (!gl_blackedges && poly.obj->getParent() && (col = getColor (poly.obj->getParent()->getColor())))
@@ -226,6 +225,11 @@
 	if (mChanged[vbonum] == false)
 		return;
 
+	mVBOData[vbonum].clear();
+
+	for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it)
+		mVBOData[vbonum] += it->data[vbonum];
+
 	glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]);
 	checkGLError();
 	glBufferData (GL_ARRAY_BUFFER, mVBOData[vbonum].size() * sizeof(float),
@@ -238,25 +242,15 @@
 
 // =============================================================================
 //
-void GLCompiler::uncompileObject (LDObject* obj)
+void GLCompiler::dropObject (LDObject* obj)
 {
 	auto it = mObjectInfo.find (obj);
 
-	if (it == mObjectInfo.end())
-		return;
-
-	ObjectVBOInfo* info = &(*it);
-
-	for (int i = 0; i < gNumVBOs; ++i)
+	if (it != mObjectInfo.end())
 	{
-		if (info->size[i] == 0)
-			continue;
-
-		mVBOData[i].remove (info->offset[i], info->size[i]);
-		mChanged[i] = true;
+		mObjectInfo.erase (it);
+		needMerge();
 	}
-
-	mObjectInfo.erase (it);
 }
 
 // =============================================================================
@@ -264,12 +258,7 @@
 void GLCompiler::compileObject (LDObject* obj)
 {
 	ObjectVBOInfo info;
-	uncompileObject (obj);
-
-	for (int i = 0; i < gNumVBOs; ++i)
-		info.offset[i] = mVBOData[i].size();
-
-	memset (info.size, 0, sizeof info.size);
+	dropObject (obj);
 	compileSubObject (obj, obj, &info);
 	mObjectInfo[obj] = info;
 	needMerge();
@@ -298,14 +287,12 @@
 	for (int complement = 0; complement < vboNumComplements; ++complement)
 	{
 		const int vbonum			= getVBONumber (surface, (EVBOComplement) complement);
-		QVector<GLfloat>& vbodata	= mVBOData[vbonum];
+		QVector<GLfloat>& vbodata	= objinfo->data[vbonum];
 		const QColor normalColor	= getPolygonColor (poly, topobj);
 		const QColor pickColor		= getIndexColor (topobj->getID());
 
 		for (int vert = 0; vert < numverts; ++vert)
 		{
-			objinfo->size[vbonum] += (complement == vboSurfaces) ? 3 : 4;
-
 			switch ((EVBOComplement) complement)
 			{
 				case vboSurfaces:
@@ -372,20 +359,14 @@
 
 		case LDObject::ESubfile:
 		{
-			CLOCK_INIT
-			CLOCK_START
 			LDSubfile* ref = static_cast<LDSubfile*> (obj);
 			auto data = ref->inlinePolygons();
-			CLOCK_TIME ("Inline")
-			CLOCK_START
 
 			for (LDPolygon& poly : data)
 			{
 				poly.id = topobj->getID();
 				compilePolygon (poly, topobj, objinfo);
 			}
-			CLOCK_TIME ("Compile")
-
 			break;
 		}
 
--- a/src/GLCompiler.h	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/GLCompiler.h	Sun Feb 23 18:49:24 2014 +0200
@@ -33,14 +33,13 @@
 	public:
 		struct ObjectVBOInfo
 		{
-			int offset[gNumVBOs];
-			int size[gNumVBOs];
+			QVector<GLfloat> data[gNumVBOs];
 		};
 
 		GLCompiler();
 		~GLCompiler();
 		void				compileDocument();
-		void				uncompileObject (LDObject* obj);
+		void				dropObject (LDObject* obj);
 		void				initialize();
 		QColor				getPolygonColor (LDPolygon& poly, LDObject* topobj) const;
 		QColor				getIndexColor (int id) const;
--- a/src/GLRenderer.cc	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/GLRenderer.cc	Sun Feb 23 18:49:24 2014 +0200
@@ -405,6 +405,7 @@
 	}
 
 	glEnableClientState (GL_VERTEX_ARRAY);
+	glEnableClientState (GL_COLOR_ARRAY);
 
 	if (gl_axes)
 	{
@@ -416,14 +417,40 @@
 		checkGLError();
 	}
 
-	drawVBOs (vboTriangles, GL_TRIANGLES);
-	drawVBOs (vboQuads, GL_QUADS);
-	drawVBOs (vboLines, GL_LINES);
-	drawVBOs (vboCondLines, GL_LINES);
+	if (isPicking())
+	{
+		drawVBOs (vboTriangles, vboPickColors, GL_TRIANGLES);
+		drawVBOs (vboQuads, vboPickColors, GL_QUADS);
+		drawVBOs (vboLines, vboPickColors, GL_LINES);
+		drawVBOs (vboCondLines, vboPickColors, GL_LINES);
+	}
+	else
+	{
+		if (gl_colorbfc)
+		{
+			glEnable (GL_CULL_FACE);
+			glCullFace (GL_BACK);
+			drawVBOs (vboTriangles, vboBFCFrontColors, GL_TRIANGLES);
+			drawVBOs (vboQuads, vboBFCFrontColors, GL_QUADS);
+			glCullFace (GL_FRONT);
+			drawVBOs (vboTriangles, vboBFCBackColors, GL_TRIANGLES);
+			drawVBOs (vboQuads, vboBFCBackColors, GL_QUADS);
+			glDisable (GL_CULL_FACE);
+		}
+		else
+		{
+			drawVBOs (vboTriangles, vboNormalColors, GL_TRIANGLES);
+			drawVBOs (vboQuads, vboNormalColors, GL_QUADS);
+		}
+
+		drawVBOs (vboLines, vboNormalColors, GL_LINES);
+		drawVBOs (vboCondLines, vboNormalColors, GL_LINES);
+	}
 
 	glPopMatrix();
 	glBindBuffer (GL_ARRAY_BUFFER, 0);
 	glDisableClientState (GL_VERTEX_ARRAY);
+	glDisableClientState (GL_COLOR_ARRAY);
 	checkGLError();
 	glDisable (GL_CULL_FACE);
 	glMatrixMode (GL_MODELVIEW);
@@ -432,10 +459,10 @@
 
 // =============================================================================
 //
-void GLRenderer::drawVBOs (EVBOSurface surface, GLenum type)
+void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type)
 {
 	int surfacenum = m_compiler->getVBONumber (surface, vboSurfaces);
-	int colornum = m_compiler->getVBONumber (surface, vboNormalColors);
+	int colornum = m_compiler->getVBONumber (surface, colors);
 
 	m_compiler->prepareVBO (surfacenum);
 	m_compiler->prepareVBO (colornum);
@@ -1598,7 +1625,7 @@
 //
 void GLRenderer::forgetObject (LDObject* obj)
 {
-	m_compiler->uncompileObject (obj);
+	m_compiler->dropObject (obj);
 }
 
 // =============================================================================
@@ -1690,11 +1717,11 @@
 
 	// Set alpha of all pixels to 0.5
 	for (long i = 0; i < img->width(); ++i)
-		for (long j = 0; j < img->height(); ++j)
-		{
-			uint32 pixel = img->pixel (i, j);
-			img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF));
-		}
+	for (long j = 0; j < img->height(); ++j)
+	{
+		uint32 pixel = img->pixel (i, j);
+		img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF));
+	}
 
 	updateOverlayObjects();
 	return true;
--- a/src/GLRenderer.h	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/GLRenderer.h	Sun Feb 23 18:49:24 2014 +0200
@@ -250,7 +250,7 @@
 		Vertex         coordconv2_3 (const QPoint& pos2d, bool snap) const;
 
 		// Draw a VBO array
-		void           drawVBOs (EVBOSurface surface, GLenum type);
+		void           drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type);
 
 		// Determine which color to draw text with
 		QColor         getTextPen() const;
--- a/src/LDObject.cc	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/LDObject.cc	Sun Feb 23 18:49:24 2014 +0200
@@ -341,12 +341,12 @@
 {
 	Type ot = getType();
 	int num =
-		(ot == LDObject::ELine)		? 2 :
-		(ot == LDObject::ETriangle)	? 3 :
-		(ot == LDObject::EQuad)		? 4 :
-		(ot == LDObject::ECondLine)	? 5 :
-									  0;
-	if (ot == 0)
+		(ot == LDObject::ELine)		?	2 :
+		(ot == LDObject::ETriangle)	?	3 :
+		(ot == LDObject::EQuad)		?	4 :
+		(ot == LDObject::ECondLine)	?	5 :
+										0;
+	if (num == 0)
 		return null;
 
 	LDPolygon* data = new LDPolygon;
--- a/src/Main.cc	Sat Feb 22 16:41:03 2014 +0200
+++ b/src/Main.cc	Sun Feb 23 18:49:24 2014 +0200
@@ -72,30 +72,6 @@
 	newFile();
 	win->show();
 
-	/*
-	LDDocument* box = getDocument ("box.dat");
-	LDSubfile* ref = new LDSubfile;
-	ref->setFileInfo (box);
-	ref->setPosition (g_origin);
-	ref->setTransform (g_identity);
-	ref->setColor (maincolor);
-	assert (box != null);
-
-	for (int i = 0; i < 500; ++i)
-	{
-		QTime t0 = QTime::currentTime();
-		LDObjectList objs = ref->inlineContents (LDSubfile::DeepCacheInline | LDSubfile::RendererInline);
-		LDObject::Type type = static_cast<LDObject*> (ref)->getType();
-		dlog ("%1: %2ms (%3 objs)\n", i, t0.msecsTo (QTime::currentTime()), objs.size());
-
-		for (LDObject* obj : objs)
-			obj->deleteSelf();
-	}
-
-	ref->deleteSelf();
-	delete box;
-	*/
-
 	// If this is the first start, get the user to configuration. Especially point
 	// them to the profile tab, it's the most important form to fill in.
 	if (firststart)

mercurial