Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Robert Osfield
Hi Arelien,

On 24 October 2013 15:11, Aurelien Albert wrote:

> Will this works with shared contexts ?
>

Shared context will have the same ContextID's but they will have seperate
osg::State and osg::GraphicsContexts, as well as seperate CullVisitor etc.
 You can use an internal map for any of these.

That is if actually really need to place per view/context state into the
scene graph, if it's possible to keep this state attached the the viewer's
osg::Camera you don't have to worry about any of this as the buffering is
inherent in the way the viewer has a seperate Camera for each of the
individual parts of each View.

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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Aurelien Albert
Hi Robert,


> The CullVisitor::getRenderInfo() method could be used to access to the 
> osg::State object and hence ContextID that is relevant to the current cull 
> traversal.  


Will this works with shared contexts ?

Thank you!

Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56966#56966





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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Robert Osfield
On 24 October 2013 14:41, Glenn Waldron  wrote:

> Well, Paul did ask for per-context uniforms. But re-reading the original
> post, it's evident that the GC ID is not available during cull anyway ...
> so scratch that idea :)
>

The CullVisitor::getRenderInfo() method could be used to access to the
osg::State object and hence ContextID that is relevant to the current cull
traversal.

Alternatively you could do CullVisitor::getCurrentCamera() and get its'
GraphicsContext which has the State and the hence ContextID.

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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Glenn Waldron
Well, Paul did ask for per-context uniforms. But re-reading the original
post, it's evident that the GC ID is not available during cull anyway ...
so scratch that idea :)


Glenn Waldron / @glennwaldron


On Thu, Oct 24, 2013 at 9:14 AM, Aurelien Albert <
aurelien.alb...@alyotech.fr> wrote:

> Hi,
>
>
> > And then index that by the GC ID if it's available through the
> cv->getCurrentCamera().
>
>
> That's a bit different for my solution :
>
> - in my idea, you get "per-view" uniforms : even if multiple views runs
> with the same graphics context, you still have different uniforms
>
> - in your idea, you get "per-context" uniforms
>
> This can be really usefull too, but this is really different in some
> situations !
>
>
> Cheers,
> Aurelien
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=56963#56963
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Aurelien Albert
Hi,


> And then index that by the GC ID if it's available through the 
> cv->getCurrentCamera().


That's a bit different for my solution :

- in my idea, you get "per-view" uniforms : even if multiple views runs with 
the same graphics context, you still have different uniforms

- in your idea, you get "per-context" uniforms

This can be really usefull too, but this is really different in some situations 
!


Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56963#56963





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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Glenn Waldron
Another idea would be a subclass of Uniform (MultiplexingUniform?) that you
can program per context.

Or, a variation on Aurelien's approach would be to use:

  osg::buffered_object> multiUniform;

And then index that by the GC ID if it's available through the
cv->getCurrentCamera(). This would be nice in that it doesn't require a
mutex.

Note: I've not tried this nor verified that it's possible :)


Glenn Waldron / @glennwaldron


On Thu, Oct 24, 2013 at 4:26 AM, Aurelien Albert <
aurelien.alb...@alyotech.fr> wrote:

> Hi,
>
> At cull traversal, I do the following (this is pseudo-code!) :
>
>
> Code:
> cullTraversal(pCullVisitor)
> {
> // Get per-view-data
> perViewData = getOrCreatePerViewData(pCullVisitor);
>
> // Compute "dynamic" uniforms
> perViewData.pDynamicUniform_1->set(value);
> perViewData.pDynamicUniform_2->set(value);
> perViewData.pDynamicUniform_3->set(value);
>
> // Push per-view data
> pCullVisitor->pushStateSet(perViewData.pStateSet);
>
> // Traverse node
> traverse()
>
> // Pop per-view data
> pCullVisitor->popStateSet();
> }
>
>
>
> The "getOrCreatePerViewData" method returns a "PerViewData" struct :
>
>
> Code:
>
> struct PerViewData
> {
> osg::ref_ptr pStateSet;
> osg::ref_ptr pDynamicUniform_1;
> osg::ref_ptr pDynamicUniform_2;
> osg::ref_ptr pDynamicUniform_3;
>
> PerViewData()
> {
> pStateSet = new osg::StateSet();
>
> pDynamicUniform_1 = osg::Uniform();
> pDynamicUniform_2 = osg::Uniform();
> pDynamicUniform_3 = osg::Uniform();
>
> pStateSet->addUniform(pDynamicUniform_1);
> pStateSet->addUniform(pDynamicUniform_2);
> pStateSet->addUniform(pDynamicUniform_3);
>  }
> }
>
> PerViewData getOrCreatePerViewData(pCullVisitor)
> {
>  return m_perViewDataMap[pCullVisitor];
> }
>
>
>
>
> Just be carrefull to :
>
> - remove "PerViewData" instance from the "m_perViewDataMap" when the
> corresponding "pCullVisitor" instance is destroyed. (use an osg::Observer
> here)
> - add any necessary mutex in multithreading mode
>
>
>
> Cheers,
> Aurelien
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=56957#56957
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Aurelien Albert
Hi,

