]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.hxx
Use Boost singleton template for our singletons
[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
29 namespace osg
30 {
31 class AlphaFunc;
32 class BlendFunc;
33 class CullFace;
34 class ShadeModel;
35 class Texture2D;
36 class TexEnv;
37 }
38
39 #include <simgear/structure/Singleton.hxx>
40
41 // Return read-only instances of common OSG state attributes.
42 namespace simgear
43 {
44 class StateAttributeFactory :
45         public ReferencedSingleton<StateAttributeFactory> {
46 public:
47     // Alpha test > .01
48     osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
49     // alpha source, 1 - alpha destination
50     osg::BlendFunc* getStandardBlendFunc() { return _standardBlendFunc.get(); }
51     // modulate
52     osg::TexEnv* getStandardTexEnv() { return _standardTexEnv.get(); }
53     osg::ShadeModel* getSmoothShadeModel() { return _smooth.get(); }
54     osg::ShadeModel* getFlatShadeModel() { return _flat.get(); }
55     // White, repeating texture
56     osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
57     // White color
58     osg::Vec4Array* getWhiteColor() {return _white.get(); }
59     // cull front and back facing polygons
60     osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); }
61     osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); }
62     StateAttributeFactory();    
63 protected:
64     osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
65     osg::ref_ptr<osg::ShadeModel> _smooth;
66     osg::ref_ptr<osg::ShadeModel> _flat;
67     osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
68     osg::ref_ptr<osg::TexEnv> _standardTexEnv;
69     osg::ref_ptr<osg::Texture2D> _whiteTexture;
70     osg::ref_ptr<osg::Vec4Array> _white;
71     osg::ref_ptr<osg::CullFace> _cullFaceFront;
72     osg::ref_ptr<osg::CullFace> _cullFaceBack;
73 };
74 }
75 #endif