Hi,
On Thu, 2010-03-18 at 11:09 +0100, Andreas Halm wrote:
> Hi,
>
> > What exactly is "the state switch" you are referring to, i.e. what state
> is > being switched from what to what?
>
> The scene consists only of about 20 items, all of them are using the same
> ChunkMaterial:
>
> Class Residue :public ResidueBase {
>
> [...]
>
> static void initialize(int w, int h);
> static void terminate();
> static void updateViewportSize(int w, int h);
>
> static ShaderProgramUnrecPtr m_pSpacefillVP;
> static ShaderProgramUnrecPtr m_pSpacefillFP;
> static ChunkMaterialUnrecPtr m_pSpacefillMaterial;
> static Vec4f m_Viewport;
>
> Action::ResultE draw(DrawEnv*);
>
> }
>
> The viewport variable and update routine are in there as the viewport
> dimension is a uniform variable in the shader, and this way I can update it
> only when the window size changes.
>
> What happens is that the shader gets activated and deactivated for every one
> of the 20 items, although I would have thought OpenSG would be smart enough
> to see that both materials are identical - but that can only work when the
> generated states are identical, and from a first look it seems they are not.
I'm looking into it, looks like there might be a wrong default setup for
the state sorter.
>
> > no, the finalize only retrieves what is already there, if it creates
> > something it should be cached (but nothing in there yet does this yet).
>
> Ok this means i should also keep a static state variable and call finalize
> only the first time?
no, for your case it should not really matter, for a simple Material as
ChunkMaterial finalize will just do a 'return this'; The state itself
should be internally cached so no need to do this again.
> > a) which chunks are set for the generated state ?
>
> There are no other chunks, only the shader. The code is identical to
> carstens, that's why I didn't post it.
> As a reference, this is the setup code:
>
> void Residue::initialize(int w, int h)
> {
> m_Viewport.setValues(0,0,w,h);
>
> ShaderProgramChunkUnrecPtr shader = ShaderProgramChunk::create();
> m_pSpacefillVP = OSG::ShaderProgram::createVertexShader();
> m_pSpacefillVP->readProgram(filename1);
> shader->addShader(m_pSpacefillVP);
>
> m_pSpacefillFP = OSG::ShaderProgram::createFragmentShader();
> m_pSpacefillFP->readProgram(filename2);
> shader->addShader(m_pSpacefillFP);
>
> m_pSpacefillVP->addUniformVariable("viewport",m_Viewport);
>
> m_pSpacefillMaterial = ChunkMaterial::create();
> m_pSpacefillMaterial->addChunk(shader);
> }
ok.
> > b) are there overrides except for lights ?
>
> There is no StateOverride if you mean that, I do change OpenGL state but
> encapsulated by glPushAttrib/glPopAttrib.
> I just started converting a pure OpenGL drawing routine to use the OpenSG
> shader stuff, doing one step at a time, and have not looked at the
> StateOverride stuff yet.
ok.
> > c) are these duplicated state switches for elements with the
> > same material (same object) or different material which just share
> > some chunks ?
>
> As mentioned above, all the objects in the scene use the same material, but
> it is switched every time. That's why I get the error message like 20 times
> per frame not only once.
>
ok, I'm about to track down why the state sorter doesn't sort as
expected.
For the error message could you just break into the
ShaderProgramChunk::deactivate and send me the callstack,
your OSGConfigured.h looks ok. As you only get the warning
for deactivate something is really strange.
kind regards
gerrit
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users