fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Shader / Base / OSGShaderAttribute.cpp
blob472b31882db61578f5d852361cb93f305ecc4afa
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGShaderAttribute.h"
40 #include "OSGShaderAttributeFields.h"
42 #include "OSGMField.ins"
44 #include "OSGSingletonHolder.ins"
46 OSG_BEGIN_NAMESPACE
48 DataType FieldTraits<ShaderAttribute>::_type("ShaderAttribute", "BaseType");
50 OSG_FIELDTRAITS_GETTYPE ( ShaderAttribute)
51 OSG_FIELD_DLLEXPORT_DEF1(MField, ShaderAttribute)
53 OSG_SINGLETON_INST(ShaderAttrIndexMapperBase, addPostFactoryExitFunction)
55 template class SingletonHolder<ShaderAttrIndexMapperBase>;
57 ShaderAttrIndexMapperBase::ShaderAttrIndexMapperBase(void) :
58 Inherited()
60 initMaps();
63 ShaderAttrIndexMapperBase::~ShaderAttrIndexMapperBase(void)
67 void ShaderAttrIndexMapperBase::initMaps(void)
69 this->addToValuePair("PositionsIndex", ShaderConstants::Attribute0Index);
70 this->addToValuePair("NormalsIndex", ShaderConstants::Attribute2Index);
71 this->addToValuePair("ColorsIndex", ShaderConstants::Attribute3Index);
72 this->addToValuePair("SecondaryColorsIndex",
73 ShaderConstants::Attribute4Index);
75 this->addToValuePair("TexCoordsIndex", ShaderConstants::Attribute8Index );
76 this->addToValuePair("TexCoords0Index", ShaderConstants::Attribute8Index );
77 this->addToValuePair("TexCoords1Index", ShaderConstants::Attribute9Index );
78 this->addToValuePair("TexCoords2Index", ShaderConstants::Attribute10Index);
79 this->addToValuePair("TexCoords3Index", ShaderConstants::Attribute11Index);
80 this->addToValuePair("TexCoords4Index", ShaderConstants::Attribute12Index);
81 this->addToValuePair("TexCoords5Index", ShaderConstants::Attribute13Index);
82 this->addToValuePair("TexCoords6Index", ShaderConstants::Attribute14Index);
83 this->addToValuePair("TexCoords7Index", ShaderConstants::Attribute15Index);
85 this->addToValuePair ("Attribute0Index",
86 ShaderConstants::Attribute0Index);
87 this->addFromValuePair(ShaderConstants::Attribute0Index,
88 "Attribute0Index");
90 this->addToValuePair ("Attribute1Index",
91 ShaderConstants::Attribute1Index);
92 this->addFromValuePair(ShaderConstants::Attribute1Index,
93 "Attribute1Index");
95 this->addToValuePair ("Attribute2Index",
96 ShaderConstants::Attribute2Index);
97 this->addFromValuePair(ShaderConstants::Attribute2Index,
98 "Attribute2Index");
100 this->addToValuePair ("Attribute3Index",
101 ShaderConstants::Attribute3Index);
102 this->addFromValuePair(ShaderConstants::Attribute3Index,
103 "Attribute3Index");
105 this->addToValuePair ("Attribute4Index",
106 ShaderConstants::Attribute4Index);
107 this->addFromValuePair(ShaderConstants::Attribute4Index,
108 "Attribute4Index");
110 this->addToValuePair ("Attribute5Index",
111 ShaderConstants::Attribute5Index);
112 this->addFromValuePair(ShaderConstants::Attribute5Index,
113 "Attribute5Index");
115 this->addToValuePair ("Attribute6Index",
116 ShaderConstants::Attribute6Index);
117 this->addFromValuePair(ShaderConstants::Attribute6Index,
118 "Attribute6Index");
120 this->addToValuePair ("Attribute7Index",
121 ShaderConstants::Attribute7Index);
122 this->addFromValuePair(ShaderConstants::Attribute7Index,
123 "Attribute7Index");
125 this->addToValuePair ("Attribute8Index",
126 ShaderConstants::Attribute8Index);
127 this->addFromValuePair(ShaderConstants::Attribute8Index,
128 "Attribute8Index");
130 this->addToValuePair ("Attribute9Index",
131 ShaderConstants::Attribute9Index);
132 this->addFromValuePair(ShaderConstants::Attribute9Index,
133 "Attribute9Index");
135 this->addToValuePair ("Attribute10Index",
136 ShaderConstants::Attribute10Index);
137 this->addFromValuePair(ShaderConstants::Attribute10Index,
138 "Attribute10Index");
140 this->addToValuePair ("Attribute11Index",
141 ShaderConstants::Attribute11Index);
142 this->addFromValuePair(ShaderConstants::Attribute11Index,
143 "Attribute11Index");
145 this->addToValuePair ("Attribute12Index",
146 ShaderConstants::Attribute12Index);
147 this->addFromValuePair(ShaderConstants::Attribute12Index,
148 "Attribute12Index");
150 this->addToValuePair ("Attribute13Index",
151 ShaderConstants::Attribute13Index);
152 this->addFromValuePair(ShaderConstants::Attribute13Index,
153 "Attribute13Index");
155 this->addToValuePair ("Attribute14Index",
156 ShaderConstants::Attribute14Index);
157 this->addFromValuePair(ShaderConstants::Attribute14Index,
158 "Attribute14Index");
160 this->addToValuePair ("Attribute15Index",
161 ShaderConstants::Attribute15Index);
162 this->addFromValuePair(ShaderConstants::Attribute15Index,
163 "Attribute15Index");
166 void FieldTraits<ShaderAttribute>::putToStream(const ShaderAttribute &val,
167 OutStream &outStr)
169 const std::string &fVal = ShaderAttrIndexMapper::the()->toString(val.first);
171 outStr << "\"";
172 outStr << fVal;
173 outStr << " ";
174 outStr << val.second;
176 outStr << "\"";
180 bool FieldTraits<ShaderAttribute>::getFromCString(
181 ShaderAttribute &outVal,
182 const Char8 *&inVal)
184 char *szSaveTok = NULL;
186 #ifndef WIN32
187 char *szTok = strtok_r(const_cast<Char8 *>(inVal),
188 " \t\n",
189 &szSaveTok);
190 #else
191 char *szTok = strtok_s(const_cast<Char8 *>(inVal),
192 " \t\n",
193 &szSaveTok);
194 #endif
196 std::string attrName;
197 std::string attrVal;
199 if(szTok != NULL)
201 attrName = szTok;
203 else
205 return false;
208 #ifndef WIN32
209 szTok = strtok_r(NULL, " \t\n", &szSaveTok);
210 #else
211 szTok = strtok_s(NULL, " \t\n", &szSaveTok);
212 #endif
213 if(szTok != NULL)
215 attrVal = szTok;
217 else
219 return false;
222 outVal.first = ShaderAttrIndexMapper::the()->fromString(attrName.c_str());
223 outVal.second = attrVal;
225 return true;
228 OSG_END_NAMESPACE