Brad,

I'll look over your implementation. Thanks for sharing this...:)

-Shayne

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of
Christiansen, Brad
Sent: Thursday, February 11, 2010 2:35 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] 2D rendering priority...

Hi,

We used this approach for rendering a 2D scene using the painters
algorithm (i.e. render back to front according to our own order
definition). I have included the most relevent code snippets. No
comments on their quality please ;  ). 

1) Added a 'user data' object (which contains the rendering priority) to
each of our leaves. 

2) As required, we run a 'RenderPriorityVisitor' over the scene to set
the correct priorities into our user data objects.

3) Create a custom render bin and setup your 2D graph to use it:
e.g. root2DstateSet->setRenderBinDetails(0, RenderBin2D::BIN_NAME,
osg::StateSet::OVERRIDE_RENDERBIN_DETAILS); 

We use OVERRIDE_RENDERBIN_DETAILS as some of the objects bellow the root
of our 2D scene are also rendered in 3D, in which case they may already
have different bin details set (e.g transparent bin).

The key bit of the custom bin is setting the sort callback. This
callback sorts the leaves based on the priority set in the 'user data'
object.

Hopefully this all makes sence. I implemented this code ~7 years ago so
there may be a neater way to do this now, but it is still working well
against the latest OSG releases. 

Cheers,

Brad

Code snippets:

---- Custom Render Bin
/** Automatically registers the bin prototype. */
static osgUtil::RegisterRenderBinProxy
s_registerBin(RenderBin2D::BIN_NAME,new RenderBin2D());

RenderBin2D() { //extends RenderBin
  setSortCallback(new SortCallback2D());      
}    

---- SortCallback2D

void SortCallback2D::sortImplementation(osgUtil::RenderBin* renderBin) {
  renderBin->copyLeavesFromStateGraphListToRenderLeafList();
 
std::sort(renderBin->getRenderLeafList().begin(),renderBin->getRenderLea
fList().end(),RenderPrioritySortFunctor());      
}

--- RenderPrioritySortFunctor
int RenderPrioritySortFunctor::getRenderOrder(const osgUtil::RenderLeaf*
leaf) const {    
    const osg::Referenced* ud = leaf->getDrawable()->getUserData();    
    if(ud) { 
      const DrawableData* data = dynamic_cast<const DrawableData*>(ud);
      return data->getRenderOrder();
    }
    return 0;
}

bool RenderPrioritySortFunctor::operator() (const osg::Node* lhs,const
osg::Node* rhs) const {
    int leftOrder = getRenderOrder(lhs);
    int rightOrder = getRenderOrder(rhs);

    if(m_sortMode == SORT_ASCENDING) {
      return leftOrder < rightOrder;
    } else { //sort descending
      return leftOrder > rightOrder;
    }
}



-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of
Tueller,Shayne R Civ USAF AFMC 519 SMXS/MXDEC
Sent: Wednesday, 10 February 2010 11:49 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] 2D rendering priority...

Brad,

Please elaborate...:)

I have not played with RenderBin so any code snippets/examples would be
appreciated.

Thanks,
-Shayne

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of
Christiansen, Brad
Sent: Wednesday, February 10, 2010 12:06 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] 2D rendering priority...

Hi,

I use a RenderBin / NodeMask combination to exactly this and it works
well. I can elaborate more if you wish.

Cheers,
Brad

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of
Tueller,Shayne R Civ USAF AFMC 519 SMXS/MXDEC
Sent: Wednesday, 10 February 2010 8:18 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] 2D rendering priority...

Paul,

Thanks for the reply. We can have up to 57 levels of priority where each
level could have 100-200 simple geometries (i.e. circles, squares,
simple line primitives, etc.). It's very rare that all levels are on
simultaneously but those that are on, need to stack in priority relative
to every other level/group that is on. Realistically, we'll have around
10-15 levels being rendered at the same time. Hopefully this
quantity/complexity won't present a problem.

I really didn't have any reservations per se about using the RenderBin
and NodeMask mechanisms. I suspected that I needed to use them but I
wanted to ping the group just to make sure I was on the right track.
When using OSG, it's always good to have a reality check before
proceeding...:)

-Shayne

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Paul
Martz
Sent: Tuesday, February 09, 2010 4:07 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] 2D rendering priority...

Tueller, Shayne R Civ USAF AFMC 519 SMXS/MXDEC wrote:
> I have a need to render a bunch of 2D geometry groups that have 
> different priorities for display (one group rendered on top of the 
> other according to their priority). I also need to have the ability to

> turn the rendering off and on for some of the groups while maintaining

> rendering priority.

How many different groups do you have, and what is the total data size
of all the groups?

> I wanted some input or ideas on what might be the best way to handle 
> this in OSG. So far I've looked at the RenderBin mechanism for 
> possible priority rendering and the setNodeMask for turning rendering
on and off.
> I'm not sure this is the most elegant way to accomplish what I need to
do.

In addition to setting the RenderBin, you'd need to disable depth test
to get the painter's algorithm to work properly, of course.

The RenderBin and NodeMask mechanisms seem like they're designed for
just the tasks you describe. Can you elaborate on why you have
reservations about their suitability?
    -Paul


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g



DISCLAIMER:-------------------------------------------------------------
----
----------
This e-mail transmission and any documents, files and previous e-mail
messages attached to it are private and confidential. They may contain
proprietary or copyright material or information that is subject to
legal professional privilege.
They are for
the use of the intended recipient only.  Any unauthorised viewing, use,
disclosure, copying, alteration, storage or distribution of, or reliance
on, this message is strictly prohibited. No part may be reproduced,
adapted or transmitted without the written permission of the owner. If
you have received this transmission in error, or are not an authorised
recipient, please immediately notify the sender by return email, delete
this message and all copies from your e-mail system, and destroy any
printed copies. Receipt by anyone other than the intended recipient
should not be deemed a waiver of any privilege or protection. Thales
Australia does not warrant or represent that this e-mail or any
documents, files and previous e-mail messages attached are error or
virus free.
------------------------------------------------------------------------
----
----------

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g



DISCLAIMER:-----------------------------------------------------------------
----------
This e-mail transmission and any documents, files and previous e-mail
messages
attached to it are private and confidential. They may contain proprietary or
copyright
material or information that is subject to legal professional privilege.
They are for
the use of the intended recipient only.  Any unauthorised viewing, use,
disclosure,
copying, alteration, storage or distribution of, or reliance on, this
message is
strictly prohibited. No part may be reproduced, adapted or transmitted
without the
written permission of the owner. If you have received this transmission in
error, or
are not an authorised recipient, please immediately notify the sender by
return email,
delete this message and all copies from your e-mail system, and destroy any
printed
copies. Receipt by anyone other than the intended recipient should not be
deemed a
waiver of any privilege or protection. Thales Australia does not warrant or
represent
that this e-mail or any documents, files and previous e-mail messages
attached are
error or virus free.
----------------------------------------------------------------------------
----------

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to