← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-pkg/yade/git-trunk] Rev 3882: Replace some "defines" by functions.

 

------------------------------------------------------------
revno: 3882
committer: Anton Gladky <gladky.anton@xxxxxxxxx>
timestamp: Wed 2016-06-01 21:16:04 +0200
message:
  Replace some "defines" by functions.
modified:
  pkg/common/OpenGLRenderer.cpp
  pkg/common/OpenGLRenderer.hpp


--
lp:yade
https://code.launchpad.net/~yade-pkg/yade/git-trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-pkg/yade/git-trunk/+edit-subscription
=== modified file 'pkg/common/OpenGLRenderer.cpp'
--- pkg/common/OpenGLRenderer.cpp	2014-10-15 06:44:01 +0000
+++ pkg/common/OpenGLRenderer.cpp	2016-06-01 19:16:04 +0000
@@ -3,23 +3,16 @@
 
 #ifdef YADE_OPENGL
 
-#include"OpenGLRenderer.hpp"
-#include<lib/opengl/OpenGLWrapper.hpp>
-#include<lib/opengl/GLUtils.hpp>
-#include<core/Timing.hpp>
-#include<core/Scene.hpp>
-#include<pkg/common/Aabb.hpp>
-#include<lib/pyutil/gil.hpp>
+#include "OpenGLRenderer.hpp"
+#include <lib/opengl/GLUtils.hpp>
+#include <core/Timing.hpp>
+#include <core/Scene.hpp>
+#include <pkg/common/Aabb.hpp>
+#include <lib/pyutil/gil.hpp>
 
-#ifdef __APPLE__
-#  include <OpenGL/glu.h>
-#  include <OpenGL/gl.h>
-#  include <GLUT/glut.h>
-#else
-#  include <GL/glu.h>
-#  include <GL/gl.h>
-#  include <GL/glut.h>
-#endif
+#include <GL/glu.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
 
 YADE_PLUGIN((OpenGLRenderer)(GlExtraDrawer));
 CREATE_LOGGER(OpenGLRenderer);
@@ -30,7 +23,6 @@
 const int OpenGLRenderer::numClipPlanes;
 OpenGLRenderer::~OpenGLRenderer(){}
 
-
 void OpenGLRenderer::init(){
 	typedef std::pair<string,DynlibDescriptor> strDldPair; // necessary as FOREACH, being macro, cannot have the "," inside the argument (preprocessor does not parse templates)
 	FOREACH(const strDldPair& item, Omega::instance().getDynlibsDescriptor()){
@@ -52,12 +44,6 @@
 	}
 
 	initDone=true;
-	// glGetError crashes at some machines?! Was never really useful, anyway.
-	// reported http://www.mail-archive.com/yade-users@xxxxxxxxxxxxxxxxxxx/msg01482.html
-	#if 0
-		int e=glGetError();
-		if(e!=GL_NO_ERROR) throw runtime_error((string("OpenGLRenderer::init returned GL error ")+boost::lexical_cast<string>(e)).c_str());
-	#endif
 }
 
 void OpenGLRenderer::setBodiesRefSe3(){
@@ -66,16 +52,22 @@
 	scene->cell->refHSize=scene->cell->hSize;
 }
 
