X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2FEffect.cxx;h=b4c010f497b66d1b5265f2c9e944714a7de7aece;hb=0d419aba8a1ea9c67b1982f4d68fe1fe7bd79033;hp=c3976d81039ad9e512dc45115939b9345ed5bcb2;hpb=2e138779265f7c5b68c46d6e91e75dc25d46e892;p=simgear.git diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index c3976d81..b4c010f4 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2008 - 2009 Tim Moore timoore@redhat.com +// Copyright (C) 2008 - 2010 Tim Moore timoore33@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -732,6 +732,28 @@ struct ShaderProgramBuilder : PassAttributeBuilder const SGReaderWriterXMLOptions* options); }; + +EffectNameValue geometryInputTypeInit[] = +{ + {"points", GL_POINTS}, + {"lines", GL_LINES}, + {"lines-adjacency", GL_LINES_ADJACENCY_EXT}, + {"triangles", GL_TRIANGLES}, + {"triangles-adjacency", GL_TRIANGLES_ADJACENCY_EXT}, +}; +EffectPropertyMap +geometryInputType(geometryInputTypeInit); + + +EffectNameValue geometryOutputTypeInit[] = +{ + {"points", GL_POINTS}, + {"line-strip", GL_LINE_STRIP}, + {"triangle-strip", GL_TRIANGLE_STRIP} +}; +EffectPropertyMap +geometryOutputType(geometryOutputTypeInit); + void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, const SGReaderWriterXMLOptions* @@ -741,6 +763,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, if (!isAttributeActive(effect, prop)) return; PropertyList pVertShaders = prop->getChildren("vertex-shader"); + PropertyList pGeomShaders = prop->getChildren("geometry-shader"); PropertyList pFragShaders = prop->getChildren("fragment-shader"); PropertyList pAttributes = prop->getChildren("attribute"); ProgramKey prgKey; @@ -750,6 +773,12 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, ++itr) prgKey.shaders.push_back(ShaderKey((*itr)->getStringValue(), Shader::VERTEX)); + for (PropertyList::iterator itr = pGeomShaders.begin(), + e = pGeomShaders.end(); + itr != e; + ++itr) + prgKey.shaders.push_back(ShaderKey((*itr)->getStringValue(), + Shader::GEOMETRY)); for (PropertyList::iterator itr = pFragShaders.begin(), e = pFragShaders.end(); itr != e; @@ -781,7 +810,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, // Add vertex shaders, then fragment shaders PropertyList& pvec = pVertShaders; Shader::Type stype = Shader::VERTEX; - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 3; ++i) { for (PropertyList::iterator nameItr = pvec.begin(), e = pvec.end(); nameItr != e; ++nameItr) { @@ -802,13 +831,35 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, } } } - pvec = pFragShaders; - stype = Shader::FRAGMENT; + if (i == 0) { + pvec = pGeomShaders; + stype = Shader::GEOMETRY; + } else { + pvec = pFragShaders; + stype = Shader::FRAGMENT; + } } BOOST_FOREACH(const ProgramKey::AttribKey& key, prgKey.attributes) { program->addBindAttribLocation(key.first, key.second); } - programMap.insert(ProgramMap::value_type(prgKey, program)); + const SGPropertyNode* pGeometryVerticesOut = getEffectPropertyChild(effect, prop, "geometry-vertices-out"); + if ( pGeometryVerticesOut ) { + program->setParameter( GL_GEOMETRY_VERTICES_OUT_EXT, pGeometryVerticesOut->getIntValue() ); + } + const SGPropertyNode* pGeometryInputType = getEffectPropertyChild(effect, prop, "geometry-input-type"); + if ( pGeometryInputType ) { + GLint type; + findAttr( geometryInputType, pGeometryInputType->getStringValue(), type ); + program->setParameter( GL_GEOMETRY_INPUT_TYPE_EXT, type ); + } + const SGPropertyNode* pGeometryOutputType = getEffectPropertyChild(effect, prop, "geometry-output-type"); + if ( pGeometryOutputType ) { + GLint type; + findAttr( geometryOutputType, pGeometryOutputType->getStringValue(), type ); + program->setParameter( GL_GEOMETRY_OUTPUT_TYPE_EXT, type ); + } + + programMap.insert(ProgramMap::value_type(prgKey, program)); } pass->setAttributeAndModes(program); } @@ -817,6 +868,8 @@ InstallAttributeBuilder installShaderProgram("program"); EffectNameValue uniformTypesInit[] = { + {"bool", Uniform::BOOL}, + {"int", Uniform::INT}, {"float", Uniform::FLOAT}, {"float-vec3", Uniform::FLOAT_VEC3}, {"float-vec4", Uniform::FLOAT_VEC4}, @@ -855,6 +908,12 @@ struct UniformBuilder :public PassAttributeBuilder if (!typeProp) { props::Type propType = valProp->getType(); switch (propType) { + case props::BOOL: + uniformType = Uniform::BOOL; + break; + case props::INT: + uniformType = Uniform::INT; + break; case props::FLOAT: case props::DOUBLE: break; // default float type; @@ -1130,6 +1189,9 @@ bool makeParametersFromStateSet(SGPropertyNode* effectRoot, const StateSet* ss) } } makeChild(paramRoot, "cull-face")->setStringValue(cullFaceString); + // Macintosh ATI workaround + bool vertexTwoSide = cullFaceString == "off"; + makeChild(paramRoot, "vertex-program-two-side")->setValue(vertexTwoSide); const BlendFunc* blendFunc = getStateAttribute(ss); SGPropertyNode* blendNode = makeChild(paramRoot, "blend"); if (blendFunc) { @@ -1228,14 +1290,15 @@ osgDB::RegisterDotOsgWrapperProxy effectProxy } // Property expressions for technique predicates -class PropertyExpression : public SGExpression +template +class PropertyExpression : public SGExpression { public: PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {} - void eval(bool& value, const expression::Binding*) const + void eval(T& value, const expression::Binding*) const { - value = _pnode->getValue(); + value = _pnode->getValue(); } protected: SGPropertyNode_ptr _pnode; @@ -1254,12 +1317,13 @@ protected: osg::ref_ptr _tniq; }; +template Expression* propertyExpressionParser(const SGPropertyNode* exp, expression::Parser* parser) { SGPropertyNode_ptr pnode = getPropertyRoot()->getNode(exp->getStringValue(), true); - PropertyExpression* pexp = new PropertyExpression(pnode); + PropertyExpression* pexp = new PropertyExpression(pnode); TechniquePredParser* predParser = dynamic_cast(parser); if (predParser) @@ -1269,6 +1333,9 @@ Expression* propertyExpressionParser(const SGPropertyNode* exp, } expression::ExpParserRegistrar propertyRegistrar("property", - propertyExpressionParser); + propertyExpressionParser); + +expression::ExpParserRegistrar propvalueRegistrar("float-property", + propertyExpressionParser); }