]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/StateAttributeFactory.cxx
materials.xml format update
[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 #include "StateAttributeFactory.hxx"
22
23 #include <osg/AlphaFunc>
24 #include <osg/Array>
25 #include <osg/BlendFunc>
26 #include <osg/CullFace>
27 #include <osg/Depth>
28 #include <osg/ShadeModel>
29 #include <osg/Texture2D>
30 #include <osg/TexEnv>
31
32 #include <osg/Image>
33
34 using namespace osg;
35
36 namespace simgear
37 {
38 StateAttributeFactory::StateAttributeFactory()
39 {
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,
58                               GL_UNSIGNED_BYTE);
59     unsigned char* imageBytes = dummyImage->data(0, 0);
60     imageBytes[0] = 255;
61     imageBytes[1] = 255;
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     // And now the transparent texture
68     dummyImage = new osg::Image;
69     dummyImage->allocateImage(1, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE);
70     imageBytes = dummyImage->data(0, 0);
71     imageBytes[0] = 255;
72     imageBytes[1] = 0;
73     _transparentTexture = new osg::Texture2D;
74     _transparentTexture->setImage(dummyImage);
75     _transparentTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
76     _transparentTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
77     _transparentTexture->setDataVariance(osg::Object::STATIC);
78     _white = new Vec4Array(1);
79     (*_white)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
80     _white->setDataVariance(Object::STATIC);
81     _cullFaceFront = new CullFace(CullFace::FRONT);
82     _cullFaceFront->setDataVariance(Object::STATIC);
83     _cullFaceBack = new CullFace(CullFace::BACK);
84     _cullFaceBack->setDataVariance(Object::STATIC);
85     _depthWritesDisabled = new Depth(Depth::LESS, 0.0, 1.0, false);
86     _depthWritesDisabled->setDataVariance(Object::STATIC);
87 }
88
89 }