#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
+#include <simgear/scene/model/SGReaderWriterXMLOptions.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/StateAttributeFactory.hxx>
#include <simgear/math/SGMath.hxx>
// Hack to force inclusion of TextureBuilder.cxx in library
osg::Texture* TextureBuilder::buildFromType(Effect* effect, const string& type,
const SGPropertyNode*props,
- const osgDB::ReaderWriter::Options*
+ const SGReaderWriterXMLOptions*
options)
{
return EffectBuilder<Texture>::buildFromType(effect, type, props, options);
void TextureUnitBuilder::buildAttribute(Effect* effect, Pass* pass,
const SGPropertyNode* prop,
- const osgDB::ReaderWriter::Options* options)
+ const SGReaderWriterXMLOptions* options)
{
if (!isAttributeActive(effect, prop))
return;
TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props,
- const osgDB::ReaderWriter::Options* options,
+ const SGReaderWriterXMLOptions* options,
const string& texType)
{
Texture::FilterMode minFilter = Texture::LINEAR_MIPMAP_LINEAR;
- findAttr(filterModes, getEffectPropertyChild(effect, props, "filter"),
- minFilter);
+ const SGPropertyNode* ep = 0;
+ if ((ep = getEffectPropertyChild(effect, props, "filter")))
+ findAttr(filterModes, ep, minFilter);
Texture::FilterMode magFilter = Texture::LINEAR;
- findAttr(filterModes, getEffectPropertyChild(effect, props,
- "mag-filter"),
- magFilter);
+ if ((ep = getEffectPropertyChild(effect, props, "mag-filter")))
+ findAttr(filterModes, ep, magFilter);
const SGPropertyNode* pWrapS
= getEffectPropertyChild(effect, props, "wrap-s");
Texture::WrapMode sWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapS, sWrap);
+ if (pWrapS)
+ findAttr(wrapModes, pWrapS, sWrap);
const SGPropertyNode* pWrapT
= getEffectPropertyChild(effect, props, "wrap-t");
Texture::WrapMode tWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapT, tWrap);
+ if (pWrapT)
+ findAttr(wrapModes, pWrapT, tWrap);
const SGPropertyNode* pWrapR
= getEffectPropertyChild(effect, props, "wrap-r");
Texture::WrapMode rWrap = Texture::CLAMP;
- findAttr(wrapModes, pWrapR, rWrap);
+ if (pWrapR)
+ findAttr(wrapModes, pWrapR, rWrap);
const SGPropertyNode* pImage
= getEffectPropertyChild(effect, props, "image");
string imageName;
}
void setAttrs(const TexTuple& attrs, Texture* tex,
- const osgDB::ReaderWriter::Options* options)
+ const SGReaderWriterXMLOptions* options)
{
const string& imageName = attrs.get<0>();
if (imageName.empty()) {
public:
TexBuilder(const string& texType) : _type(texType) {}
Texture* build(Effect* effect, const SGPropertyNode*,
- const osgDB::ReaderWriter::Options* options);
+ const SGReaderWriterXMLOptions* options);
protected:
typedef map<TexTuple, ref_ptr<T> > TexMap;
TexMap texMap;
template<typename T>
Texture* TexBuilder<T>::build(Effect* effect, const SGPropertyNode* props,
- const osgDB::ReaderWriter::Options* options)
+ const SGReaderWriterXMLOptions* options)
{
TexTuple attrs = makeTexTuple(effect, props, options, _type);
typename TexMap::iterator itr = texMap.find(attrs);
{
public:
Texture* build(Effect* effect, const SGPropertyNode*,
- const osgDB::ReaderWriter::Options* options);
+ const SGReaderWriterXMLOptions* options);
};
Texture* WhiteTextureBuilder::build(Effect* effect, const SGPropertyNode*,
- const osgDB::ReaderWriter::Options* options)
+ const SGReaderWriterXMLOptions* options)
{
return StateAttributeFactory::instance()->getWhiteTexture();
}
TextureBuilder::Registrar installWhite("white", new WhiteTextureBuilder);
}
+class TransparentTextureBuilder : public TextureBuilder
+{
+public:
+ Texture* build(Effect* effect, const SGPropertyNode*,
+ const SGReaderWriterXMLOptions* options);
+};
+
+Texture* TransparentTextureBuilder::build(Effect* effect, const SGPropertyNode*,
+ const SGReaderWriterXMLOptions* options)
+{
+ return StateAttributeFactory::instance()->getTransparentTexture();
+}
+
+namespace
+{
+TextureBuilder::Registrar installTransparent("transparent",
+ new TransparentTextureBuilder);
+}
+
osg::Image* make3DNoiseImage(int texSize)
{
osg::Image* image = new osg::Image;
{
public:
Texture* build(Effect* effect, const SGPropertyNode*,
- const osgDB::ReaderWriter::Options* options);
+ const SGReaderWriterXMLOptions* options);
protected:
typedef map<int, ref_ptr<Texture3D> > NoiseMap;
NoiseMap _noises;
};
Texture* NoiseBuilder::build(Effect* effect, const SGPropertyNode* props,
- const osgDB::ReaderWriter::Options* options)
+ const SGReaderWriterXMLOptions* options)
{
int texSize = 64;
const SGPropertyNode* sizeProp = getEffectPropertyChild(effect, props,
EffectNameValue<TexEnvCombine::OperandParam> opParamInit[] =
{
- {"src_color", TexEnvCombine::SRC_COLOR},
- {"one_minus_src_color", TexEnvCombine::ONE_MINUS_SRC_COLOR},
- {"src_alpha", TexEnvCombine::SRC_ALPHA},
- {"one_minus_src_alpha", TexEnvCombine::ONE_MINUS_SRC_ALPHA}
+ {"src-color", TexEnvCombine::SRC_COLOR},
+ {"one-minus-src-color", TexEnvCombine::ONE_MINUS_SRC_COLOR},
+ {"src-alpha", TexEnvCombine::SRC_ALPHA},
+ {"one-minus-src-alpha", TexEnvCombine::ONE_MINUS_SRC_ALPHA}
};
EffectPropertyMap<TexEnvCombine::OperandParam> operandParams(opParamInit);
if ((p = getEffectPropertyChild(effect, envProp, "combine-alpha"))) {
TexEnvCombine::CombineParam calpha = TexEnvCombine::MODULATE;
findAttr(combineParams, p, calpha);
- result->setCombine_RGB(calpha);
+ result->setCombine_Alpha(calpha);
}
if ((p = getEffectPropertyChild(effect, envProp, "source0-rgb"))) {
TexEnvCombine::SourceParam source = TexEnvCombine::TEXTURE;
TexGen* result = new TexGen;
const SGPropertyNode* p = 0;
TexGen::Mode mode = TexGen::OBJECT_LINEAR;
- if (findAttr(tgenModes, getEffectPropertyChild(effect, tgenProp, "mode"),
- mode))
- result->setMode(mode);
+ findAttr(tgenModes, getEffectPropertyChild(effect, tgenProp, "mode"), mode);
+ result->setMode(mode);
const SGPropertyNode* planesNode = tgenProp->getChild("planes");
if (planesNode) {
for (int i = 0; i < planesNode->nChildren(); ++i) {
const SGPropertyNode* planeNode = planesNode->getChild(i);
TexGen::Coord coord;
- if (!findAttr(tgenCoords, planeNode->getName(), coord)) {
- SG_LOG(SG_INPUT, SG_ALERT, "Unknown TexGen plane "
- << planeNode->getName());
- } else {
- const SGPropertyNode* realNode
- = getEffectPropertyNode(effect, planeNode);
- SGVec4d plane = realNode->getValue<SGVec4d>();
- result->setPlane(coord, toOsg(plane));
- }
+ findAttr(tgenCoords, planeNode->getName(), coord);
+ const SGPropertyNode* realNode
+ = getEffectPropertyNode(effect, planeNode);
+ SGVec4d plane = realNode->getValue<SGVec4d>();
+ result->setPlane(coord, toOsg(plane));
}
}
return result;
const Texture2D* texture = dynamic_cast<const Texture2D*>(tex);
makeChild(texUnit, "unit")->setValue(0);
if (!tex) {
+ // The default shader-based technique ignores active
makeChild(texUnit, "active")->setValue(false);
- makeChild(texUnit, "type")->setValue("white");
return false;
}
const Image* image = texture->getImage();
}
makeChild(texUnit, "active")->setValue(true);
makeChild(texUnit, "type")->setValue("2d");
+ string filter = findName(filterModes,
+ texture->getFilter(Texture::MIN_FILTER));
+ string magFilter = findName(filterModes,
+ texture->getFilter(Texture::MAG_FILTER));
string wrapS = findName(wrapModes, texture->getWrap(Texture::WRAP_S));
string wrapT = findName(wrapModes, texture->getWrap(Texture::WRAP_T));
string wrapR = findName(wrapModes, texture->getWrap(Texture::WRAP_R));
makeChild(texUnit, "image")->setStringValue(imageName);
+ makeChild(texUnit, "filter")->setStringValue(filter);
+ makeChild(texUnit, "mag-filter")->setStringValue(magFilter);
makeChild(texUnit, "wrap-s")->setStringValue(wrapS);
makeChild(texUnit, "wrap-t")->setStringValue(wrapT);
makeChild(texUnit, "wrap-r")->setStringValue(wrapR);