]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.hxx
Cleanup and performance tuning of the random trees code.
[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/AlphaFunc>
28 #include <osg/Array>
29 #include <osg/BlendFunc>
30 #include <osg/CullFace>
31 #include <osg/ShadeModel>
32 #include <osg/Texture2D>
33 #include <osg/TexEnv>
34
35 // Return read-only instances of common OSG state attributes.
36 namespace simgear
37 {
38 class StateAttributeFactory : public osg::Referenced {
39 public:
40     // Alpha test > .01
41     osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
42     // alpha source, 1 - alpha destination
43     osg::BlendFunc* getStandardBlendFunc() { return _standardBlendFunc.get(); }
44     // modulate
45     osg::TexEnv* getStandardTexEnv() { return _standardTexEnv.get(); }
46     osg::ShadeModel* getSmoothShadeModel() { return _smooth.get(); }
47     osg::ShadeModel* getFlatShadeModel() { return _flat.get(); }
48     // White, repeating texture
49     osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
50     // White color
51     osg::Vec4Array* getWhiteColor() {return _white.get(); }
52     // cull back facing polygons
53     osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); }
54     
55     static StateAttributeFactory* instance();
56 protected:
57     StateAttributeFactory();
58     osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
59     osg::ref_ptr<osg::ShadeModel> _smooth;
60     osg::ref_ptr<osg::ShadeModel> _flat;
61     osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
62     osg::ref_ptr<osg::TexEnv> _standardTexEnv;
63     osg::ref_ptr<osg::Texture2D> _whiteTexture;
64     osg::ref_ptr<osg::Vec4Array> _white;
65     osg::ref_ptr<osg::CullFace> _cullFaceBack;
66     static osg::ref_ptr<StateAttributeFactory> _theInstance;
67     static OpenThreads::Mutex _instanceMutex;
68 };
69 }
70 #endif