At cull traversal, I do the following (this is pseudo-code!) :


Code:
cullTraversal(pCullVisitor)
{
// Get per-view-data
perViewData = getOrCreatePerViewData(pCullVisitor);

// Compute "dynamic" uniforms
perViewData.pDynamicUniform_1->set(value);
perViewData.pDynamicUniform_2->set(value);
perViewData.pDynamicUniform_3->set(value);

// Push per-view data
pCullVisitor->pushStateSet(perViewData.pStateSet);

// Traverse node
traverse()

// Pop per-view data
pCullVisitor->popStateSet();
}



The "getOrCreatePerViewData" method returns a "PerViewData" struct :


Code:

struct PerViewData
{
osg::ref_ptr pStateSet;
osg::ref_ptr pDynamicUniform_1;
osg::ref_ptr pDynamicUniform_2;
osg::ref_ptr pDynamicUniform_3;

PerViewData()
{
pStateSet = new osg::StateSet();

pDynamicUniform_1 = osg::Uniform();
pDynamicUniform_2 = osg::Uniform();
pDynamicUniform_3 = osg::Uniform();

pStateSet->addUniform(pDynamicUniform_1);
pStateSet->addUniform(pDynamicUniform_2);
pStateSet->addUniform(pDynamicUniform_3);
 }
}

PerViewData getOrCreatePerViewData(pCullVisitor)
{
 return m_perViewDataMap[pCullVisitor];
}




Just be carrefull to :

- remove "PerViewData" instance from the "m_perViewDataMap" when the 
corresponding "pCullVisitor" instance is destroyed. (use an osg::Observer here)
- add any necessary mutex in multithreading mode



Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56957#56957





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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Gaëtan André
Hi,

I am also interesting in this topic.

How do you push 'dynamic" Uniforms at cull traversal ? Does it work well of
multi-threading is activated ?

Cheers,
Gaëtan


2013/10/24 Aurelien Albert 

> Hi,
>
>
> > If you have just a single uniform value per context then I'd simply
> place the Uniform on the each if the viiewer's osg::Camera's StateSet, such
> that each Camera assigned to each Context gets it's own state inherited
> down including the Uniform.
>
>
>
> > Some nodes have a cull callback. During the cull traversal, the callback
> identify the current view/context
> > and push the corresponding state set in the render graph, traverse the
> children and pop the state set.
>
>
> I have exactly the same needs, and I use the same solutions !
>
> - Some of my "per-view" uniforms are "static" : their value never change
> => those are added on viewer's camera's stateset
>
> - Some of my "per-view" uniforms are "dynamic" : their value change at
> each frame (based on camera position, user settings, a specific object
> position...)
> => those are pushed at cull traversal : the view is identified from the
> cullvisitor, specific value computation is done there and the uniform is
> pushed.
>
>
> Cheers,
> Aurelien
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=56954#56954
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Preferred method for per-context uniforms

2013-10-24 Thread Aurelien Albert
Hi,


> If you have just a single uniform value per context then I'd simply place the 
> Uniform on the each if the viiewer's osg::Camera's StateSet, such that each 
> Camera assigned to each Context gets it's own state inherited down including 
> the Uniform. 



> Some nodes have a cull callback. During the cull traversal, the callback 
> identify the current view/context 
> and push the corresponding state set in the render graph, traverse the 
> children and pop the state set. 


I have exactly the same needs, and I use the same solutions !

- Some of my "per-view" uniforms are "static" : their value never change
=> those are added on viewer's camera's stateset

- Some of my "per-view" uniforms are "dynamic" : their value change at each 
frame (based on camera position, user settings, a specific object position...)
=> those are pushed at cull traversal : the view is identified from the 
cullvisitor, specific value computation is done there and the uniform is pushed.


Cheers,
Aurelien

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=56954#56954





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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-23 Thread Lionel Lagarde

Hi,

We have to manage some similar problems. We have different shaders and 
different uniforms in the same

scene graph.

Some nodes have a cull callback. During the cull traversal, the callback 
identify the current view/context
and push the corresponding state set in the render graph, traverse the 
children and pop the state set.




