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,
21 #include "StateAttributeFactory.hxx"
23 #include <osg/AlphaFunc>
25 #include <osg/BlendFunc>
26 #include <osg/CullFace>
27 #include <osg/ShadeModel>
28 #include <osg/Texture2D>
37 StateAttributeFactory::StateAttributeFactory()
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,
58 unsigned char* imageBytes = dummyImage->data(0, 0);
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);