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>
40 #include <simgear/structure/Singleton.hxx>
42 // Return read-only instances of common OSG state attributes.
45 class StateAttributeFactory :
46 public ReferencedSingleton<StateAttributeFactory> {
48 ~StateAttributeFactory();
51 osg::AlphaFunc* getStandardAlphaFunc() { return _standardAlphaFunc.get(); }
52 // alpha source, 1 - alpha destination
53 osg::BlendFunc* getStandardBlendFunc() { return _standardBlendFunc.get(); }
55 osg::TexEnv* getStandardTexEnv() { return _standardTexEnv.get(); }
56 osg::ShadeModel* getSmoothShadeModel() { return _smooth.get(); }
57 osg::ShadeModel* getFlatShadeModel() { return _flat.get(); }
58 // White, repeating texture
59 osg::Texture2D* getWhiteTexture() { return _whiteTexture.get(); }
61 osg::Vec4Array* getWhiteColor() {return _white.get(); }
62 // A white, completely transparent texture
63 osg::Texture2D* getTransparentTexture()
65 return _transparentTexture.get();
67 // cull front and back facing polygons
68 osg::CullFace* getCullFaceFront() { return _cullFaceFront.get(); }
69 osg::CullFace* getCullFaceBack() { return _cullFaceBack.get(); }
70 // Standard depth with writes disabled.
71 osg::Depth* getDepthWritesDisabled() { return _depthWritesDisabled.get(); }
72 StateAttributeFactory();
74 osg::ref_ptr<osg::AlphaFunc> _standardAlphaFunc;
75 osg::ref_ptr<osg::ShadeModel> _smooth;
76 osg::ref_ptr<osg::ShadeModel> _flat;
77 osg::ref_ptr<osg::BlendFunc> _standardBlendFunc;
78 osg::ref_ptr<osg::TexEnv> _standardTexEnv;
79 osg::ref_ptr<osg::Texture2D> _whiteTexture;
80 osg::ref_ptr<osg::Texture2D> _transparentTexture;
81 osg::ref_ptr<osg::Vec4Array> _white;
82 osg::ref_ptr<osg::CullFace> _cullFaceFront;
83 osg::ref_ptr<osg::CullFace> _cullFaceBack;
84 osg::ref_ptr<osg::Depth> _depthWritesDisabled;