]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.cxx
Use Boost singleton template for our singletons
[simgear.git] / simgear / scene / util / StateAttributeFactory.cxx
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 #include "StateAttributeFactory.hxx"
22
23 #include <osg/AlphaFunc>
24 #include <osg/Array>
25 #include <osg/BlendFunc>
26 #include <osg/CullFace>
27 #include <osg/ShadeModel>
28 #include <osg/Texture2D>
29 #include <osg/TexEnv>
30
31 #include <osg/Image>
32
33 using namespace osg;
34
35 namespace simgear
36 {
37 StateAttributeFactory::StateAttributeFactory()
38 {
39     _standardAlphaFunc = new AlphaFunc;
40     _standardAlphaFunc->setFunction(osg::AlphaFunc::GREATER);
41     _standardAlphaFunc->setReferenceValue(0.01);
42     _standardAlphaFunc->setDataVariance(Object::STATIC);
43     _smooth = new ShadeModel;
44     _smooth->setMode(ShadeModel::SMOOTH);
45     _smooth->setDataVariance(Object::STATIC);
46     _flat = new ShadeModel(ShadeModel::FLAT);
47     _flat->setDataVariance(Object::STATIC);
48     _standardBlendFunc = new BlendFunc;
49     _standardBlendFunc->setSource(BlendFunc::SRC_ALPHA);
50     _standardBlendFunc->setDestination(BlendFunc::ONE_MINUS_SRC_ALPHA);
51     _standardBlendFunc->setDataVariance(Object::STATIC);
52     _standardTexEnv = new TexEnv;
53     _standardTexEnv->setMode(TexEnv::MODULATE);
54     _standardTexEnv->setDataVariance(Object::STATIC);
55     osg::Image *dummyImage = new osg::Image;
56     dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA,
57                               GL_UNSIGNED_BYTE);
58     unsigned char* imageBytes = dummyImage->data(0, 0);
59     imageBytes[0] = 255;
60     imageBytes[1] = 255;
61     _whiteTexture = new osg::Texture2D;
62     _whiteTexture->setImage(dummyImage);
63     _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
64     _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
65     _whiteTexture->setDataVariance(osg::Object::STATIC);
66     _white = new Vec4Array(1);
67     (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
68     _white->setDataVariance(Object::STATIC);
69     _cullFaceFront = new CullFace(CullFace::FRONT);
70     _cullFaceFront->setDataVariance(Object::STATIC);
71     _cullFaceBack = new CullFace(CullFace::BACK);
72     _cullFaceBack->setDataVariance(Object::STATIC);
73 }
74
75 }