fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Collada / OSGColladaEffect.h
blob480794c8754ef57c112e8e46934e81ae6b605ab5
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 #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 {
63 #endif
65 // forward decl
66 class domProfile_COMMON;
67 class domProfile_GLSL;
68 class domProfile_CG;
69 class domEffect;
70 class domInstance_effect;
72 #ifdef OSG_WITH_COLLADA_NAMESPACE
74 #endif
76 OSG_BEGIN_NAMESPACE
78 // forward decl
79 class ColladaInstanceEffect;
80 class ColladaMaterial;
81 class ChunkMaterial;
82 class MaterialChunk;
83 class BlendChunk;
84 OSG_GEN_CONTAINERPTR(BlendChunk);
86 class DepthChunk;
87 OSG_GEN_CONTAINERPTR(DepthChunk);
89 /*! \ingroup GrpFileIOCollada
90 \nohierarchy
93 class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
95 /*========================== PUBLIC =================================*/
97 public:
99 /*---------------------------------------------------------------------*/
100 /*! \name Types */
101 /*! \{ */
103 typedef ColladaInstantiableElement Inherited;
104 typedef ColladaEffect Self;
106 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaEffect);
108 class ColladaEffectInstInfo : public ColladaInstInfo
110 /*========================== PUBLIC =============================*/
112 public:
114 /*-----------------------------------------------------------------*/
115 /*! \name Types */
116 /*! \{ */
118 typedef ColladaInstInfo Inherited;
119 typedef ColladaEffectInstInfo Self;
121 OSG_GEN_INTERNAL_MEMOBJPTR(ColladaEffectInstInfo);
123 /*! \} */
124 /*-----------------------------------------------------------------*/
125 /*! \name Create */
126 /*! \{ */
128 static ColladaInstInfoTransitPtr
129 create(ColladaMaterial *colInstParent,
130 ColladaInstanceEffect *colInst );
132 /*! \} */
133 /*-----------------------------------------------------------------*/
134 /*! \name Process */
135 /*! \{ */
137 virtual void process(void);
139 /*! \} */
140 /*========================= PROTECTED ===========================*/
142 protected:
144 /*-----------------------------------------------------------------*/
145 /*! \name Constructors/Destructor */
146 /*! \{ */
148 ColladaEffectInstInfo (ColladaMaterial *colInstParent,
149 ColladaInstanceEffect *colInst );
150 virtual ~ColladaEffectInstInfo(void );
152 /*! \} */
153 /*-----------------------------------------------------------------*/
156 OSG_GEN_MEMOBJPTR(ColladaEffectInstInfo);
158 /*! \} */
159 /*---------------------------------------------------------------------*/
160 /*! \name Create */
161 /*! \{ */
163 enum TextureTarget
165 EmissionTexture = 0x0000,
166 AmbientTexture = 0x0001,
167 DiffuseTexture = 0x0002,
168 SpecularTexture = 0x0003,
169 TransparentTexture = 0x0004,
170 BumpTexture = 0x0005,
172 LastTexture = 0x0006
175 /*! \} */
176 /*---------------------------------------------------------------------*/
177 /*! \name Create */
178 /*! \{ */
180 static ColladaElementTransitPtr create(daeElement *elem,
181 ColladaGlobal *global);
183 /*! \} */
184 /*---------------------------------------------------------------------*/
185 /*! \name Reading */
186 /*! \{ */
188 virtual void read (ColladaElement *colElemParent);
189 virtual Material *createInstance(ColladaInstInfo *colInstInfo );
191 /*! \} */
192 /*---------------------------------------------------------------------*/
193 /*! \name Access */
194 /*! \{ */
196 virtual daeElement *findDOMParam(const std::string &name) const;
197 virtual ColladaElement *findParam (const std::string &name) const;
199 /*! \} */
200 /*---------------------------------------------------------------------*/
201 /*! \name Access */
202 /*! \{ */
204 virtual void setTexture(
205 TextureTarget eTarget,
206 ColladaTexture *pColTexture,
207 domCommon_color_or_texture_type::domTexture *pDomTexture = NULL);
209 /*! \} */
210 /*========================= PROTECTED ===============================*/
212 protected:
214 /*---------------------------------------------------------------------*/
215 /*! \name Types */
216 /*! \{ */
218 // <sampler2D> DOM and loader objects
219 /*! \nohierarchy
222 struct ParamSampler2D
224 ColladaSampler2DRefPtr colSampler2D;
225 domFx_sampler2D_commonRef sampler2D;
227 ParamSampler2D(void) : colSampler2D(NULL), sampler2D(NULL) {}
230 // <surface> DOM and loader objects
231 /*! \nohierarchy
234 struct ParamSurface
236 ColladaSurfaceRefPtr colSurface;
237 domFx_surface_commonRef surface;
239 ParamSurface(void) : colSurface(NULL), surface(NULL) {}
242 // <texture> DOM and loader objects
243 /*! \nohierarchy
246 struct ParamTexture
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;
268 /*! \} */
269 /*---------------------------------------------------------------------*/
270 /*! \name Constructors/Destructor */
271 /*! \{ */
273 ColladaEffect(daeElement *elem, ColladaGlobal *global);
274 virtual ~ColladaEffect(void );
276 /*! \} */
277 /*---------------------------------------------------------------------*/
278 /*! \name Profile Handlers */
279 /*! \{ */
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,
294 domEffect *effect,
295 domInstance_effect *instEffect );
297 virtual MaterialTransitPtr createInstanceProfileGLSL (
298 domProfile_GLSL *prof,
299 domEffect *effect,
300 domInstance_effect *instEffect );
302 virtual MaterialTransitPtr createInstanceProfileCG (
303 domProfile_CG *prof,
304 domEffect *effect,
305 domInstance_effect *instEffect );
307 /*! \} */
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,
317 ChunkMaterial *mat,
318 MaterialChunk *matChunk,
319 BlendChunkUnrecPtr &blendChunk,
320 DepthChunkUnrecPtr &depthChunk,
321 UInt32 &texCount );
323 void handleProfileCommonDiffuse(
324 domCommon_color_or_texture_type *diffuse,
325 ColladaInstanceEffect *colInstEffect,
326 ChunkMaterial *mat,
327 MaterialChunk *matChunk,
328 BlendChunkUnrecPtr &blendChunk,
329 DepthChunkUnrecPtr &depthChunk,
330 UInt32 &texCount );
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 &paramOut,
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 &paramOut,
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 &paramOut );
353 virtual void addTexture(const std::string &tcSemantic,
354 ColladaInstanceEffect *colInstEffect,
355 ColladaTexture *colTexture,
356 ChunkMaterial *mat,
357 GLenum envMode,
358 UInt32 &texCount );
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);
373 OSG_END_NAMESPACE
375 // #include "OSGColladaEffect.inl"
377 #endif // OSG_WITH_COLLADA
379 #endif // _OSGCOLLADAEFFECT_H_