fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaInstanceMaterial.cpp
blob591fa0c49a3ac820c6e37bb82202a3f0b0cdb4eb
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2009 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 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
40 #pragma GCC diagnostic ignored "-Wold-style-cast"
41 #endif
43 #include "OSGColladaInstanceMaterial.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaLog.h"
48 #include "OSGColladaInstanceEffect.h"
50 #include <dom/domInstance_material.h>
52 OSG_BEGIN_NAMESPACE
54 ColladaElementRegistrationHelper ColladaInstanceMaterial::_regHelper(
55 &ColladaInstanceMaterial::create, "instance_material");
57 ColladaElementTransitPtr
58 ColladaInstanceMaterial::create(daeElement *elem, ColladaGlobal *global)
60 return ColladaElementTransitPtr(new ColladaInstanceMaterial(elem, global));
63 void
64 ColladaInstanceMaterial::read(ColladaElement *colElemParent)
66 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read\n"));
68 domInstance_materialRef instMat =
69 getDOMElementAs<domInstance_material>();
70 ColladaMaterialRefPtr colMat = getTargetElem();
72 if(colMat == NULL)
74 colMat = dynamic_pointer_cast<ColladaMaterial>(
75 ColladaElementFactory::the()->create(
76 getTargetDOMElem(), getGlobal()));
78 colMat->read(this);
81 if(instMat->getSymbol() != NULL)
83 _symbol = instMat->getSymbol();
85 else
87 SFATAL << "ColladaInstanceMaterial::read: No symbol."
88 << std::endl;
91 _target = instMat->getTarget().str();
93 const domInstance_material::domBind_Array &binds =
94 instMat->getBind_array();
96 _bindStore.resize(binds.getCount());
98 for(UInt32 i = 0; i < binds.getCount(); ++i)
100 std::string target = binds[i]->getTarget();
101 std::string semantic;
103 if(binds[i]->getSemantic() != NULL)
105 semantic = binds[i]->getSemantic();
108 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read: "
109 "<bind> semantic [%s] target [%s]\n",
110 semantic.c_str(), target.c_str()));
112 _bindStore[i].semantic = semantic;
113 _bindStore[i].target = target;
116 const domInstance_material::domBind_vertex_input_Array &bindVerts =
117 instMat->getBind_vertex_input_array();
119 _bindVertexStore.resize(bindVerts.getCount());
121 for(UInt32 i = 0; i < bindVerts.getCount(); ++i)
123 std::string semantic = bindVerts[i]->getSemantic ();
124 std::string inSemantic = bindVerts[i]->getInput_semantic();
125 UInt32 inSet = bindVerts[i]->getInput_set ();
127 OSG_COLLADA_LOG(("ColladaInstanceMaterial::read "
128 "<bind_vertex_input> semantic [%s] "
129 "inSemantic [%s] inSet [%d]\n",
130 semantic.c_str(), inSemantic.c_str(), inSet));
132 _bindVertexStore[i].semantic = semantic;
133 _bindVertexStore[i].inSemantic = inSemantic;
134 _bindVertexStore[i].inSet = inSet;
138 ColladaMaterial *
139 ColladaInstanceMaterial::getTargetElem(void) const
141 ColladaMaterial *retVal = NULL;
142 domMaterialRef targetElem = getTargetDOMElem();
144 if(targetElem != NULL)
146 retVal = getUserDataAs<ColladaMaterial>(targetElem);
149 return retVal;
152 domMaterial *
153 ColladaInstanceMaterial::getTargetDOMElem(void) const
155 domMaterialRef retVal = NULL;
156 domInstance_materialRef instMat = getDOMElementAs<domInstance_material>();
158 if(instMat->getTarget().getElement() != NULL)
160 retVal = daeSafeCast<domMaterial>(instMat->getTarget().getElement());
163 return retVal;
166 const std::string &
167 ColladaInstanceMaterial::getSymbol(void) const
169 return _symbol;
172 const std::string &
173 ColladaInstanceMaterial::getTarget(void) const
175 return _target;
178 const ColladaInstanceMaterial::BindStore &
179 ColladaInstanceMaterial::getBindStore(void) const
181 return _bindStore;
184 const ColladaInstanceMaterial::BindInfo *
185 ColladaInstanceMaterial::findBindInfo(const std::string &semantic) const
187 const BindInfo *retVal = NULL;
189 for(UInt32 i = 0; i < _bindStore.size(); ++i)
191 if(_bindStore[i].semantic == semantic)
193 retVal = &_bindStore[i];
194 break;
198 return retVal;
201 const ColladaInstanceMaterial::BindVertexStore &
202 ColladaInstanceMaterial::getBindVertexStore(void) const
204 return _bindVertexStore;
207 const ColladaInstanceMaterial::BindVertexInfo *
208 ColladaInstanceMaterial::findBindVertexInfo(
209 const std::string &inSemantic, UInt32 inSet) const
211 const BindVertexInfo *retVal = NULL;
213 for(UInt32 i = 0; i < _bindVertexStore.size(); ++i)
215 if(_bindVertexStore[i].inSemantic == inSemantic &&
216 _bindVertexStore[i].inSet == inSet )
218 retVal = &_bindVertexStore[i];
219 break;
223 return retVal;
226 ColladaInstanceEffect *
227 ColladaInstanceMaterial::getInstanceEffect(void) const
229 domMaterialRef material = getTargetDOMElem ();
230 domInstance_effectRef instEffect = material->getInstance_effect();
232 return getUserDataAs<ColladaInstanceEffect>(instEffect);
235 ColladaInstanceMaterial::ColladaInstanceMaterial(
236 daeElement *elem, ColladaGlobal *global)
238 : Inherited (elem, global)
239 , _symbol ()
240 , _target ()
241 , _bindStore ()
242 , _bindVertexStore()
246 ColladaInstanceMaterial::~ColladaInstanceMaterial(void)
250 OSG_END_NAMESPACE
252 #endif // OSG_WITH_COLLADA