fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaSampler2D.cpp
blob6167981306d1ffcac0ade96e964132339260d781
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 "OSGColladaSampler2D.h"
45 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
47 #include "OSGColladaLog.h"
48 #include "OSGColladaGlobal.h"
49 #include "OSGColladaEffect.h"
50 #include "OSGColladaSurface.h"
52 #include <dom/domFx_sampler2D_common.h>
54 OSG_BEGIN_NAMESPACE
56 ColladaElementRegistrationHelper ColladaSampler2D::_regHelper(
57 &ColladaSampler2D::create,
58 "sampler2D" );
61 ColladaElementTransitPtr ColladaSampler2D::create(daeElement *elem,
62 ColladaGlobal *global)
64 return ColladaElementTransitPtr(new ColladaSampler2D(elem, global));
67 void ColladaSampler2D::read(ColladaElement *colElemParent)
69 OSG_COLLADA_LOG(("OSGColladaSampler2D::read\n"));
71 #if 0
73 _texObj = TextureObjChunk::create();
74 _texObj->setImage(colSurface->getImage());
76 getGlobal()->getStatCollector()->getElem(
77 ColladaGlobal::statNTextureCreated)->inc();
79 #endif
82 ColladaSurface *ColladaSampler2D::getSurface(void) const
84 domFx_sampler2D_commonRef sampler2D =
85 this->getDOMElementAs<domFx_sampler2D_common>();
87 domFx_sampler2D_common::domSourceRef source = sampler2D->getSource();
89 if(_colEffect == NULL)
91 SWARNING << "ColladaSampler2D::read: No effect set, can not resolve "
92 << "<source> elements." << std::endl;
93 return NULL;
96 ColladaElement *colElem = _colEffect->findParam(source->getValue());
97 ColladaSurface *colSurface = dynamic_cast<ColladaSurface *>(colElem);
99 if(colElem == NULL || colSurface == NULL)
101 SWARNING << "ColladaSampler2D::read: Could not resolve <source> ["
102 << source->getValue() << "]." << std::endl;
104 return NULL;
107 return colSurface;
110 void ColladaSampler2D::setupTexObj(TextureObjChunk *pTex)
112 if(pTex == NULL)
113 return;
115 domFx_sampler2D_commonRef sampler2D =
116 this->getDOMElementAs<domFx_sampler2D_common>();
118 if(sampler2D->getWrap_s() != NULL)
120 switch(sampler2D->getWrap_s()->getValue())
122 case FX_SAMPLER_WRAP_COMMON_NONE:
123 pTex->setWrapS(GL_CLAMP_TO_BORDER);
124 break;
126 case FX_SAMPLER_WRAP_COMMON_WRAP:
127 pTex->setWrapS(GL_REPEAT);
128 break;
130 case FX_SAMPLER_WRAP_COMMON_MIRROR:
131 pTex->setWrapS(GL_MIRRORED_REPEAT);
132 break;
134 case FX_SAMPLER_WRAP_COMMON_CLAMP:
135 pTex->setWrapS(GL_CLAMP_TO_EDGE);
136 break;
138 case FX_SAMPLER_WRAP_COMMON_BORDER:
139 pTex->setWrapS(GL_CLAMP_TO_BORDER);
140 break;
142 case FX_SAMPLER_WRAP_COMMON_COUNT:
143 SWARNING << "OSGColladaSampler2D::read <wrap_s> "
144 << "FX_SAMPLER_WRAP_COMMON_COUNT not handled"
145 << std::endl;
146 break;
150 if(sampler2D->getWrap_t() != NULL)
152 switch(sampler2D->getWrap_t()->getValue())
154 case FX_SAMPLER_WRAP_COMMON_NONE:
155 pTex->setWrapT(GL_CLAMP_TO_BORDER);
156 break;
158 case FX_SAMPLER_WRAP_COMMON_WRAP:
159 pTex->setWrapT(GL_REPEAT);
160 break;
162 case FX_SAMPLER_WRAP_COMMON_MIRROR:
163 pTex->setWrapT(GL_MIRRORED_REPEAT);
164 break;
166 case FX_SAMPLER_WRAP_COMMON_CLAMP:
167 pTex->setWrapT(GL_CLAMP_TO_EDGE);
168 break;
170 case FX_SAMPLER_WRAP_COMMON_BORDER:
171 pTex->setWrapT(GL_CLAMP_TO_BORDER);
172 break;
174 case FX_SAMPLER_WRAP_COMMON_COUNT:
175 SWARNING << "OSGColladaSampler2D::read <wrap_t> "
176 << "FX_SAMPLER_WRAP_COMMON_COUNT not handled"
177 << std::endl;
178 break;
183 ColladaEffect *ColladaSampler2D::getEffect(void) const
185 return _colEffect;
188 void ColladaSampler2D::setEffect(ColladaEffect *colEffect)
190 _colEffect = colEffect;
194 ColladaSampler2D::ColladaSampler2D(daeElement *elem, ColladaGlobal *global) :
195 Inherited(elem,
196 global),
197 _colEffect(NULL )
201 ColladaSampler2D::~ColladaSampler2D(void)
205 OSG_END_NAMESPACE
207 #endif // OSG_WITH_COLLADA