[osg-users] Exporting OpenFlight Models

Daniel Emminizer, Code 5773 dan.emminizer at nrl.navy.mil
Wed Jun 27 10:01:18 PDT 2018


Hi Robert,

Tl;dr: I think I found a bug in OpenFlight's FltExportVisitor::isTextured() when FFP is disabled.  This email explains PR 568 more thoroughly.



I am having problems saving out OpenFlight models and was hoping someone could point out what I'm doing wrong.  I think I might have identified a bug but would like another set of eyes.

I have an open source FLT that is textured that I'm trying to load, make a minor edit to, and save out.  My code is simple:

    osg::ref_ptr<osgDB::Options> opts = new osgDB::Options;
    opts->setOptionString("keepExternalReferences");
    osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(argv[1], opts.get());

    opts = new osgDB::Options;
    bool succeeded = osgDB::writeNodeFile(*node, argv[2], opts.get());

It writes out the geometry, but never writes out the textures.  I've spent the last couple of hours tracking down why and I think I understand.  I'm using GL3 / GLCORE mode in OSG 3.6.2-rc2.  I think it's important to note this because I believe the bug is related to a FFP change with StateSet.

The OpenFlight loader reads the image and the textures just fine, and displays them.  TexturePalette::readTexture() correctly calls setTextureAttributeAndModes() with a valid texture.  This ends up calling osg::Texture::getModeUsage(), which is responsible for turning on GL_TEXTURE_2D.

Later on, the FltExportVisitor only respects a texture if GL_TEXTURE_2D is enabled, via FltExportVisitor::isTextured().

But when OSG_GL_FIXED_FUNCTION_AVAILABLE is disabled due to GLCORE profile, osg::Texture::getModeUsage() is not defined, so setTextureAttributeandModes() never sets the mode on GL_TEXTURE_2D.


I think the fix is to update isTextured() to check for presence of a texture when OSG_GL_FIXED_FUNCTION_AVAILABLE is not set.  Does this seem reasonable?

I have put up a PR to inspect at: https://github.com/openscenegraph/OpenSceneGraph/pull/568

I do have workarounds on my side, so this isn't super critical.  But I think it will impact anyone who uses OSG with GLCORE mode who is trying to export FLT files.

Thanks,

 - Dan



More information about the osg-users mailing list