00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "StateAttributeFactory.hxx"
00022
00023 #include <osg/AlphaFunc>
00024 #include <osg/Array>
00025 #include <osg/BlendFunc>
00026 #include <osg/CullFace>
00027 #include <osg/Depth>
00028 #include <osg/ShadeModel>
00029 #include <osg/Texture2D>
00030 #include <osg/TexEnv>
00031
00032 #include <osg/Image>
00033
00034 using namespace osg;
00035
00036 namespace simgear
00037 {
00038 StateAttributeFactory::StateAttributeFactory()
00039 {
00040 _standardAlphaFunc = new AlphaFunc;
00041 _standardAlphaFunc->setFunction(osg::AlphaFunc::GREATER);
00042 _standardAlphaFunc->setReferenceValue(0.01);
00043 _standardAlphaFunc->setDataVariance(Object::STATIC);
00044 _smooth = new ShadeModel;
00045 _smooth->setMode(ShadeModel::SMOOTH);
00046 _smooth->setDataVariance(Object::STATIC);
00047 _flat = new ShadeModel(ShadeModel::FLAT);
00048 _flat->setDataVariance(Object::STATIC);
00049 _standardBlendFunc = new BlendFunc;
00050 _standardBlendFunc->setSource(BlendFunc::SRC_ALPHA);
00051 _standardBlendFunc->setDestination(BlendFunc::ONE_MINUS_SRC_ALPHA);
00052 _standardBlendFunc->setDataVariance(Object::STATIC);
00053 _standardTexEnv = new TexEnv;
00054 _standardTexEnv->setMode(TexEnv::MODULATE);
00055 _standardTexEnv->setDataVariance(Object::STATIC);
00056 osg::Image *dummyImage = new osg::Image;
00057 dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA,
00058 GL_UNSIGNED_BYTE);
00059 unsigned char* imageBytes = dummyImage->data(0, 0);
00060 imageBytes[0] = 255;
00061 imageBytes[1] = 255;
00062 _whiteTexture = new osg::Texture2D;
00063 _whiteTexture->setImage(dummyImage);
00064 _whiteTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
00065 _whiteTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
00066 _whiteTexture->setDataVariance(osg::Object::STATIC);
00067
00068 dummyImage = new osg::Image;
00069 dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
00070 imageBytes = dummyImage->data(0, 0);
00071 imageBytes[0] = 255;
00072 imageBytes[1] = 0;
00073 _transparentTexture = new osg::Texture2D;
00074 _transparentTexture->setImage(dummyImage);
00075 _transparentTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
00076 _transparentTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
00077 _transparentTexture->setDataVariance(osg::Object::STATIC);
00078 _white = new Vec4Array(1);
00079 (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
00080 _white->setDataVariance(Object::STATIC);
00081 _cullFaceFront = new CullFace(CullFace::FRONT);
00082 _cullFaceFront->setDataVariance(Object::STATIC);
00083 _cullFaceBack = new CullFace(CullFace::BACK);
00084 _cullFaceBack->setDataVariance(Object::STATIC);
00085 _depthWritesDisabled = new Depth(Depth::LESS, 0.0, 1.0, false);
00086 _depthWritesDisabled->setDataVariance(Object::STATIC);
00087 }
00088
00089 }