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 #include <OpenThreads/ScopedLock>
25 #include "StateAttributeFactory.hxx"
31 StateAttributeFactory::StateAttributeFactory()
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,
52 unsigned char* imageBytes = dummyImage->data(0, 0);
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);
62 osg::ref_ptr<StateAttributeFactory> StateAttributeFactory::_theInstance;
63 OpenThreads::Mutex StateAttributeFactory::_instanceMutex;
65 StateAttributeFactory* StateAttributeFactory::instance()
67 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_instanceMutex);
68 if (!_theInstance.valid()) {
69 _theInstance = new StateAttributeFactory;
71 return _theInstance.get();