]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/util/StateAttributeFactory.hxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / util / StateAttributeFactory.hxx
index 0a7809dd74dacd8e073bec9605648e0b2714c597..884abbbe370b0fd16f9449de9d1a80943ccc6fd3 100644 (file)
 
 #include <OpenThreads/Mutex>
 #include <osg/ref_ptr>
-#include <osg/AlphaFunc>
 #include <osg/Array>
-#include <osg/BlendFunc>
-#include <osg/CullFace>
-#include <osg/ShadeModel>
-#include <osg/Texture2D>
-#include <osg/TexEnv>
+#include <map>
+
+namespace osg
+{
+class AlphaFunc;
+class BlendFunc;
+class CullFace;
+class Depth;
+class ShadeModel;
+class Texture2D;
+class Texture3D;
+class TexEnv;
+}
+
+#include <simgear/scene/util/OsgSingleton.hxx>
 
 // Return read-only instances of common OSG state attributes.
 namespace simgear
 {
-class StateAttributeFactory : public osg::Referenced {
+class StateAttributeFactory :
+        public ReferencedSingleton<StateAttributeFactory> {
 public:
+    ~StateAttributeFactory();
+          
     // Alpha test > .01
     osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
     // alpha source, 1 - alpha destination
@@ -49,24 +61,32 @@ public:
     osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
     // White color
     osg::Vec4Array* getWhiteColor() {return _white.get(); }
+    // A white, completely transparent texture
+    osg::Texture2D* getTransparentTexture()
+    {
+        return _transparentTexture.get();
+    }
     // cull front and back facing polygons
     osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); }
     osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); }
-    
-    static StateAttributeFactory* instance();
+    // Standard depth with writes disabled.
+    osg::Depth* getDepthWritesDisabled() { return _depthWritesDisabled.get(); }
+    osg::Texture3D* getNoiseTexture(int size);
+    StateAttributeFactory();    
 protected:
-    StateAttributeFactory();
     osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
     osg::ref_ptr<osg::ShadeModel> _smooth;
     osg::ref_ptr<osg::ShadeModel> _flat;
     osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
     osg::ref_ptr<osg::TexEnv> _standardTexEnv;
     osg::ref_ptr<osg::Texture2D> _whiteTexture;
+    osg::ref_ptr<osg::Texture2D> _transparentTexture;
     osg::ref_ptr<osg::Vec4Array> _white;
     osg::ref_ptr<osg::CullFace> _cullFaceFront;
     osg::ref_ptr<osg::CullFace> _cullFaceBack;
-    static osg::ref_ptr<StateAttributeFactory> _theInstance;
-    static OpenThreads::Mutex _instanceMutex;
+    osg::ref_ptr<osg::Depth> _depthWritesDisabled;
+    typedef std::map<int, osg::ref_ptr<osg::Texture3D> > NoiseMap;
+    NoiseMap _noises;
 };
 }
 #endif