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 #ifndef _OSGCOLLADAEFFECT_H_
40 #define _OSGCOLLADAEFFECT_H_
42 #include "OSGConfig.h"
44 #if defined(OSG_WITH_COLLADA) || defined(OSG_DO_DOC)
46 #include "OSGColladaInstantiableElement.h"
47 #include "OSGColladaElementFactoryHelper.h"
48 #include "OSGColladaInstInfo.h"
49 #include "OSGColladaSampler2D.h"
50 #include "OSGColladaSurface.h"
51 #include "OSGColladaTexture.h"
52 #include "OSGMaterial.h"
54 #include <dom/domImage.h>
55 #include <dom/domFx_sampler2D_common.h>
56 #include <dom/domFx_surface_common.h>
57 #include <dom/domCommon_color_or_texture_type.h>
58 #include <dom/domCommon_float_or_param_type.h>
59 #include <dom/domCommon_transparent_type.h>
61 #ifdef OSG_WITH_COLLADA_NAMESPACE
62 namespace ColladaDOM141
{
66 class domProfile_COMMON
;
67 class domProfile_GLSL
;
70 class domInstance_effect
;
72 #ifdef OSG_WITH_COLLADA_NAMESPACE
79 class ColladaInstanceEffect
;
80 class ColladaMaterial
;
84 OSG_GEN_CONTAINERPTR(BlendChunk
);
87 OSG_GEN_CONTAINERPTR(DepthChunk
);
89 /*! \ingroup GrpFileIOCollada
93 class OSG_FILEIO_DLLMAPPING ColladaEffect
: public ColladaInstantiableElement
95 /*========================== PUBLIC =================================*/
99 /*---------------------------------------------------------------------*/
103 typedef ColladaInstantiableElement Inherited
;
104 typedef ColladaEffect Self
;
106 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaEffect
);
108 class ColladaEffectInstInfo
: public ColladaInstInfo
110 /*========================== PUBLIC =============================*/
114 /*-----------------------------------------------------------------*/
118 typedef ColladaInstInfo Inherited
;
119 typedef ColladaEffectInstInfo Self
;
121 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaEffectInstInfo
);
124 /*-----------------------------------------------------------------*/
128 static ColladaInstInfoTransitPtr
129 create(ColladaMaterial
*colInstParent
,
130 ColladaInstanceEffect
*colInst
);
133 /*-----------------------------------------------------------------*/
137 virtual void process(void);
140 /*========================= PROTECTED ===========================*/
144 /*-----------------------------------------------------------------*/
145 /*! \name Constructors/Destructor */
148 ColladaEffectInstInfo (ColladaMaterial
*colInstParent
,
149 ColladaInstanceEffect
*colInst
);
150 virtual ~ColladaEffectInstInfo(void );
153 /*-----------------------------------------------------------------*/
156 OSG_GEN_MEMOBJPTR(ColladaEffectInstInfo
);
159 /*---------------------------------------------------------------------*/
165 EmissionTexture
= 0x0000,
166 AmbientTexture
= 0x0001,
167 DiffuseTexture
= 0x0002,
168 SpecularTexture
= 0x0003,
169 TransparentTexture
= 0x0004,
170 BumpTexture
= 0x0005,
176 /*---------------------------------------------------------------------*/
180 static ColladaElementTransitPtr
create(daeElement
*elem
,
181 ColladaGlobal
*global
);
184 /*---------------------------------------------------------------------*/
188 virtual void read (ColladaElement
*colElemParent
);
189 virtual Material
*createInstance(ColladaInstInfo
*colInstInfo
);
192 /*---------------------------------------------------------------------*/
196 virtual daeElement
*findDOMParam(const std::string
&name
) const;
197 virtual ColladaElement
*findParam (const std::string
&name
) const;
200 /*---------------------------------------------------------------------*/
204 virtual void setTexture(
205 TextureTarget eTarget
,
206 ColladaTexture
*pColTexture
,
207 domCommon_color_or_texture_type::domTexture
*pDomTexture
= NULL
);
210 /*========================= PROTECTED ===============================*/
214 /*---------------------------------------------------------------------*/
218 // <sampler2D> DOM and loader objects
222 struct ParamSampler2D
224 ColladaSampler2DRefPtr colSampler2D
;
225 domFx_sampler2D_commonRef sampler2D
;
227 ParamSampler2D(void) : colSampler2D(NULL
), sampler2D(NULL
) {}
230 // <surface> DOM and loader objects
236 ColladaSurfaceRefPtr colSurface
;
237 domFx_surface_commonRef surface
;
239 ParamSurface(void) : colSurface(NULL
), surface(NULL
) {}
242 // <texture> DOM and loader objects
248 ColladaTextureRefPtr colTexture
;
249 domCommon_color_or_texture_type::domTextureRef texture
;
251 ParamTexture(void) : colTexture(), texture(NULL
) {}
254 typedef std::map
<std::string
, ParamSampler2D
> ParamSampler2DMap
;
255 typedef ParamSampler2DMap::iterator ParamSampler2DMapIt
;
256 typedef ParamSampler2DMap::const_iterator ParamSampler2DMapConstIt
;
258 typedef std::map
<std::string
, ParamSurface
> ParamSurfaceMap
;
259 typedef ParamSurfaceMap::iterator ParamSurfaceMapIt
;
260 typedef ParamSurfaceMap::const_iterator ParamSurfaceMapConstIt
;
262 typedef domCommon_newparam_type_Array CommonParamArray
;
264 typedef std::vector
<ParamTexture
> ParamTextureList
;
265 typedef ParamTextureList::iterator ParamTextureListIt
;
266 typedef ParamTextureList::const_iterator ParamTextureListConstIt
;
269 /*---------------------------------------------------------------------*/
270 /*! \name Constructors/Destructor */
273 ColladaEffect(daeElement
*elem
, ColladaGlobal
*global
);
274 virtual ~ColladaEffect(void );
277 /*---------------------------------------------------------------------*/
278 /*! \name Profile Handlers */
281 virtual void readImageArray (const domImage_Array
&images
);
282 virtual void readNewParams (const CommonParamArray
&newParams
);
284 virtual void readProfileCommon( domProfile_COMMON
*prof
);
285 virtual void readProfileGLSL ( domProfile_GLSL
*prof
);
286 virtual void readProfileCG ( domProfile_CG
*prof
);
288 virtual void readTextureParams(
289 domCommon_color_or_texture_type::domTexture
*texture
,
290 TextureTarget target
);
292 virtual MaterialTransitPtr
createInstanceProfileCommon(
293 domProfile_COMMON
*prof
,
295 domInstance_effect
*instEffect
);
297 virtual MaterialTransitPtr
createInstanceProfileGLSL (
298 domProfile_GLSL
*prof
,
300 domInstance_effect
*instEffect
);
302 virtual MaterialTransitPtr
createInstanceProfileCG (
305 domInstance_effect
*instEffect
);
308 /*---------------------------------------------------------------------*/
310 void handleProfileCommonEmission(
311 domCommon_color_or_texture_type
*emission
,
312 MaterialChunk
*matChunk
);
314 void handleProfileCommonAmbient(
315 domCommon_color_or_texture_type
*ambient
,
316 ColladaInstanceEffect
*colInstEffect
,
318 MaterialChunk
*matChunk
,
319 BlendChunkUnrecPtr
&blendChunk
,
320 DepthChunkUnrecPtr
&depthChunk
,
323 void handleProfileCommonDiffuse(
324 domCommon_color_or_texture_type
*diffuse
,
325 ColladaInstanceEffect
*colInstEffect
,
327 MaterialChunk
*matChunk
,
328 BlendChunkUnrecPtr
&blendChunk
,
329 DepthChunkUnrecPtr
&depthChunk
,
332 void handleProfileCommonSpecular(
333 domCommon_color_or_texture_type
*specular
,
334 MaterialChunk
*matChunk
);
336 virtual void fillColorParamTex (
337 domCommon_color_or_texture_type
*colTex
,
338 domCommon_color_or_texture_type::domColorRef
&colOut
,
339 domCommon_color_or_texture_type::domParamRef
¶mOut
,
340 domCommon_color_or_texture_type::domTextureRef
&texOut
);
342 virtual void fillColorParamTex (
343 domCommon_transparent_type
*colTex
,
344 domCommon_color_or_texture_type::domColorRef
&colOut
,
345 domCommon_color_or_texture_type::domParamRef
¶mOut
,
346 domCommon_color_or_texture_type::domTextureRef
&texOut
);
348 virtual void fillFloatParam (
349 domCommon_float_or_param_type
*floatParam
,
350 domCommon_float_or_param_type::domFloatRef
&floatOut
,
351 domCommon_float_or_param_type::domParamRef
¶mOut
);
353 virtual void addTexture(const std::string
&tcSemantic
,
354 ColladaInstanceEffect
*colInstEffect
,
355 ColladaTexture
*colTexture
,
360 virtual Real32
luminance(const Color4f
&col
);
362 static ColladaElementRegistrationHelper _regHelper
;
364 ParamSampler2DMap _sampler2DParams
;
365 ParamSurfaceMap _surfaceParams
;
366 ParamTextureList _textures
;
368 ExtraHandlerStore _extraHandlers
;
371 OSG_GEN_MEMOBJPTR(ColladaEffect
);
375 // #include "OSGColladaEffect.inl"
377 #endif // OSG_WITH_COLLADA
379 #endif // _OSGCOLLADAEFFECT_H_