]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.hxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / util / StateAttributeFactory.hxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2007 Tim Moore
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #ifndef SIMGEAR_STATEATTRIBUTEFACTORY_HXX
23 #define SIMGEAR_STATEATTRIBUTEFACTORY_HXX 1
24
25 #include <OpenThreads/Mutex>
26 #include <osg/ref_ptr>
27 #include <osg/Array>
28 #include <map>
29
30 namespace osg
31 {
32 class AlphaFunc;
33 class BlendFunc;
34 class CullFace;
35 class Depth;
36 class ShadeModel;
37 class Texture2D;
38 class Texture3D;
39 class TexEnv;
40 }
41
42 #include <simgear/scene/util/OsgSingleton.hxx>
43
44 // Return read-only instances of common OSG state attributes.
45 namespace simgear
46 {
47 class StateAttributeFactory :
48         public ReferencedSingleton<StateAttributeFactory> {
49 public:
50     ~StateAttributeFactory();
51           
52     // Alpha test > .01
53     osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
54     // alpha source, 1 - alpha destination
55     osg::BlendFunc* getStandardBlendFunc() { return _standardBlendFunc.get(); }
56     // modulate
57     osg::TexEnv* getStandardTexEnv() { return _standardTexEnv.get(); }
58     osg::ShadeModel* getSmoothShadeModel() { return _smooth.get(); }
59     osg::ShadeModel* getFlatShadeModel() { return _flat.get(); }
60     // White, repeating texture
61     osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
62     // White color
63     osg::Vec4Array* getWhiteColor() {return _white.get(); }
64     // A white, completely transparent texture
65     osg::Texture2D* getTransparentTexture()
66     {
67         return _transparentTexture.get();
68     }
69     // cull front and back facing polygons
70     osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); }
71     osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); }
72     // Standard depth with writes disabled.
73     osg::Depth* getDepthWritesDisabled() { return _depthWritesDisabled.get(); }
74     osg::Texture3D* getNoiseTexture(int size);
75     StateAttributeFactory();    
76 protected:
77     osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
78     osg::ref_ptr<osg::ShadeModel> _smooth;
79     osg::ref_ptr<osg::ShadeModel> _flat;
80     osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
81     osg::ref_ptr<osg::TexEnv> _standardTexEnv;
82     osg::ref_ptr<osg::Texture2D> _whiteTexture;
83     osg::ref_ptr<osg::Texture2D> _transparentTexture;
84     osg::ref_ptr<osg::Vec4Array> _white;
85     osg::ref_ptr<osg::CullFace> _cullFaceFront;
86     osg::ref_ptr<osg::CullFace> _cullFaceBack;
87     osg::ref_ptr<osg::Depth> _depthWritesDisabled;
88     typedef std::map<int, osg::ref_ptr<osg::Texture3D> > NoiseMap;
89     NoiseMap _noises;
90 };
91 }
92 #endif