]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.cxx
Repaint 2D cloud layers using texture combiner
[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
22 #include <OpenThreads/ScopedLock>
23
24 #include <osg/Image>
25 #include "StateAttributeFactory.hxx"
26
27 using namespace osg;
28
29 namespace simgear
30 {
31 StateAttributeFactory::StateAttributeFactory()
32 {
33     _standardAlphaFunc = new AlphaFunc;
34     _standardAlphaFunc->setFunction(osg::AlphaFunc::GREATER);
35     _standardAlphaFunc->setReferenceValue(0.01);
36     _standardAlphaFunc->setDataVariance(Object::STATIC);
37     _smooth = new ShadeModel;
38     _smooth->setMode(ShadeModel::SMOOTH);
39     _smooth->setDataVariance(Object::STATIC);
40     _flat = new ShadeModel(ShadeModel::FLAT);
41     _flat->setDataVariance(Object::STATIC);
42     _standardBlendFunc = new BlendFunc;
43     _standardBlendFunc->setSource(BlendFunc::SRC_ALPHA);
44     _standardBlendFunc->setDestination(BlendFunc::ONE_MINUS_SRC_ALPHA);
45     _standardBlendFunc->setDataVariance(Object::STATIC);
46     _standardTexEnv = new TexEnv;
47     _standardTexEnv->setMode(TexEnv::MODULATE);
48     _standardTexEnv->setDataVariance(Object::STATIC);
49     osg::Image *dummyImage = new osg::Image;
50     dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA,
51                               GL_UNSIGNED_BYTE);
52     unsigned char* imageBytes = dummyImage->data(0, 0);
53     imageBytes[0] = 255;
54     imageBytes[1] = 255;
55     _whiteTexture = new osg::Texture2D;
56     _whiteTexture->setImage(dummyImage);
57     _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
58     _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
59     _whiteTexture->setDataVariance(osg::Object::STATIC);
60 }
61
62 osg::ref_ptr<StateAttributeFactory> StateAttributeFactory::_theInstance;
63 OpenThreads::Mutex StateAttributeFactory::_instanceMutex;
64
65 StateAttributeFactory* StateAttributeFactory::instance()
66 {
67     OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
68     if (!_theInstance.valid()) {
69         _theInstance = new StateAttributeFactory;
70     }
71     return _theInstance.get();
72 }
73 }