From: Tim Moore Date: Fri, 13 Aug 2010 10:42:10 +0000 (+0200) Subject: support for integer uniforms X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fe7c6554f7b0297e3b2c53940c920cdaf7767245;p=simgear.git support for integer uniforms Also, share common Uniform objects --- diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index a7ccbb59..d3344b58 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -889,11 +889,27 @@ EffectNameValue uniformTypesInit[] = }; EffectPropertyMap uniformTypes(uniformTypesInit); +// Optimization hack for common uniforms. +// XXX protect these with a mutex? + +ref_ptr texture0; +ref_ptr colorMode[3]; + struct UniformBuilder :public PassAttributeBuilder { void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop, const SGReaderWriterXMLOptions* options) { + if (!texture0.valid()) { + texture0 = new Uniform(Uniform::SAMPLER_2D, "texture"); + texture0->set(0); + texture0->setDataVariance(Object::STATIC); + for (int i = 0; i < 3; ++i) { + colorMode[i] = new Uniform(Uniform::INT, "colorMode"); + colorMode[i]->set(i); + colorMode[i]->setDataVariance(Object::STATIC); + } + } if (!isAttributeActive(effect, prop)) return; const SGPropertyNode* nameProp = prop->getChild("name"); @@ -957,6 +973,7 @@ struct UniformBuilder :public PassAttributeBuilder static_cast(&Uniform::set), vec4Names, options); break; + case Uniform::INT: case Uniform::SAMPLER_1D: case Uniform::SAMPLER_2D: case Uniform::SAMPLER_3D: @@ -970,6 +987,19 @@ struct UniformBuilder :public PassAttributeBuilder default: // avoid compiler warning break; } + // optimize common uniforms + if (uniformType == Uniform::SAMPLER_2D || uniformType == Uniform::INT) + { + int val; + uniform->get(val); + if (uniformType == Uniform::SAMPLER_2D && val == 0 + && name == "texture") { + uniform = texture0; + } else if (uniformType == Uniform::INT && val >= 0 && val < 3 + && name == "colorMode") { + uniform = colorMode[val]; + } + } pass->addUniform(uniform.get()); } };