diff --git a/examples/osgshaderpipeline/osgshaderpipeline.cpp b/examples/osgshaderpipeline/osgshaderpipeline.cpp index 1849c84a9..28ade2f52 100644 --- a/examples/osgshaderpipeline/osgshaderpipeline.cpp +++ b/examples/osgshaderpipeline/osgshaderpipeline.cpp @@ -19,6 +19,40 @@ #include +bool readShaderArguments(osg::ArgumentParser& arguments, const std::string& option, osg::Program* program, const std::string& fallbackShaderFilename) +{ + bool shaderAssigned = false; + std::string shaderFilename; + while(arguments.read(option, shaderFilename)) + { + osg::ref_ptr shader = osgDB::readRefShaderFile(shaderFilename); + if (shader) + { + shaderAssigned = true; + program->addShader(shader); + } + else + { + OSG_NOTICE<<"Unable to load shader file : "< shader = osgDB::readRefShaderFile(fallbackShaderFilename); + if (shader) + { + shaderAssigned = true; + program->addShader(shader); + return true; + } + else + { + OSG_NOTICE<<"Unable to load shader file : "< program = new osg::Program; - bool vertexShadersAssigned = false; - std::string vertexShaderFilename; - while(arguments.read("--vert", vertexShaderFilename)) + if (!readShaderArguments(arguments, "--vert", program, "shaders/shaderpipeline.vert")) { - osg::ref_ptr vertexShader = osgDB::readRefShaderFile(vertexShaderFilename); - if (vertexShader) - { - vertexShadersAssigned = true; - program->addShader(vertexShader); - } - else - { - OSG_NOTICE<<"Unable to load vertex shader file : "< vertexShader = osgDB::readRefShaderFile(vertexShaderFilename); - if (vertexShader) - { - vertexShadersAssigned = true; - program->addShader(vertexShader); - } - else - { - OSG_NOTICE<<"Unable to load vertex shader file : "< fragmentShader = osgDB::readRefShaderFile(fragmentShaderFilename); - if (fragmentShader) - { - fragmentShadersAssigned = true; - program->addShader(fragmentShader); - } - else - { - OSG_NOTICE<<"Unable to load fragment shader file : "< fragmentShader = osgDB::readRefShaderFile(fragmentShaderFilename); - if (fragmentShader) - { - fragmentShadersAssigned = true; - program->addShader(fragmentShader); - } - else - { - OSG_NOTICE<<"Unable to load fragment shader file : "<