]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/util/StateAttributeFactory.cxx
accomodate changes to osgDB::DatabasePager interface
[simgear.git] / simgear / scene / util / StateAttributeFactory.cxx
index 30407b05caab501fa1612bc2a177f9154459533f..25a0a57622860f841105ebd9985de3613682c220 100644 (file)
  * MA 02110-1301, USA.
  *
  */
+#include "StateAttributeFactory.hxx"
 
-#include <OpenThreads/ScopedLock>
+#include <osg/AlphaFunc>
+#include <osg/Array>
+#include <osg/BlendFunc>
+#include <osg/CullFace>
+#include <osg/Depth>
+#include <osg/ShadeModel>
+#include <osg/Texture2D>
+#include <osg/TexEnv>
 
 #include <osg/Image>
-#include "StateAttributeFactory.hxx"
 
 using namespace osg;
 
@@ -32,7 +39,7 @@ StateAttributeFactory::StateAttributeFactory()
 {
     _standardAlphaFunc = new AlphaFunc;
     _standardAlphaFunc->setFunction(osg::AlphaFunc::GREATER);
-    _standardAlphaFunc->setReferenceValue(0.01);
+    _standardAlphaFunc->setReferenceValue(0.01f);
     _standardAlphaFunc->setDataVariance(Object::STATIC);
     _smooth = new ShadeModel;
     _smooth->setMode(ShadeModel::SMOOTH);
@@ -57,22 +64,26 @@ StateAttributeFactory::StateAttributeFactory()
     _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
     _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
     _whiteTexture->setDataVariance(osg::Object::STATIC);
+    // And now the transparent texture
+    dummyImage = new osg::Image;
+    dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
+    imageBytes = dummyImage->data(0, 0);
+    imageBytes[0] = 255;
+    imageBytes[1] = 0;
+    _transparentTexture = new osg::Texture2D;
+    _transparentTexture->setImage(dummyImage);
+    _transparentTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
+    _transparentTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
+    _transparentTexture->setDataVariance(osg::Object::STATIC);
     _white = new Vec4Array(1);
     (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
     _white->setDataVariance(Object::STATIC);
+    _cullFaceFront = new CullFace(CullFace::FRONT);
+    _cullFaceFront->setDataVariance(Object::STATIC);
     _cullFaceBack = new CullFace(CullFace::BACK);
     _cullFaceBack->setDataVariance(Object::STATIC);
+    _depthWritesDisabled = new Depth(Depth::LESS, 0.0, 1.0, false);
+    _depthWritesDisabled->setDataVariance(Object::STATIC);
 }
 
-osg::ref_ptr<StateAttributeFactory> StateAttributeFactory::_theInstance;
-OpenThreads::Mutex StateAttributeFactory::_instanceMutex;
-
-StateAttributeFactory* StateAttributeFactory::instance()
-{
-    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
-    if (!_theInstance.valid()) {
-        _theInstance = new StateAttributeFactory;
-    }
-    return _theInstance.get();
-}
 }