Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom shaderGenerator not being used by registry #2642

Open
gabr1gus opened this issue Oct 15, 2024 · 1 comment
Open

custom shaderGenerator not being used by registry #2642

gabr1gus opened this issue Oct 15, 2024 · 1 comment

Comments

@gabr1gus
Copy link

osgEarth Version: 3.7.0 build 163

I was trying to use a custom shader generator so I would be able to create a different behavior for textures and shaderGen as the default is in conflict with the way that is used in my models, however, after creating this custom ShaderGenerator and using osgEarth::Registry::instance()->setShaderGenerator() to set this custom shadergen, I confirmed that no custom code was being called, even if using osgEarth::Registry::shaderGenerator().run(model) however, the custom code was being called if using the object directly, not through the registry.

For what I could find, this problem seem to be caused by osgEarth's use of ShaderGeneratorProxy.

All instances of registry that could return a instance of shaderGenerator, return instead an instance of shaderGenerator proxy, and in its constructor
ShaderGeneratorProxy(const ShaderGenerator* temp) : _instance( new ShaderGenerator(*temp, osg::CopyOp::SHALLOW_COPY) ) { }
It forces the creation of a new ShaderGenerator in specific, overruling any custom shadergenerator that may be passed to registry.

In my code I've "fixed" it by adding a function to shader generator:
virtual ShaderGenerator* getCopy(const osg::CopyOp& copy) const { return new ShaderGenerator(*this, copy); }
re-implementing this function in my custom ShaderGenerator as:
virtual ShaderGenerator* getCopy(const osg::CopyOp& copy) const { return new CustomShaderGenerator(*this, copy); }
and altering shaderGeneratorProxy constructor to:
ShaderGeneratorProxy(const ShaderGenerator* temp) : _instance( temp->getCopy( osg::CopyOp::SHALLOW_COPY) ) { }

@gwaldron
Copy link
Owner

You are probably the first one is history to try this :) so I am not surprised there are issues.
Can you please submit a PR and we'll integrate it? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants