1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2009 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 #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
40 #pragma GCC diagnostic ignored "-Wold-style-cast"
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>
56 ColladaElementRegistrationHelper
ColladaSampler2D::_regHelper(
57 &ColladaSampler2D::create
,
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"));
73 _texObj
= TextureObjChunk::create();
74 _texObj
->setImage(colSurface
->getImage());
76 getGlobal()->getStatCollector()->getElem(
77 ColladaGlobal::statNTextureCreated
)->inc();
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
;
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
;
110 void ColladaSampler2D::setupTexObj(TextureObjChunk
*pTex
)
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
);
126 case FX_SAMPLER_WRAP_COMMON_WRAP
:
127 pTex
->setWrapS(GL_REPEAT
);
130 case FX_SAMPLER_WRAP_COMMON_MIRROR
:
131 pTex
->setWrapS(GL_MIRRORED_REPEAT
);
134 case FX_SAMPLER_WRAP_COMMON_CLAMP
:
135 pTex
->setWrapS(GL_CLAMP_TO_EDGE
);
138 case FX_SAMPLER_WRAP_COMMON_BORDER
:
139 pTex
->setWrapS(GL_CLAMP_TO_BORDER
);
142 case FX_SAMPLER_WRAP_COMMON_COUNT
:
143 SWARNING
<< "OSGColladaSampler2D::read <wrap_s> "
144 << "FX_SAMPLER_WRAP_COMMON_COUNT not handled"
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
);
158 case FX_SAMPLER_WRAP_COMMON_WRAP
:
159 pTex
->setWrapT(GL_REPEAT
);
162 case FX_SAMPLER_WRAP_COMMON_MIRROR
:
163 pTex
->setWrapT(GL_MIRRORED_REPEAT
);
166 case FX_SAMPLER_WRAP_COMMON_CLAMP
:
167 pTex
->setWrapT(GL_CLAMP_TO_EDGE
);
170 case FX_SAMPLER_WRAP_COMMON_BORDER
:
171 pTex
->setWrapT(GL_CLAMP_TO_BORDER
);
174 case FX_SAMPLER_WRAP_COMMON_COUNT
:
175 SWARNING
<< "OSGColladaSampler2D::read <wrap_t> "
176 << "FX_SAMPLER_WRAP_COMMON_COUNT not handled"
183 ColladaEffect
*ColladaSampler2D::getEffect(void) const
188 void ColladaSampler2D::setEffect(ColladaEffect
*colEffect
)
190 _colEffect
= colEffect
;
194 ColladaSampler2D::ColladaSampler2D(daeElement
*elem
, ColladaGlobal
*global
) :
201 ColladaSampler2D::~ColladaSampler2D(void)
207 #endif // OSG_WITH_COLLADA