From d42a8fd2699598f026a1b4409235ced16e41e298 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 May 2006 13:22:59 +0000 Subject: [PATCH] From Paul Martz, "This change is based on current CVS. (Note both Brede and I have submitted changes to this plugin that aren't in current CVS yet -- this change is based on current CVS, not our changed files.) This changes how shader palette records are parsed to support GLSL per the OpenFlight 16.1 spec. Existing functionality for 16.0 files is preserved. The change to Document.h simply adds an enum for VERSION_16_1." --- src/osgPlugins/OpenFlight/Document.h | 7 ++- src/osgPlugins/OpenFlight/PaletteRecords.cpp | 59 +++++++++++++++----- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/osgPlugins/OpenFlight/Document.h b/src/osgPlugins/OpenFlight/Document.h index 386d1cdd4..ba822d7dd 100644 --- a/src/osgPlugins/OpenFlight/Document.h +++ b/src/osgPlugins/OpenFlight/Document.h @@ -38,7 +38,8 @@ enum Version VERSION_15_6 = 1560, VERSION_15_7 = 1570, VERSION_15_8 = 1580, - VERSION_16_0 = 1600 + VERSION_16_0 = 1600, + VERSION_16_1 = 1610 }; enum CoordUnits { @@ -75,8 +76,8 @@ class Document { public: - Document(); - virtual ~Document(); + Document(); + virtual ~Document(); void setOptions(const osgDB::ReaderWriter::Options* options) { _options = options; } const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); } diff --git a/src/osgPlugins/OpenFlight/PaletteRecords.cpp b/src/osgPlugins/OpenFlight/PaletteRecords.cpp index 434104320..0d67f81eb 100644 --- a/src/osgPlugins/OpenFlight/PaletteRecords.cpp +++ b/src/osgPlugins/OpenFlight/PaletteRecords.cpp @@ -618,28 +618,61 @@ protected: int32 index = in.readInt32(); int32 type = in.readInt32(); std::string name = in.readString(1024); - std::string vertexProgramFilename = in.readString(1024); - std::string fragmentProgramFilename = in.readString(1024); + + if (type == CG) + { + // CG support is currently not implemented. Just parse. + std::string vertexProgramFilename = in.readString(1024); + std::string fragmentProgramFilename = in.readString(1024); + int32 vertexProgramProfile = in.readInt32(); + int32 fragmentProgramProfile = in.readInt32(); + std::string vertexProgramEntry = in.readString(256); + std::string fragmentProgramEntry = in.readString(256); + } if (type == GLSL) { + int32 vertexProgramFileCount( 1 ); + int32 fragmentProgramFileCount( 1 ); + + if (document.version() > VERSION_16_1) + { + // In 16.1, possibly multiple filenames for each vertex and fragment program. + vertexProgramFileCount = in.readInt32(); + fragmentProgramFileCount = in.readInt32(); + } + // else 16.0 + // Technically, 16.0 didn't support GLSL, but this plugin + // supports it with a single vertex shader filename and a + // single fragment shader filename. + osg::Program* program = new osg::Program; program->setName(name); - std::string vertexProgramFilePath = osgDB::findDataFile(vertexProgramFilename); - if (!vertexProgramFilePath.empty()) + int idx; + for( idx=0; idxaddShader( vertexShader ); - } + std::string vertexProgramFilename = in.readString(1024); - std::string fragmentProgramFilePath = osgDB::findDataFile(fragmentProgramFilename); - if (!fragmentProgramFilePath.empty()) + std::string vertexProgramFilePath = osgDB::findDataFile(vertexProgramFilename); + if (!vertexProgramFilePath.empty()) + { + osg::Shader* vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexProgramFilePath); + if (vertexShader) + program->addShader( vertexShader ); + } + } + for( idx=0; idxaddShader( fragmentShader ); + std::string fragmentProgramFilename = in.readString(1024); + + std::string fragmentProgramFilePath = osgDB::findDataFile(fragmentProgramFilename); + if (!fragmentProgramFilePath.empty()) + { + osg::Shader* fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath); + if (fragmentShader) + program->addShader( fragmentShader ); + } } ShaderPool* shaderPool = document.getOrCreateShaderPool();