Hello again,

Thanks for your reply!

I have now tried the suggestions concerning both preDrawCallback and
osg::Operation and they result in the same behaviour. I still get one
context with correct terrain textures and one with black textures.
Everything else in the scene shows up as expected in both contexts.

When using the osg::Operation I had to add the operation after
viewer.realize(), otherwise it wasn't performed.

What to try next?

//Karl


On 7/13/07, Robert Osfield <[EMAIL PROTECTED]> wrote:

HI Karl,

To do the graphics work you should do all the ops from the thread that
the graphics context has.  The easist way to this by adding in pre or
post draw callback to the camera.  Alternatively you can add an custom
osg::Operation to the GraphicsWindow and this will be called during
the standard frame.

In the SVN version of the OSG you also have the option of using a
CompileContext, which is a pbuffer created per main graphics context
and is shared with this context.  This CompileContext can have its own
GaphicsThread that you can pass a custom osg::Operation to do the
compile.  Its effectively the same approach as adding it to the main
GraphicsWindow except its done in a separate thread.

The src/applications/osgviewer.cpp has some code in place that
illustrates how to create the compile contexts.

Another things you might consider is using the OSG standard database
paging support, this way you won't need to do any tricky stuff
yourself, it'll all be done for you.

Robert.

On 7/13/07, Karl Heijdenberg <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a tricky problem with composite viewer. I will try to explain it.
>
> We are developing an application for flight simulation with both terrain
and
> texture paging.
> The problem occurs for the texture paging in a callback that loads
textures
> to the graphics card.
>
> First of all I create two contexts and using one camera per context.
> For each camera I add an update callback, for texture loading.
>
> The callback class, that is called, holds a pointer to the graphics
context.
> Upon a callback call I
> only get filled black polygons, when textures are loaded (for both
> contexts). If I add a call to makeCurrent()
> on the graphics context in the called method, my textures are shown for
the
> first
> context as expected. However in the second context the textures are
still
> black.
>
> // Setup composite viewer
>   viewer_ = new CompositeViewer;
>
>
viewer_->setThreadingModel(osgViewer::CompositeViewer::ThreadPerContext);
>
>   osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>   traits->x = 0;
>   traits->y = 0;
>   traits->width =  1280;
>   traits->height = 480;
>   traits->windowDecoration = false;
>   traits->doubleBuffer = true;
>   traits->sharedContext = 0;
>
>   traits->screenNum = 0;
>
>
> //Create first context and add first View to the composite viewer
>  {
>     osg::ref_ptr<osg::GraphicsContext> gc =
> osg::GraphicsContext::createGraphicsContext(traits.get ());
>     gc->createNewContextID();
>
>     if(gc.valid())
>       {
>     osgViewer::View* view = new osgViewer::View;
>     viewer_->addView(view);
>
>     //std::cout << "gc->createNewContextID();" <<
gc->createNewContextID()
> << std::endl;
>     view->addEventHandler(keyboardHandler_.get());
>     view->setSceneData(getSceneRoot());
>     view->addEventHandler(MouseFly::Instance());
>     view->getCamera()->setViewport(new osg::Viewport(0,0,
> traits->width, traits->height));
>     view->getCamera()->setProjectionMatrixAsPerspective(45,
> traits->width/traits->height, 10, 1000000);
>     view->getCamera()->setGraphicsContext(gc.get());
>     view->getCamera()->setNearFarRatio( 0.5/30000.0);
>
>     osg::ref_ptr<UpdateTRAMCallback> TRAMupdateCallback =
> new UpdateTRAMCallback();
>     osg::ref_ptr<SubloadTRAMCallback> TRAMsubloadCallback =
> new SubloadTRAMCallback(gc.get());
>
>     osg::ref_ptr<osg::NodeCallback> nc = new
> osg::NodeCallback;
>     nc->addNestedCallback(TRAMsubloadCallback.get()); // once every
> graphical context
>     nc->addNestedCallback(TRAMupdateCallback.get());
>
>     view->getCamera()->setUpdateCallback(nc.get());
>
>       }
>   }
>
>   traits->x = 0;
>   traits->y = 800;
>
> //Create second context and add second View to the composite viewer
>    {
>     osg::ref_ptr<osg::GraphicsContext> gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>     gc->createNewContextID();
>     if(gc.valid())
>       {
>     osgViewer::View* view = new osgViewer::View;
>     viewer_->addView(view);
>
>     view->addEventHandler(keyboardHandler_.get());
>     view->setSceneData(getSceneRoot());
>     view->addEventHandler(MouseFly::Instance());
>     view->getCamera()->setViewport(new osg::Viewport(0,0,
> traits->width, traits->height));
>     view->getCamera()->setProjectionMatrixAsPerspective(45,
> traits->width/traits->height, 10, 1000000);
>     view->getCamera()->setGraphicsContext(gc.get());
>     view->getCamera()->setNearFarRatio( 0.5/30000.0);
>
>     osg::ref_ptr<UpdateTRAMCallback> TRAMupdateCallback =
> new UpdateTRAMCallback();
>     osg::ref_ptr<SubloadTRAMCallback> TRAMsubloadCallback =
> new SubloadTRAMCallback(gc.get());
>
>     osg::ref_ptr<osg::NodeCallback> nc = new
> osg::NodeCallback;
>     nc->addNestedCallback(TRAMsubloadCallback.get()); // once every
> graphical context
>     nc->addNestedCallback(TRAMupdateCallback.get());
>
>     view->getCamera()->setUpdateCallback(nc.get());
>       }
>   }
>
>   viewer_->realize();
>
>
>
> //Callback class methods
>   void SubloadTRAMCallback::operator()( osg::Node *node,
> osg::NodeVisitor *nv )
>   {
>     // gc_->makeCurrent(); //If this is called we get a desired
behaviour
> for the first context.
>     TextureController::Instance()->subload((gc_.valid() ?
> gc_->getState() : 0));
>     traverse(node,nv);
>
>   }
>
>
> When using a shared context instead of separate contexts the textures
are
> loaded correctly for both views.
> Still the call to gc_->makeCurrent() is required.
>
> For any other models with mapped textures everything works as expected
in
> both contexts. These models
> are below one group node and the terrains (with textures loaded by the
> callback) below another group node
> in the scene.
>
> Before we tried to use composite viewer we used producer and the
> scenehandler from producerOSG. We used corresponding
> callbacks for the prodcuer cameras. In this case the texures were drawn
in
> the same manner. When we used only one context
> the textures were drawn as expected, but with two contexts all terrain
> textures were drawn black. In producer we did not make
> a call to makeCurrent().
>
> OSG 2.0 / RHEL 5
>
> Any ideas?
>
> Thanks in advance!
>
> //Karl
> _______________________________________________
> osg-users mailing list
> osg-users@openscenegraph.net
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
>
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to