1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGShaderAttribute.h"
40 #include "OSGShaderAttributeFields.h"
42 #include "OSGMField.ins"
44 #include "OSGSingletonHolder.ins"
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) :
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
,
90 this->addToValuePair ("Attribute1Index",
91 ShaderConstants::Attribute1Index
);
92 this->addFromValuePair(ShaderConstants::Attribute1Index
,
95 this->addToValuePair ("Attribute2Index",
96 ShaderConstants::Attribute2Index
);
97 this->addFromValuePair(ShaderConstants::Attribute2Index
,
100 this->addToValuePair ("Attribute3Index",
101 ShaderConstants::Attribute3Index
);
102 this->addFromValuePair(ShaderConstants::Attribute3Index
,
105 this->addToValuePair ("Attribute4Index",
106 ShaderConstants::Attribute4Index
);
107 this->addFromValuePair(ShaderConstants::Attribute4Index
,
110 this->addToValuePair ("Attribute5Index",
111 ShaderConstants::Attribute5Index
);
112 this->addFromValuePair(ShaderConstants::Attribute5Index
,
115 this->addToValuePair ("Attribute6Index",
116 ShaderConstants::Attribute6Index
);
117 this->addFromValuePair(ShaderConstants::Attribute6Index
,
120 this->addToValuePair ("Attribute7Index",
121 ShaderConstants::Attribute7Index
);
122 this->addFromValuePair(ShaderConstants::Attribute7Index
,
125 this->addToValuePair ("Attribute8Index",
126 ShaderConstants::Attribute8Index
);
127 this->addFromValuePair(ShaderConstants::Attribute8Index
,
130 this->addToValuePair ("Attribute9Index",
131 ShaderConstants::Attribute9Index
);
132 this->addFromValuePair(ShaderConstants::Attribute9Index
,
135 this->addToValuePair ("Attribute10Index",
136 ShaderConstants::Attribute10Index
);
137 this->addFromValuePair(ShaderConstants::Attribute10Index
,
140 this->addToValuePair ("Attribute11Index",
141 ShaderConstants::Attribute11Index
);
142 this->addFromValuePair(ShaderConstants::Attribute11Index
,
145 this->addToValuePair ("Attribute12Index",
146 ShaderConstants::Attribute12Index
);
147 this->addFromValuePair(ShaderConstants::Attribute12Index
,
150 this->addToValuePair ("Attribute13Index",
151 ShaderConstants::Attribute13Index
);
152 this->addFromValuePair(ShaderConstants::Attribute13Index
,
155 this->addToValuePair ("Attribute14Index",
156 ShaderConstants::Attribute14Index
);
157 this->addFromValuePair(ShaderConstants::Attribute14Index
,
160 this->addToValuePair ("Attribute15Index",
161 ShaderConstants::Attribute15Index
);
162 this->addFromValuePair(ShaderConstants::Attribute15Index
,
166 void FieldTraits
<ShaderAttribute
>::putToStream(const ShaderAttribute
&val
,
169 const std::string
&fVal
= ShaderAttrIndexMapper::the()->toString(val
.first
);
174 outStr
<< val
.second
;
180 bool FieldTraits
<ShaderAttribute
>::getFromCString(
181 ShaderAttribute
&outVal
,
184 char *szSaveTok
= NULL
;
187 char *szTok
= strtok_r(const_cast<Char8
*>(inVal
),
191 char *szTok
= strtok_s(const_cast<Char8
*>(inVal
),
196 std::string attrName
;
209 szTok
= strtok_r(NULL
, " \t\n", &szSaveTok
);
211 szTok
= strtok_s(NULL
, " \t\n", &szSaveTok
);
222 outVal
.first
= ShaderAttrIndexMapper::the()->fromString(attrName
.c_str());
223 outVal
.second
= attrVal
;