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>
28 #include <osg/ShadeModel>
29 #include <osg/Texture2D>
38 StateAttributeFactory::StateAttributeFactory()
40 _standardAlphaFunc = new AlphaFunc;
41 _standardAlphaFunc->setFunction(osg::AlphaFunc::GREATER);
42 _standardAlphaFunc->setReferenceValue(0.01);
43 _standardAlphaFunc->setDataVariance(Object::STATIC);
44 _smooth = new ShadeModel;
45 _smooth->setMode(ShadeModel::SMOOTH);
46 _smooth->setDataVariance(Object::STATIC);
47 _flat = new ShadeModel(ShadeModel::FLAT);
48 _flat->setDataVariance(Object::STATIC);
49 _standardBlendFunc = new BlendFunc;
50 _standardBlendFunc->setSource(BlendFunc::SRC_ALPHA);
51 _standardBlendFunc->setDestination(BlendFunc::ONE_MINUS_SRC_ALPHA);
52 _standardBlendFunc->setDataVariance(Object::STATIC);
53 _standardTexEnv = new TexEnv;
54 _standardTexEnv->setMode(TexEnv::MODULATE);
55 _standardTexEnv->setDataVariance(Object::STATIC);
56 osg::Image *dummyImage = new osg::Image;
57 dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA,
59 unsigned char* imageBytes = dummyImage->data(0, 0);
62 _whiteTexture = new osg::Texture2D;
63 _whiteTexture->setImage(dummyImage);
64 _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
65 _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
66 _whiteTexture->setDataVariance(osg::Object::STATIC);
67 _white = new Vec4Array(1);
68 (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
69 _white->setDataVariance(Object::STATIC);
70 _cullFaceFront = new CullFace(CullFace::FRONT);
71 _cullFaceFront->setDataVariance(Object::STATIC);
72 _cullFaceBack = new CullFace(CullFace::BACK);
73 _cullFaceBack->setDataVariance(Object::STATIC);
74 _depthWritesDisabled = new Depth(Depth::LESS, 0.0, 1.0, false);
75 _depthWritesDisabled->setDataVariance(Object::STATIC);