Hi,
I got it to work, I think it was that I had to commit changes in the main
Thread before rendering and not afterwards.
thanks and best regards,
Victor
On Fri, Sep 26, 2014 at 10:43 PM, Victor Haefner <victor.haef...@gmail.com>
wrote:
> Hi Carsten,
>
> thanks for those clarifications about changelists, but I still am confused
> about the difference between commit and apply.
> I made a standalone working example of my problem (c++11), my next step
> will be to merge it in my project.. hope it will work :)
> this needs two cluster multicast clients 'l1' and 'l2', hope it will be
> useful to someone, any feedback is welcome.
>
> Thanks and best regards,
> Victor
>
> #include <OpenSG/OSGGLUT.h>
> #include <OpenSG/OSGConfig.h>
> #include <OpenSG/OSGSimpleGeometry.h>
> #include <OpenSG/OSGGLUTWindow.h>
> #include <OpenSG/OSGPerspectiveCamera.h>
> #include <OpenSG/OSGSimpleSceneManager.h>
> #include <OpenSG/OSGSolidBackground.h>
> #include <OpenSG/OSGPointLight.h>
> #include <OpenSG/OSGMultiDisplayWindow.h>
> #include <boost/thread/thread.hpp>
> #include <boost/thread.hpp>
>
> #include <OpenSG/OSGChangeList.h>
> #include <OpenSG/OSGThread.h>
> #include <OpenSG/OSGThreadManager.h>
>
> OSG_USING_NAMESPACE;
> using namespace std;
>
> enum STATE {
> NO_CONNECTION = 0,
> CONNECTED = 1,
> INITIALIZING = 2,
> CONNECTING = 3
> };
>
> GLUTWindowRecPtr gwin;
> TransformRecPtr trans;
> RenderActionRefPtr ract;
> ViewportRecPtr vp2;
> ViewportRecPtr vp3;
> int N = 1;
>
> class OSGThread : public ExternalThread {
> public:
> static ExternalThread* create(const char* szName, int uiId) {
> return ExternalThread::create(szName, uiId);
> }
> };
>
> class MultiWindow {
> private:
> boost::thread* thread = 0;
> int tries = 0;
> string server;
> ViewportRecPtr vp;
> STATE state = INITIALIZING;
> MultiDisplayWindowRecPtr mwin;
>
> public:
> MultiWindow(string s, ViewportRecPtr vp) {
> N++;
> server = s;
> this->vp = vp;
> thread = new boost::thread(boost::bind(&MultiWindow::update,
> this));
> }
>
> bool init_win(const std::string &msg, const std::string &server,
> Real32 progress) {
> if (progress == 1) { state = CONNECTED; return true; }
> if (tries == 3) { state = NO_CONNECTION; return false; }
> tries++;
> return true;
> }
>
> void initialize(RenderActionRefPtr ract) {
> cout << "Initializing\n";
> state = CONNECTING;
> mwin = MultiDisplayWindow::create();
>
> mwin->setSize(300, 300);
> mwin->setHServers(1);
> mwin->setVServers(1);
> mwin->editMFServers()->push_back(server.c_str());
> mwin->addPort(vp);
>
> Thread::getCurrentChangeList()->commitChangesAndClear();
> Thread::getCurrentChangeList()->fillFromCurrentState();
>
> ClusterWindow::ConnectionCB cb =
> boost::bind(&MultiWindow::init_win, this, _1, _2, _3);
> mwin->initAsync(cb);
> cout << " done\n";
> }
>
> void update() {
> ExternalThreadRefPtr tr = OSGThread::create("update", 0);
> tr->initialize(0);
>
> sleep(3);
>
> do {
> BarrierRefPtr barrier = Barrier::get("MDW", true);
> barrier->enter(N);
>
> ThreadRefPtr appThread =
> dynamic_cast<Thread*>(ThreadManager::getAppThread());
> ChangeList* cl = Thread::getCurrentChangeList();
> ChangeList* acl = appThread->getChangeList();
> cl->merge(*acl);
>
> if (state == INITIALIZING) initialize(ract);
> if (state == CONNECTED) {
> try { mwin->render(ract); }
> catch(exception e) { state = INITIALIZING; }
> }
>
> Thread::getCurrentChangeList()->clear();
> barrier->enter(N);
>
> osgSleep(1);
> } while(true);
> }
> };
>
> void reshape(int w, int h) { gwin->resize(w, h); glutPostRedisplay(); }
> void display(void) {
> OSG::Matrix m;
> OSG::Real32 time = glutGet(GLUT_ELAPSED_TIME );
> m.setRotate(OSG::Quaternion(OSG::Vec3f(0,1,0), time/300.f));
> m.setTranslate(Vec3f(0,0,-1));
> trans->setMatrix(m);
> commitChanges();
>
> gwin->render(ract);
>
> BarrierRefPtr barrier = Barrier::get("MDW", true);
> if (barrier->getNumWaiting() == N-1) {
> barrier->enter(N);
> barrier->enter(N);
> }
>
> Thread::getCurrentChangeList()->clear();
> }
>
>
> int main(int argc, char **argv) {
> glutInit(&argc, argv);
> glEnable(GL_DEPTH_TEST);
> glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
> ChangeList::setReadWriteDefault();
> osgInit(argc,argv);
> int winid = glutCreateWindow("MW test");
> glutDisplayFunc(display);
> glutReshapeFunc(reshape);
> glutIdleFunc(display);
> gwin = GLUTWindow::create();
> gwin->setGlutId(winid);
> gwin->init();
> ract = RenderAction::create();
>
> trans = Transform::create();
> NodeRecPtr l = makeNodeFor(PointLight::create());
> NodeRecPtr t = makeNodeFor(trans);
> NodeRecPtr cb = makeNodeFor(Transform::create());
> NodeRecPtr g = makeTeapot(4, 0.1);
> PerspectiveCameraRecPtr c = PerspectiveCamera::create();
> SolidBackgroundRecPtr bg = SolidBackground::create();
> l->addChild(cb);
> l->addChild(t);
> t->addChild(g);
> c->setBeacon(cb);
> c->setFov(osgDegree2Rad(60));
> c->setNear(0.1);
> c->setFar(10);
>
> ViewportRecPtr vp = Viewport::create();
> gwin->addPort(vp);
> vp->setRoot(l);
> vp->setCamera(c);
> vp->setBackground(bg);
>
> vp2 = Viewport::create();
> vp2->setRoot(l);
> vp2->setCamera(c);
> vp2->setBackground(bg);
>
> vp3 = Viewport::create();
> vp3->setRoot(l);
> vp3->setCamera(c);
> vp3->setBackground(bg);
>
> MultiWindow* mv1 = new MultiWindow("l1", vp2);
> MultiWindow* mv2 = new MultiWindow("l2", vp3);
>
> glutMainLoop();
>
> return 0;
> }
>
> On Fri, Sep 26, 2014 at 10:55 AM, Carsten Neumann <
> carsten.p.neum...@gmail.com> wrote:
>
>> Hello Victor,
>>
>> On 2014-09-25 21:35, Victor Haefner wrote:
>> > I see nothing on the cluster client and I get this output:
>> > ...
>> > WARNING: New container type 'GeoPnt3fProperty' local id '6476' remote id
>> > '1100' dies because of missing ref counts.
>> > WARNING: New container type 'GeoVec3fProperty' local id '6477' remote id
>> > '1101' dies because of missing ref counts.
>> [SNIP]
>> > Any ideas why the refcount is 'missing' ??
>>
>> I haven't had a chance to look at/think about the code you've posted.
>> These warnings mean that the machine received the information that a new
>> FieldContainer was created, but the changes sent to the machine did not
>> contain any info about a ref count increase. That means at the end of
>> processing the received changes the container has zero references and
>> thus is destroyed (containers are kept 'artificially' alive for the
>> duration of the sync but not longer).
>>
>> > I think I am doing something wrong when merging the changelists..
>> >
>> > I also did not fully understand what committing a changelist does.
>>
>> The CL serves two (related) purposes. The first is entirely unrelated to
>> multi-threading or clusters: changes are recorded (which FC and which
>> Fields of the FC) and when calling OSG::commitChanges() the changed()
>> member function of modified FCs is called so that they can update
>> internal state that depends on the changed fields. Changes that are
>> recorded but for which commitChanges() was not called yet are
>> 'uncommitted' changes, afterwards they are 'committed' changes.
>>
>> The second purpose is to be able to transfer changes to a different
>> aspect copy (local or remote) of an FC. Therefore commitChanges() does
>> not throw away the change record, but keeps it until the CL is cleared
>> (for single thread, non-cluster apps it can be done in one call:
>> commitChangesAndClear()). In a threaded/cluster application you would
>> usually clear the CL right after merging it to the destination
>> aspect/sending it over the network - that way you don't loose changes
>> and avoid applying them twice.
>>
>> Hope the above helps, cheers,
>> Carsten
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
>> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
>> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
>> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Opensg-users mailing list
>> Opensg-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/opensg-users
>>
>
>
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users