+template<class FunctorType, class DispatcherT>
+void OpenGLRenderer::setupDispatcher(const vector<string> & names, DispatcherT & dispatcher) {
+	dispatcher.clearMatrix();
+	for(const auto & s : names) {
+		shared_ptr<FunctorType> f(boost::static_pointer_cast<FunctorType>(ClassFactory::instance().createShared(s)));
+		f->initgl();
+		dispatcher.add(f);
+	}
+}
 
 void OpenGLRenderer::initgl(){
 	LOG_DEBUG("(re)initializing GL for gldraw methods.\n");
-	#define _SETUP_DISPATCHER(names,FunctorType,dispatcher) dispatcher.clearMatrix(); FOREACH(string& s,names) {shared_ptr<FunctorType> f(boost::static_pointer_cast<FunctorType>(ClassFactory::instance().createShared(s))); f->initgl(); dispatcher.add(f);}
-		// _SETUP_DISPATCHER(stateFunctorNames,GlStateFunctor,stateDispatcher);
-		_SETUP_DISPATCHER(boundFunctorNames,GlBoundFunctor,boundDispatcher);
-		_SETUP_DISPATCHER(shapeFunctorNames,GlShapeFunctor,shapeDispatcher);
-		_SETUP_DISPATCHER(geomFunctorNames,GlIGeomFunctor,geomDispatcher);
-		_SETUP_DISPATCHER(physFunctorNames,GlIPhysFunctor,physDispatcher);
-	#undef _SETUP_DISPATCHER
+	setupDispatcher<GlBoundFunctor, GlBoundDispatcher> (boundFunctorNames, boundDispatcher);
+	setupDispatcher<GlShapeFunctor, GlShapeDispatcher> (shapeFunctorNames, shapeDispatcher);
+	setupDispatcher<GlIGeomFunctor, GlIGeomDispatcher> (geomFunctorNames, geomDispatcher);
+	setupDispatcher<GlIPhysFunctor, GlIPhysDispatcher> (physFunctorNames, physDispatcher);
 }
 
 bool OpenGLRenderer::pointClipped(const Vector3r& p){
@@ -84,7 +76,6 @@
 	return false;
 }
 
-
 void OpenGLRenderer::setBodiesDispInfo(){
 	if(scene->bodies->size()!=bodyDisp.size()) {
 		bodyDisp.resize(scene->bodies->size());
@@ -228,8 +219,6 @@
 			d->render();
 		glPopMatrix();
 	}
-
-
 }
 
 void OpenGLRenderer::renderAllInteractionsWire(){
@@ -288,7 +277,6 @@
 	}
 }
 
-
 void OpenGLRenderer::renderIPhys(){
 	physDispatcher.scene=scene.get(); physDispatcher.updateScenePtr();
 	{
@@ -412,5 +400,4 @@
 	}
 }
 
-
 #endif /* YADE_OPENGL */

=== modified file 'pkg/common/OpenGLRenderer.hpp'
--- pkg/common/OpenGLRenderer.hpp	2015-05-22 05:46:49 +0000
+++ pkg/common/OpenGLRenderer.hpp	2016-06-01 19:16:04 +0000
@@ -2,12 +2,10 @@
 // © 2008 Václav Šmilauer <eudoxos@xxxxxxxx>
 #pragma once
 
-#include<lib/multimethods/DynLibDispatcher.hpp>
-#include<core/Dispatcher.hpp>
-#include<core/Body.hpp>
-#include<lib/opengl/OpenGLWrapper.hpp>
-
-#include<pkg/common/GLDrawFunctors.hpp>
+#include <lib/multimethods/DynLibDispatcher.hpp>
+#include <core/Dispatcher.hpp>
+#include <core/Body.hpp>
+#include <pkg/common/GLDrawFunctors.hpp>
 
 struct GlExtraDrawer: public Serializable{
 	Scene* scene;
@@ -88,6 +86,7 @@
 		// called also to render selectable entitites;
 		void renderShape();
 		void renderAllInteractionsWire();
+		template<class FunctorType, class DispatcherT> void setupDispatcher(const vector<string> & names, DispatcherT & dispatcher);
 
 	YADE_CLASS_BASE_DOC_ATTRS_CTOR_PY(OpenGLRenderer,Serializable,"Class responsible for rendering scene on OpenGL devices.",
 		((Vector3r,dispScale,((void)"disable scaling",Vector3r::Ones()),,"Artificially enlarge (scale) dispalcements from bodies' :yref:`reference positions<State.refPos>` by this relative amount, so that they become better visible (independently in 3 dimensions). Disbled if (1,1,1)."))