3 * Copyright (C) 2007 Tim Moore
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.
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.
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,
22 #ifndef SIMGEAR_STATEATTRIBUTEFACTORY_HXX
23 #define SIMGEAR_STATEATTRIBUTEFACTORY_HXX 1
25 #include <OpenThreads/Mutex>
26 #include <osg/ref_ptr>
27 #include <osg/AlphaFunc>
28 #include <osg/BlendFunc>
29 #include <osg/ShadeModel>
30 #include <osg/Texture2D>
33 // Return read-only instances of common OSG state attributes.
36 class StateAttributeFactory : public osg::Referenced {
39 osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
40 // alpha source, 1 - alpha destination
41 osg::BlendFunc* getStandardBlendFunc() { return _standardBlendFunc.get(); }
43 osg::TexEnv* getStandardTexEnv() { return _standardTexEnv.get(); }
44 osg::ShadeModel* getSmoothShadeModel() { return _smooth.get(); }
45 osg::ShadeModel* getFlatShadeModel() { return _flat.get(); }
46 // White, repeating texture
47 osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
48 static StateAttributeFactory* instance();
50 StateAttributeFactory();
51 osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
52 osg::ref_ptr<osg::ShadeModel> _smooth;
53 osg::ref_ptr<osg::ShadeModel> _flat;
54 osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
55 osg::ref_ptr<osg::TexEnv> _standardTexEnv;
56 osg::ref_ptr<osg::Texture2D> _whiteTexture;
57 static osg::ref_ptr<StateAttributeFactory> _theInstance;
58 static OpenThreads::Mutex _instanceMutex;