Hi Terry,

As a side note, even though there's no OpenGL-blessed standard on shader filename extensions, I think we can safely rely on .vs, .gs, .vs, .vert, .geom, .frag to be the most widely-used.

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.

I don't think so either. But the problem with each shader type needing a different extension is separate from the problem of shaders needing a specific extension.

The problem with OSG's implementation of shaders here is that it wants you to set the shader type. How would a shader's type be inferred from something other than the extension (and other than user knowledge)? You'd have to parse the shader and decide knowing that a vertex shader has to write to gl_Position, a fragment shader has to write to gl_FragColor, and a geometry shader will probably have emitVertex() and emitPrimitive() calls... Messy. Given that, I prefer to name my shaders so it's clear.

One solution would be not to have to set a shader's type at all. In fact OpenGL doesn't require anything like a shader type, it just relies on the user providing whatever shaders it needs to. I don't even know what OSG uses the shader type for. We'd still want to use a common extension for shaders though, so OSG's extension-based loading mechanism would still work, as you mentioned. I've seen people using something like .glsl (osgPPU for example).

Removing the reliance on extension for all file types would be a major undertaking, and would be possible for binary files that could have a magic tag in their header (I think there's even a command on linux you can use to get a file's type from this) but for shaders which are text, again you'd need to parse the file and look for surefire signs that it's a GLSL shader... Messy IMHO.

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 think this is really a great addition, very useful. Thanks for all your hard work on this!

J-S
--
______________________________________________________
Jean-Sébastien Guay    [email protected]
                               http://www.cm-labs.com/
                    http://whitestar02.dyndns-web.com/
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to