fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaMaterial.cpp
blobb9380bc20dc79287e6d05da9d257164951b8c306
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 "OSGColladaMaterial.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaGlobal.h"
48 #include "OSGColladaInstanceEffect.h"
49 #include "OSGColladaInstanceMaterial.h"
50 #include "OSGColladaLog.h"
51 #include "OSGNameAttachment.h"
53 #include <dom/domMaterial.h>
54 #include <dom/domInstance_effect.h>
56 OSG_BEGIN_NAMESPACE
58 ColladaInstInfoTransitPtr
59 ColladaMaterial::ColladaMaterialInstInfo::create(
60 ColladaElement *colInstParent, ColladaInstanceMaterial *colInst)
62 return ColladaInstInfoTransitPtr(
63 new ColladaMaterialInstInfo(colInstParent, colInst));
66 void
67 ColladaMaterial::ColladaMaterialInstInfo::process(void)
69 SFATAL << "ColladaMaterialInstInfo::process called!" << std::endl;
72 ColladaMaterial::ColladaMaterialInstInfo::ColladaMaterialInstInfo(
73 ColladaElement *colInstParent, ColladaInstanceMaterial *colInst)
75 : Inherited(colInstParent, colInst)
79 ColladaMaterial::ColladaMaterialInstInfo::~ColladaMaterialInstInfo(void)
83 // ===========================================================================
85 ColladaElementRegistrationHelper ColladaMaterial::_regHelper(
86 &ColladaMaterial::create, "material");
89 ColladaElementTransitPtr
90 ColladaMaterial::create(daeElement *elem, ColladaGlobal *global)
92 return ColladaElementTransitPtr(new ColladaMaterial(elem, global));
95 void
96 ColladaMaterial::read(ColladaElement *colElemParent)
98 OSG_COLLADA_LOG(("ColladaMaterial::read\n"));
100 domMaterialRef material = getDOMElementAs<domMaterial>();
101 domInstance_effectRef instEffect = material->getInstance_effect();
102 ColladaInstanceEffectRefPtr colInstEffect =
103 getUserDataAs<ColladaInstanceEffect>(instEffect);
105 if(colInstEffect == NULL)
107 colInstEffect = dynamic_pointer_cast<ColladaInstanceEffect>(
108 ColladaElementFactory::the()->create(instEffect, getGlobal()));
110 colInstEffect->read(this);
114 Material *
115 ColladaMaterial::createInstance(ColladaInstInfo *colInstInfo)
117 OSG_COLLADA_LOG(("ColladaMaterial::createInstance\n"));
119 MaterialUnrecPtr retVal = NULL;
120 domMaterialRef material = getDOMElementAs<domMaterial>();
121 domInstance_effectRef instEffect = material->getInstance_effect();
122 ColladaInstanceEffectRefPtr colInstEffect =
123 getUserDataAs<ColladaInstanceEffect>(instEffect);
125 if(getInstStore().empty() == true)
127 OSG_ASSERT(colInstEffect != NULL);
128 OSG_ASSERT(colInstEffect->getTargetElem() != NULL);
130 ColladaInstInfoRefPtr colEffectInstInfo =
131 ColladaEffect::ColladaEffectInstInfo::create(this, colInstEffect);
133 retVal = colInstEffect->getTargetElem()->createInstance(
134 colEffectInstInfo);
136 if(getGlobal()->getOptions()->getCreateNameAttachments() == true &&
137 material->getName() != NULL )
139 setName(retVal, material->getName());
142 editInstStore().push_back(retVal);
144 else
146 retVal = dynamic_pointer_cast<Material>(getInstStore()[0]);
148 getGlobal()->getStatCollector()->getElem(
149 ColladaGlobal::statNMaterialUsed)->inc();
152 return retVal;
155 ColladaMaterial::ColladaMaterial(daeElement *elem, ColladaGlobal *global)
156 : Inherited(elem, global)
160 ColladaMaterial::~ColladaMaterial(void)
164 OSG_END_NAMESPACE
166 #endif // OSG_WITH_COLLADA