// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#ifdef HAVE_CONFIG_H
+# include <simgear_config.h>
+#endif
+
#include "TextureBuilder.hxx"
#include <osg/Texture1D>
#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/StateAttributeFactory.hxx>
+#include <simgear/math/SGMath.hxx>
+#include <simgear/structure/OSGUtils.hxx>
#include "Noise.hxx"
using namespace std;
using namespace osg;
+using namespace effect;
+
// Hack to force inclusion of TextureBuilder.cxx in library
osg::Texture* TextureBuilder::buildFromType(Effect* effect, const string& type,
const SGPropertyNode*props,
namespace
{
-EffectNameValue<Texture::FilterMode> filterModes[] =
+EffectNameValue<Texture::FilterMode> filterModesInit[] =
{
{ "linear", Texture::LINEAR },
{ "linear-mipmap-linear", Texture::LINEAR_MIPMAP_LINEAR},
{ "nearest-mipmap-linear", Texture::NEAREST_MIPMAP_LINEAR},
{ "nearest-mipmap-nearest", Texture::NEAREST_MIPMAP_NEAREST}
};
+EffectPropertyMap<Texture::FilterMode> filterModes(filterModesInit);
-EffectNameValue<Texture::WrapMode> wrapModes[] =
+EffectNameValue<Texture::WrapMode> wrapModesInit[] =
{
{"clamp", Texture::CLAMP},
{"clamp-to-border", Texture::CLAMP_TO_BORDER},
{"mirror", Texture::MIRROR},
{"repeat", Texture::REPEAT}
};
-
+EffectPropertyMap<Texture::WrapMode> wrapModes(wrapModesInit);
TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props,
TextureBuilder::Registrar installNoise("noise", new NoiseBuilder);
}
+bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss)
+{
+ SGPropertyNode* texUnit = makeChild(paramRoot, "texture");
+ const Texture* tex = getStateAttribute<Texture>(0, ss);
+ const Texture2D* texture = dynamic_cast<const Texture2D*>(tex);
+ makeChild(texUnit, "unit")->setValue(0);
+ if (!tex) {
+ makeChild(texUnit, "active")->setValue(false);
+ makeChild(texUnit, "type")->setValue("white");
+ return false;
+ }
+ const Image* image = texture->getImage();
+ string imageName;
+ if (image) {
+ imageName = image->getFileName();
+ } else {
+ makeChild(texUnit, "active")->setValue(false);
+ makeChild(texUnit, "type")->setValue("white");
+ return false;
+ }
+ makeChild(texUnit, "active")->setValue(true);
+ makeChild(texUnit, "type")->setValue("2d");
+ 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, "wrap-s")->setStringValue(wrapS);
+ makeChild(texUnit, "wrap-t")->setStringValue(wrapT);
+ makeChild(texUnit, "wrap-r")->setStringValue(wrapR);
+ return true;
+}
+
}