+class GBufferBuilder : public TextureBuilder
+{
+public:
+ GBufferBuilder(int b) : buffer(b) {}
+ Texture* build(Effect* effect, Pass* pass, const SGPropertyNode*,
+ const SGReaderWriterOptions* options);
+private:
+ int buffer;
+};
+
+Texture* GBufferBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* prop,
+ const SGReaderWriterOptions* options)
+{
+ int unit = 0;
+ const SGPropertyNode* pUnit = prop->getChild("unit");
+ if (pUnit) {
+ unit = pUnit->getValue<int>();
+ } else {
+ const SGPropertyNode* pName = prop->getChild("name");
+ if (pName)
+ try {
+ unit = boost::lexical_cast<int>(pName->getStringValue());
+ } catch (boost::bad_lexical_cast& lex) {
+ SG_LOG(SG_INPUT, SG_ALERT, "can't decode name as texture unit "
+ << lex.what());
+ }
+ }
+ pass->setBufferUnit( unit, buffer );
+
+ // Return white for now. Would be overridden in Technique::ProcessDrawable
+ return StateAttributeFactory::instance()->getWhiteTexture();
+}
+
+namespace
+{
+TextureBuilder::Registrar installDepthBuffer("depth-buffer", new GBufferBuilder(0));
+TextureBuilder::Registrar installNormalBuffer("normal-buffer", new GBufferBuilder(1));
+TextureBuilder::Registrar installDiffuseBuffer("diffuse-buffer", new GBufferBuilder(2));
+TextureBuilder::Registrar installSpecularBuffer("specular-buffer", new GBufferBuilder(3));
+}
+