Re: [osg-users] Fwd: Fwd: Fwd: shader implementation - newbie

2009-04-28 Thread Robert Osfield
On Tue, Apr 28, 2009 at 10:19 AM, ami guru dosto.wa...@gmail.com wrote:
 Hello Robert,

 I have already implemented the scenario that i am looking for in OpenGL by
 setting the glUseProgram(0) to glUseProgram(whichShader).

 And i wanted to implement the same scenario in OSG. None of the example that
 accompany the repository have implemented
 the scenario that i m looking for except a discussion in the mailing list.

The OSG automatically does th glUseProgram(0) when you attach a blank
osg::Program to a subgraph's StateSet.

The OSG automatically does the  glUseProgram(programID)  when you
attach a osg::Program with shaders.

You can share shaders between multiple osg::Program, this means that
you'll only pay for compilation once for each shared shader, and then
once for linking for each osg::Program.   It's a efficient as you can
do it trying to manually do things yourself, so just use the standard
OSG osg::Program/osg::Shader functionality.  Don't try to be clever or
over complicate things.

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


[osg-users] Fwd: Fwd: Fwd: shader implementation - newbie

2009-04-28 Thread ami guru
Hello Robert,

I have already implemented the scenario that i am looking for in OpenGL by
setting the glUseProgram(0) to glUseProgram(whichShader).

And i wanted to implement the same scenario in OSG. None of the example that
accompany the repository have implemented
the scenario that i m looking for except a discussion in the mailing list.

One of it was forwarded to you in the previous mail since among many other
suggested methods yours one to be the better one considering the fact that
you described the cons of the others.



Regards
Sajjad

-- Forwarded message --
From: Robert Osfield robert.osfi...@gmail.com
Date: Tue, Apr 28, 2009 at 10:34 AM
Subject: Re: [osg-users] Fwd: Fwd: shader implementation - newbie
To: OpenSceneGraph Users osg-users@lists.openscenegraph.org


Hi Sajjad,

This is almost certainly more complicated than you need.  As I said I
not have to time to nurse maid you through learning about shaders.
The OSG has a number of places where it use shaders in its
implementation, and number of examples as well.

Robert.

On Tue, Apr 28, 2009 at 8:32 AM, ami guru dosto.wa...@gmail.com wrote:
 Hello Robert,

 After going through  the archives i have found that it has already
discussed
 the issue that is not present yet within the API.

 Something like SwitchStateSet.

 But you did have pave a way to get that done. I am not sure if anyone has
 done that and updated the repository.Your recommendation is as follows:


'

 Re: [osg-users] Rendering the scene multiple times with different shaders.

 Robert Osfield
 Thu, 22 May 2008 08:10:39 -0700

 Hi Stephane,

 On Thu, May 22, 2008 at 4:02 PM, Stephane Lamoliatte
 [EMAIL PROTECTED] wrote:
 Robert, don't you think this feature could be done by some kind of custom
 osgFX::Effect node ?


 You could probably write a custom node that overrides the cull
 callback and post processes/rebuild the StateGraph it's generated.  I
 don't think this is an example of a osgFX::Effect though, such as
 class might belong in osgFX though.


 It might still be most efficient to tailor CullVisitor to do the
 remapping of the StateSet, such as by tweaking the pushStateSet
 method, that currently looks like:

 inline void pushStateSet(const osg::StateSet* ss)

 {
 _currentStateGraph = _currentStateGraph-find_or_insert(ss);
 if (_numberOfEncloseOverrideRenderBinDetails==0 
 ss-useRenderBinDetails()  !ss-getBinName().empty())

 {
 _currentRenderBin =
 _currentRenderBin-find_or_insert(ss-getBinNumber(),ss-getBinName());
 }
 if
 (ss-getRenderBinMode()==osg::StateSet::OVERRIDE_RENDERBIN_DETAILS)

 {
 ++_numberOfEncloseOverrideRenderBinDetails;
 }
 }

 One could possible add a check against an internal map of StateSet
 inside this function.  The only draw back to adding this into

 CullVisitor is that it'd add an extra bool check to see if one needed
 to do the look up.  i.e.


 inline void pushStateSet(const osg::StateSet* ss)
 {
 if (_doStateSetSubstituion)

 {
  StateSetMap::iterator itr =
 _statesetSubsitutionMap.find(ss);
  if (itr!=  _statesetSubsitutionMap.end()) ss =
 itr-second.get();
 }
 _currentStateGraph = _currentStateGraph-find_or_insert(ss);

 if (_numberOfEncloseOverrideRenderBinDetails==0 
 ss-useRenderBinDetails()  !ss-getBinName().empty())
 {
 _currentRenderBin =
 _currentRenderBin-find_or_insert(ss-getBinNumber(),ss-getBinName());

 }
 if
 (ss-getRenderBinMode()==osg::StateSet::OVERRIDE_RENDERBIN_DETAILS)
 {
 ++_numberOfEncloseOverrideRenderBinDetails;
 }
 }


 The custom node would then populate the push and pop
 _statesetSubsitutionMap settings in its cull traversal.

 Feel free to experiment with such an implementation and it works out
 send it in to osg-submissions for consideration as

 part of the core OSG.

 Robert.




***''

 If i have understood that correctly you have suggested to to tailor the
 CullVisitor which means to make a subclass of CullVisitor like
 MyCullVisitor and override the functions that you have specified. Now i
want
 to get that implemented. And i need your suggestion on the items i have to
 cover more to understand and implement the scenario.

 First of all is there any example in OSG that implemented the CullVisitor
 concept. When i have have impelemented it how do i use that from the my
 createSceneGraph() function when i have the very same model that will be
 loaded with different shaders with user interaction.


 Regards
 Sajjad

 -- Forwarded message --
 From: Robert Osfield