X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2FEffect.cxx;h=c934815760ced8359c0c3678fde2e9b865544deb;hb=430e72b42404cd07685de13c767a9ca443ad1f49;hp=1a52c65948e97363f3397591c50892df05dfe598;hpb=a543560f7db48e5c91d7551f93ba9740e1a7061f;p=simgear.git diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index 1a52c659..c9348157 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -67,13 +67,14 @@ #include #include -#include +#include #include +#include #include #include #include #include - +#include namespace simgear @@ -90,7 +91,7 @@ Effect::Effect() } Effect::Effect(const Effect& rhs, const CopyOp& copyop) - : root(rhs.root), parametersProp(rhs.parametersProp), _cache(0), + : osg::Object(rhs,copyop), root(rhs.root), parametersProp(rhs.parametersProp), _cache(0), _isRealized(rhs._isRealized) { typedef vector > TechniqueList; @@ -154,7 +155,7 @@ Effect::~Effect() } void buildPass(Effect* effect, Technique* tniq, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { Pass* pass = new Pass; tniq->passes.push_back(pass); @@ -203,12 +204,12 @@ osg::Vec4f getColor(const SGPropertyNode* prop) struct LightingBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); }; void LightingBuilder::buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -222,7 +223,7 @@ InstallAttributeBuilder installLighting("lighting"); struct ShadeModelBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -244,7 +245,7 @@ InstallAttributeBuilder installShadeModel("shade-model"); struct CullFaceBuilder : PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) { @@ -272,7 +273,7 @@ InstallAttributeBuilder installCullFace("cull-face"); struct ColorMaskBuilder : PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -299,7 +300,7 @@ EffectPropertyMap renderingHints(renderingHintInit); struct HintBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -315,7 +316,7 @@ InstallAttributeBuilder installHint("rendering-hint"); struct RenderBinBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -342,7 +343,7 @@ InstallAttributeBuilder installRenderBin("render-bin"); struct MaterialBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); }; EffectNameValue colorModeInit[] = @@ -358,7 +359,7 @@ EffectPropertyMap colorModes(colorModeInit); void MaterialBuilder::buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -428,7 +429,7 @@ EffectPropertyMap blendFuncModes(blendFuncModesInit); struct BlendBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -541,7 +542,7 @@ EffectPropertyMap stencilOperation(stencilOperationInit); struct StencilBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -619,7 +620,7 @@ alphaComparison(alphaComparisonInit); struct AlphaTestBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -670,9 +671,9 @@ InstallAttributeBuilder installAlphaTest("alpha-test"); InstallAttributeBuilder textureUnitBuilder("texture-unit"); // Shader key, used both for shaders with relative and absolute names -typedef pair ShaderKey; +typedef pair ShaderKey; -inline ShaderKey makeShaderKey(SGPropertyNode_ptr& ptr, Shader::Type shaderType) +inline ShaderKey makeShaderKey(SGPropertyNode_ptr& ptr, int shaderType) { return ShaderKey(ptr->getStringValue(), shaderType); } @@ -736,7 +737,7 @@ void reload_shaders() struct ShaderProgramBuilder : PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options); + const SGReaderWriterOptions* options); }; @@ -763,7 +764,7 @@ geometryOutputType(geometryOutputTypeInit); void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* + const SGReaderWriterOptions* options) { using namespace boost; @@ -814,7 +815,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, BOOST_FOREACH(const ShaderKey& shaderKey, prgKey.shaders) { const string& shaderName = shaderKey.first; - Shader::Type stype = shaderKey.second; + Shader::Type stype = (Shader::Type)shaderKey.second; string fileName = SGModelLib::findDataFile(shaderName, options); if (fileName.empty()) throw BuilderException(string("couldn't find shader ") + @@ -832,12 +833,13 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, BOOST_FOREACH(const ShaderKey& skey, resolvedKey.shaders) { const string& fileName = skey.first; - Shader::Type stype = skey.second; + Shader::Type stype = (Shader::Type)skey.second; ShaderMap::iterator sitr = shaderMap.find(skey); if (sitr != shaderMap.end()) { program->addShader(sitr->second.get()); } else { ref_ptr shader = new Shader(stype); + shader->setName(fileName); if (shader->loadShaderSourceFromFile(fileName)) { program->addShader(shader.get()); shaderMap.insert(ShaderMap::value_type(skey, shader)); @@ -899,7 +901,7 @@ ref_ptr colorMode[3]; struct UniformBuilder :public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!texture0.valid()) { texture0 = new Uniform(Uniform::SAMPLER_2D, "texture"); @@ -915,6 +917,7 @@ struct UniformBuilder :public PassAttributeBuilder return; const SGPropertyNode* nameProp = prop->getChild("name"); const SGPropertyNode* typeProp = prop->getChild("type"); + const SGPropertyNode* positionedProp = prop->getChild("positioned"); const SGPropertyNode* valProp = prop->getChild("value"); string name; Uniform::Type uniformType = Uniform::FLOAT; @@ -959,6 +962,11 @@ struct UniformBuilder :public PassAttributeBuilder uniform->setName(name); uniform->setType(uniformType); switch (uniformType) { + case Uniform::BOOL: + initFromParameters(effect, valProp, uniform.get(), + static_cast(&Uniform::set), + options); + break; case Uniform::FLOAT: initFromParameters(effect, valProp, uniform.get(), static_cast(&Uniform::set), @@ -991,8 +999,8 @@ struct UniformBuilder :public PassAttributeBuilder // optimize common uniforms if (uniformType == Uniform::SAMPLER_2D || uniformType == Uniform::INT) { - int val; - uniform->get(val); + int val = 0; + uniform->get(val); // 'val' remains unchanged in case of error (Uniform is a non-scalar) if (uniformType == Uniform::SAMPLER_2D && val == 0 && name == "texture") { uniform = texture0; @@ -1002,6 +1010,11 @@ struct UniformBuilder :public PassAttributeBuilder } } pass->addUniform(uniform.get()); + if (positionedProp && positionedProp->getBoolValue() && uniformType == Uniform::FLOAT_VEC4) { + osg::Vec4 offset; + uniform->get(offset); + pass->addPositionedUniform( name, offset ); + } } }; @@ -1013,7 +1026,7 @@ InstallAttributeBuilder installUniform("uniform"); struct NameBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { // name can't use string name = prop->getStringValue(); @@ -1035,7 +1048,7 @@ EffectPropertyMap polygonModeModes(polygonModeModesInit); struct PolygonModeBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -1063,7 +1076,7 @@ InstallAttributeBuilder installPolygonMode("polygon-mode"); struct PolygonOffsetBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -1091,7 +1104,7 @@ InstallAttributeBuilder installPolygonOffset("polygon-offs struct VertexProgramTwoSideBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -1108,7 +1121,7 @@ installTwoSide("vertex-program-two-side"); struct VertexProgramPointSizeBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop); if (!realProp) @@ -1138,7 +1151,7 @@ EffectPropertyMap depthFunction(depthFunctionInit); struct DepthBuilder : public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { if (!isAttributeActive(effect, prop)) return; @@ -1157,19 +1170,22 @@ struct DepthBuilder : public PassAttributeBuilder const SGPropertyNode* pfar = getEffectPropertyChild(effect, prop, "far"); if (pfar) - depth->setZFar(pnear->getValue()); + depth->setZFar(pfar->getValue()); const SGPropertyNode* pmask = getEffectPropertyChild(effect, prop, "write-mask"); if (pmask) depth->setWriteMask(pmask->getValue()); - pass->setAttribute(depth.get()); + const SGPropertyNode* penabled + = getEffectPropertyChild(effect, prop, "enabled"); + bool enabled = ( penabled == 0 || penabled->getBoolValue() ); + pass->setAttributeAndModes(depth.get(), enabled ? osg::StateAttribute::ON : osg::StateAttribute::OFF); } }; InstallAttributeBuilder installDepth("depth"); void buildTechnique(Effect* effect, const SGPropertyNode* prop, - const SGReaderWriterXMLOptions* options) + const SGReaderWriterOptions* options) { Technique* tniq = new Technique; effect->techniques.push_back(tniq); @@ -1278,7 +1294,7 @@ bool makeParametersFromStateSet(SGPropertyNode* effectRoot, const StateSet* ss) // Walk the techniques property tree, building techniques and // passes. -bool Effect::realizeTechniques(const SGReaderWriterXMLOptions* options) +bool Effect::realizeTechniques(const SGReaderWriterOptions* options) { if (_isRealized) return true; @@ -1377,10 +1393,11 @@ public: void valueChanged(SGPropertyNode* node) { - _tniq->refreshValidity(); + if (_tniq.valid()) + _tniq->refreshValidity(); } protected: - osg::ref_ptr _tniq; + osg::observer_ptr _tniq; }; template