Figured it out.  My override of Shader::loadShaderSourceFromFile() is
no longer necessary.  First I had to realize that OSG's plugin
infrastructure really revolves around files being sent to the
appropriate loaders and functions based on their extension.  This
includes shaders, which is a bit odd because there is no accepted
standard for shader filename extensions.  The glsl plugin is hardwired
with the extensions .vert and .frag.  So the first thing I did was
change all my shader file extensions from .vs and .fs to .vert and
.frag.  This would allow me to exploit the glsl plugin instead of
relying on Shader::loadShaderSourceFromFile(), which has no hope of
finding a file in an archive.

Next I modifed Shader_readLocalData() in
src/osgWrappers/deprecated-dotosg/osg/Shader.cpp.  Instead of trying
to simply call Shader::loadShaderSourceFromFile() it now first calls
osgDB::readShaderFile().  This will eventually dispatch any file with
a .vert or .frag extension to the glsl plugin.

Unfortunately, when loading shaders from an archive it will send them
to the glsl plugin's readObject() function, which was not implemented.
 I implemented it so that would it simply pass through to readShader()
instead.

It would be nice to have a solution that is flexible enough to load
shaders that have any extension, but I don't know if this is possible
with OSG's heavy reliance on filename extensions.

Note that if you want to try all this out, put your archive in your
OSG_FILE_PATH environment variable, and then try to load a model from
that archive.  You will also need to load the zip plugin in your code
like this:

osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("zip"));

I have just been adding this to osgviewer for testing.  I'm not sure
if it's appropriate to try to make the zip plugin load automatically
if you put a .zip archive in you OSG_FILE_PATH.  Thoughts?

Also note that these changes fix an existing deficiency.  Say you have
archive.zip which contains model.osg, texture.png, shader.vert, and
shader.frag.  The model references the texture and shaders.  If you
load it up with "osgviewer archive.zip" you will load the model and
the texture, but the shaders will not be found.  The zip loader caches
archive.zip when you load it, but the cached archives are never
checked when you try to load the shaders.  The additions I have made
fix this.

I have attached all my modified files, including the ones I submitted
previously.
--
Terry Welsh
mogumbo 'at' gmail.com
www.reallyslick.com



On Mon, Dec 5, 2011 at 8:15 PM, Terry Welsh <[email protected]> wrote:
> Okay, I finally got back to working on this a bit.  The good news is
> that the code I submitted works fine in Windows.  The bad news is that
> my loadShaderSourceFromFile() override function will not work in
> Windows.  Apparently, dlls don't let you overload functions the same
> way you can in Linux .so files :(
>
> And so I'm back to trying to figure out how to fix up the .osg loader,
> which should also solve my shader loading problem.  I've dug into the
> code pretty deep and it looks like someone may have had a plan to get
> rid of all the deprecated code in the .osg loader, but I have no idea
> what that plan is.  Is there a plan for rewriting the .osg loader
> without deprecated code that I just haven't figured out?  And, if so,
> has most of the code been written and just not assembled correctly in
> ReaderWriterOSG.cpp?  Or is there plenty of heavy lifting left to do?
> I'll be happy to work on this more, but I am unable to figure out
> current intentions just by looking at the code.
>
> For a little bit there I was hoping I could just rewrite
> DeprecatedDotOsgWrapperManager::readShader() but when I step through
> the loading process, that function never even gets called.  Instead,
> DeprecatedDotOsgWrapperManager::readObject() calls
> Shader_readLocalData(), which calls
> Shader::loadShaderSourceFromFile().
> --
> Terry Welsh
> mogumbo 'at' gmail.com
> www.reallyslick.com
>
>
>>
>> Message: 2
>> Date: Fri, 14 Oct 2011 08:40:59 +0100
>> From: Robert Osfield <[email protected]>
>> To: OpenSceneGraph Submissions
>>        <[email protected]>
>> Subject: Re: [osg-submissions] tight integration of virtual file
>>        system
>> Message-ID:
>>        <cafn7y+wqznesunvmcja4chw_hyszanmrfugl1gpkdntsr5e...@mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi Terry,
>>
>> I'm afraid I've been rushed off my feet with client work so haven't
>> had a chance to review your submission.  As a general comment we
>> should work on migrating from the Shader::loadShadeSourceFromFile to
>> the osgDB::readShadeFile().
>>
>> Others are welcome to dive in and test out your changes and give you
>> feedback.  I'll be working to clear my backlog and once I've got a
>> window I'll dive back into reviewing submissions.
>>
>> Thanks for you patience,
>> Robert.
>>

Attachment: vfs.tar.gz
Description: GNU Zip compressed data

_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to