On 23/10/2013 18:49, Robert Osfield wrote:

HI Paul,

If you have just a single uniform value per context then I'd simply 
place the Uniform on the each if the viiewer's osg::Camera's StateSet, 
such that each Camera assigned to each Context gets it's own state 
inherited down including the Uniform.


If you want to put a vector of Uniform in the scene graph, then It 
would probably be most robust to use a custom osg::Group node that 
manages the cull traversal where it push/pops the approach Unifiorm as 
well as any resizeGLObjectBuffers/releaseGLObjects etc.  The key to 
doing it thread safe is to make sure you have allocated the vector to 
the required number of contexts prior to traversal - this is what the 
resizeGLObjectsBuffers() helps with.


Robert.


On 23 October 2013 17:38, Paul Martz > wrote:


Hi all -- I've been inactive with OSG lately, but from time to
time get called back. Given my lack of recent experience, I would
appreciate your help with this issue.

I have a multicontext/multidisplay app that needs to compute a
uniform during cull, and it will have a different value for each
context/display. Computing the uniform value is straightforward,
but actually executing the uniform per-context during draw is
somewhat difficult.

I can't simply store the uniform in the Node's StateSet, for
example, because doing that during cull is not thread safe.

Ideally I would store the uniform in a vector indexed by context
ID, but I don't have a context ID during cull.

Would it be feasible to store the uniforms in a map indexed by
RenderStage address, then execute the uniforms from a Camera
per-draw callback?

Assuming I use a per-context or per-RenderStage container to store
the uniforms, how do I initially grow that container in a
thread-safe way during the first frame?

What are other people doing in this situation? Thanks in advance
for the advice.

-- 
Paul Martz

Skew Matrix Software LLC

___
osg-users mailing list
osg-users@lists.openscenegraph.org

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




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


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


Re: [osg-users] Preferred method for per-context uniforms

2013-10-23 Thread Robert Osfield
HI Paul,

If you have just a single uniform value per context then I'd simply place
the Uniform on the each if the viiewer's osg::Camera's StateSet, such that
each Camera assigned to each Context gets it's own state inherited down
including the Uniform.

If you want to put a vector of Uniform in the scene graph, then It would
probably be most robust to use a custom osg::Group node that manages the
cull traversal where it push/pops the approach Unifiorm as well as any
resizeGLObjectBuffers/releaseGLObjects etc.  The key to doing it thread
safe is to make sure you have allocated the vector to the required number
of contexts prior to traversal - this is what the resizeGLObjectsBuffers()
helps with.

Robert.


On 23 October 2013 17:38, Paul Martz  wrote:

> Hi all -- I've been inactive with OSG lately, but from time to time get
> called back. Given my lack of recent experience, I would appreciate your
> help with this issue.
>
> I have a multicontext/multidisplay app that needs to compute a uniform
> during cull, and it will have a different value for each context/display.
> Computing the uniform value is straightforward, but actually executing the
> uniform per-context during draw is somewhat difficult.
>
> I can't simply store the uniform in the Node's StateSet, for example,
> because doing that during cull is not thread safe.
>
> Ideally I would store the uniform in a vector indexed by context ID, but I
> don't have a context ID during cull.
>
> Would it be feasible to store the uniforms in a map indexed by RenderStage
> address, then execute the uniforms from a Camera per-draw callback?
>
> Assuming I use a per-context or per-RenderStage container to store the
> uniforms, how do I initially grow that container in a thread-safe way
> during the first frame?
>
> What are other people doing in this situation? Thanks in advance for the
> advice.
>
> --
> Paul Martz
> Skew Matrix Software LLC
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Preferred method for per-context uniforms

2013-10-23 Thread Paul Martz
Hi all -- I've been inactive with OSG lately, but from time to time get
called back. Given my lack of recent experience, I would appreciate your
help with this issue.

I have a multicontext/multidisplay app that needs to compute a uniform
during cull, and it will have a different value for each context/display.
Computing the uniform value is straightforward, but actually executing the
uniform per-context during draw is somewhat difficult.

I can't simply store the uniform in the Node's StateSet, for example,
because doing that during cull is not thread safe.

Ideally I would store the uniform in a vector indexed by context ID, but I
don't have a context ID during cull.

Would it be feasible to store the uniforms in a map indexed by RenderStage
address, then execute the uniforms from a Camera per-draw callback?

Assuming I use a per-context or per-RenderStage container to store the
uniforms, how do I initially grow that container in a thread-safe way
during the first frame?

What are other people doing in this situation? Thanks in advance for the
advice.

-- 
Paul Martz
Skew Matrix Software LLC
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org