~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAStreamWriter/include/COLLADASWEffectProfile.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
        This file is part of COLLADAStreamWriter.
 
5
        
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#ifndef __COLLADASTREAMWRITER_EFFECT_H__
 
12
#define __COLLADASTREAMWRITER_EFFECT_H__
 
13
 
 
14
#include "COLLADASWPrerequisites.h"
 
15
#include "COLLADASWElementWriter.h"
 
16
#include "COLLADASWExtraTechnique.h"
 
17
#include "COLLADASWColor.h"
 
18
#include "COLLADASWColorOrTexture.h"
 
19
#include "COLLADASWConstants.h"
 
20
#include "COLLADABUURI.h"
 
21
#include <vector>
 
22
#include <map>
 
23
 
 
24
 
 
25
namespace COLLADASW
 
26
{
 
27
 
 
28
    /** A class to write a @a \<profile_COMMON\> element to the stream*/
 
29
    class EffectProfile : public ElementWriter, public BaseExtraTechnique
 
30
    {
 
31
 
 
32
    public:
 
33
 
 
34
        /** The possible profile types. */
 
35
        enum ProfileType
 
36
        {
 
37
            COMMON, 
 
38
            CG,
 
39
            GLES,
 
40
            GLSL
 
41
        };
 
42
 
 
43
        /** The list of the lighting models supported by the COMMON profile of COLLADASW. */
 
44
        enum ShaderType
 
45
        {
 
46
            /** The constant lighting model.
 
47
            This lighting model uses the emissive color everywhere, without
 
48
            any complex lighting calculations. It also uses the translucency
 
49
            factor and the translucency color, by multiplying them together
 
50
            and applying them to your standard alpha channel according to the
 
51
            final lighting color.*/
 
52
            CONSTANT,
 
53
 
 
54
            /** The Lambert lighting model.
 
55
            This lighting model improves on the constant lighting model by
 
56
            using the dot-product between the normalized light vectors and the
 
57
            polygon normals to determine how much light should affect each polygon.
 
58
            This value is multiplied to the diffuse color and (1 + the ambient color). */
 
59
            LAMBERT,
 
60
 
 
61
            /** The Phong lighting model.
 
62
            This lighting model improves on the Lambert lighting model by
 
63
            calculating how much light is reflected by the polygons into the viewer's eye.
 
64
            For this calculation, the shininess, the specular color and the reflectivity is used. */
 
65
            PHONG,
 
66
 
 
67
            /** The Blinn lighting model.
 
68
            This lighting model improves on the Lambert lighting model by
 
69
            calculating how much light is reflected by the polygons into the viewer's eye.
 
70
            For this calculation, the shininess, the specular color and the reflectivity is used. */
 
71
            BLINN,
 
72
 
 
73
            /** Not a valid lighting model. */
 
74
            UNSPECIFIED
 
75
        };
 
76
 
 
77
        enum Opaque
 
78
        {
 
79
            UNSPECIFIED_OPAQUE,
 
80
            A_ONE,
 
81
            RGB_ZERO,
 
82
            A_ZERO,
 
83
            RGB_ONE
 
84
        };
 
85
 
 
86
                typedef std::list< std::pair<String, String> > StringPairList;
 
87
 
 
88
    private:
 
89
 
 
90
        friend class LibraryEffects;
 
91
 
 
92
                struct ExtraColorOrTextureEntry
 
93
                {
 
94
                        ColorOrTexture colorOrTexture;
 
95
                        String elementSid;
 
96
                        StringPairList attributes;
 
97
                };
 
98
 
 
99
                typedef std::map<String, std::vector<ExtraColorOrTextureEntry> > ExtraColorOrTextureEntryByProfileName;
 
100
 
 
101
        /**
 
102
         * A text string containing the unique identifier of the element. 
 
103
         * This value must be unique within the instance document. Optional.
 
104
         */
 
105
        String mEffectProfileId;
 
106
 
 
107
        /** The include sid and uri for the cg profile. */
 
108
        String mIncludeSid;
 
109
        URI mIncludeURI;
 
110
 
 
111
        /** For writing code directly into code tags. */
 
112
        String mCodeSid;
 
113
        String mCode;
 
114
 
 
115
        /** The technique sid that is used, if no other is specified*/
 
116
        static const String DEFAULT_TECHNIQUE_SID;
 
117
 
 
118
        /** The sid of the technique element*/
 
119
        String mTechniqueSid;
 
120
 
 
121
        TagCloser mTechniqueCloser;
 
122
 
 
123
        /** The current profile type. */
 
124
        ProfileType mProfileType;
 
125
 
 
126
        TagCloser mProfileCloser;
 
127
 
 
128
        /** The current shader type. */
 
129
        ShaderType mShaderType;
 
130
 
 
131
        /** The ColorOrTexture-values can be sampled. */
 
132
        ColorOrTexture mEmission;
 
133
        String mEmissionSid;
 
134
 
 
135
        ColorOrTexture mAmbient;
 
136
        String mAmbientSid; 
 
137
 
 
138
        ColorOrTexture mDiffuse;
 
139
        String mDiffuseSid; 
 
140
 
 
141
        ColorOrTexture mSpecular;
 
142
        String mSpecularSid;
 
143
 
 
144
        ColorOrTexture mTransparent;
 
145
        String mTransparentSid;
 
146
 
 
147
        ColorOrTexture mReflective;
 
148
        String mReflectiveSid;
 
149
 
 
150
        /** Just if we want to add an extra technique element to the current effect
 
151
            with the information of a texture. */
 
152
                ExtraColorOrTextureEntryByProfileName mExtraTechniqueColorOrTextureEntries;
 
153
 
 
154
        /** A list with all sampled image ids, which was already written.
 
155
        So you will not sample the same object a second time. */
 
156
        std::vector<String> mSampledImages;
 
157
 
 
158
        double mShininess;
 
159
        String mShininessSid;
 
160
 
 
161
        double mReflectivity;
 
162
        String mReflectivitySid;
 
163
 
 
164
        Opaque mOpaque;
 
165
 
 
166
        double mTransparency;
 
167
        String mTransparencySid;
 
168
 
 
169
        double mIndexOfRefraction;
 
170
        String mIndexOfRefractionSid;
 
171
 
 
172
        /** The extra tag elements under the effect profile. */
 
173
        BaseExtraTechnique mProfileExtra;
 
174
 
 
175
        /** The extra tag elements under the effect profile's technique element. */
 
176
        BaseExtraTechnique mProfileTechniqueExtra;
 
177
 
 
178
        /** The extra tag elements under the effect profile's technique element. */
 
179
        BaseExtraTechnique mProfileTechniqueTextureExtra;
 
180
 
 
181
    public:
 
182
 
 
183
        /** Constructor
 
184
        @param streamWriter The stream writer the @a \<profile_COMMON\> element should be written to
 
185
        */
 
186
        EffectProfile ( StreamWriter* streamWriter, const String& effectProfileId = "" );
 
187
        virtual ~EffectProfile(){};
 
188
 
 
189
        /** The extra tag elements under the effect profile. */
 
190
        BaseExtraTechnique& getProfileExtra () { return mProfileExtra; }
 
191
 
 
192
        /** The extra tag elements under the effect profile's technique element. */
 
193
        BaseExtraTechnique& getProfileTechniqueExtra () { return mProfileTechniqueExtra; }
 
194
 
 
195
        /**
 
196
        * A text string containing the unique identifier of the element. 
 
197
        * This value must be unique within the instance document. Optional.
 
198
        */
 
199
        const COLLADASW::String& getEffectProfileId () const { return mEffectProfileId; }
 
200
        void setEffectProfileId ( const COLLADASW::String& val ) { mEffectProfileId = val; }
 
201
 
 
202
        /** The current profile type. */
 
203
        const EffectProfile::ProfileType& getProfileType () const { return mProfileType; }
 
204
 
 
205
        /** The current profile type. */
 
206
        void setProfileType ( const EffectProfile::ProfileType& val ) { mProfileType = val; }
 
207
 
 
208
        /** Opens the current profile. */
 
209
        void openProfile ();
 
210
 
 
211
        /** Close the current profile. */
 
212
        void closeProfile ();
 
213
 
 
214
        /** Adds the EffectProfile to the stream*/
 
215
        void addProfileElements ();
 
216
 
 
217
        /** Opens a technique element with the given sid.  */
 
218
        void openTechnique ( const String& techniqueSid );
 
219
 
 
220
        /** Close the current technique element. */
 
221
        void closeTechnique ();
 
222
 
 
223
        /** Sets the sid of the @a \<technique\> element*/
 
224
        void setTechniqueSid ( const String& techniqueSid );
 
225
 
 
226
        /** Returns the sid of the @a \<technique\> element*/
 
227
        const String& getTechniqueSid () const;
 
228
 
 
229
        /** Sets the shader type to @a shaderType */
 
230
        void setShaderType( ShaderType shaderType );
 
231
 
 
232
        /** Returns the shader type */
 
233
        ShaderType getShaderType() const;
 
234
 
 
235
        /** Reference to the included file. */
 
236
        void setInclude ( const URI &includeUri, const String &sid="" );
 
237
 
 
238
        const URI & getIncludeURI() { return mIncludeURI; }
 
239
 
 
240
        /** For writing code directly into code tags. */
 
241
        const String& getCode () const;
 
242
        void setCode ( const String &code, const String &sid="" );
 
243
 
 
244
        /** Sets the emission to @a emission */
 
245
        void setEmission( 
 
246
            const ColorOrTexture& emission, 
 
247
            const bool useDefaultSid = false, 
 
248
            const String& sid = "" );
 
249
 
 
250
                /** Returns the default sid used for the emission element*/ 
 
251
                static const String& getEmissionDefaultSid();
 
252
 
 
253
        /** Returns a reference to the emission*/
 
254
        ColorOrTexture& getEmission();
 
255
 
 
256
        /** Sets the ambient to @a ambient */
 
257
        void  setAmbient( 
 
258
            const ColorOrTexture& ambient, 
 
259
            const bool useDefaultSid = false, 
 
260
            const String& sid = "" );
 
261
 
 
262
                /** Returns the default sid used for the ambient element*/ 
 
263
                static const String& getAmbientDefaultSid();
 
264
 
 
265
        /** Returns a reference to ambient*/
 
266
        ColorOrTexture& getAmbient();
 
267
 
 
268
        /** Sets the diffuse to @a diffuse */
 
269
        void  setDiffuse( 
 
270
            const ColorOrTexture& diffuse, 
 
271
            const bool useDefaultSid = false, 
 
272
            const String& sid = "" );
 
273
 
 
274
                /** Returns the default sid used for the diffuse element*/ 
 
275
                static const String& getDiffuseDefaultSid();
 
276
 
 
277
        /** Returns a reference to diffuse*/
 
278
        ColorOrTexture& getDiffuse();
 
279
 
 
280
        /** Sets the specular to @a specular */
 
281
        void  setSpecular( 
 
282
            const ColorOrTexture& specular, 
 
283
            const bool useDefaultSid = false, 
 
284
            const String& sid = "" );
 
285
 
 
286
                /** Returns the default sid used for the specular element*/ 
 
287
                static const String& getSpecularDefaultSid();
 
288
 
 
289
        /** Returns a reference to specular*/
 
290
        ColorOrTexture& getSpecular();
 
291
 
 
292
        /** Sets the shininess to @a shininess */
 
293
        void  setShininess( double shininess, const bool useDefaultSid = false, const String& sid = "" );
 
294
 
 
295
                /** Returns the default sid used for the shininess element*/ 
 
296
                static const String& getShininessDefaultSid() { return CSWC::CSW_ELEMENT_SHININESS; }
 
297
 
 
298
        /** Returns the shininess*/
 
299
        double getShininess() const;
 
300
 
 
301
        /** Sets the reflective to @a reflective */
 
302
        void  setReflective( 
 
303
            const ColorOrTexture& reflective, 
 
304
            const bool useDefaultSid = false, 
 
305
            const String& sid = "" );
 
306
 
 
307
                /** Returns the default sid used for the reflective element*/ 
 
308
                static const String& getReflectiveDefaultSid();
 
309
 
 
310
        /** Returns a reference to reflective*/
 
311
        ColorOrTexture& getReflective();
 
312
 
 
313
        /** Sets the reflectivity to @a reflectivity */
 
314
        void  setReflectivity( double reflectivity, const bool useDefaultSid = false, const String& sid = "" );
 
315
 
 
316
                /** Returns the default sid used for the reflectivity element*/ 
 
317
                static const String& getReflectivityDefaultSid();
 
318
 
 
319
        /** Sets the transparent to @a transparent */
 
320
        void setTransparent( 
 
321
            const ColorOrTexture& transparent, 
 
322
            const bool useDefaultSid = false, 
 
323
            const String& sid = "" );
 
324
 
 
325
                /** Returns the default sid used for the transparent element*/ 
 
326
                static const String& getTransparentDefaultSid();
 
327
 
 
328
        /** Returns a reference to transparent*/
 
329
        ColorOrTexture& getTransparent();
 
330
 
 
331
        /** Sets the opaque attribute of transparent to @a opaque */
 
332
        void setOpaque( Opaque opaque);
 
333
 
 
334
        /** Sets the opaque attribute of transparent to @a opaque */
 
335
        Opaque getOpaque();
 
336
 
 
337
        /** Sets the transparency to @a transparency */
 
338
        void  setTransparency( double transparency, const bool useDefaultSid = false, const String& sid = "" );
 
339
 
 
340
                /** Returns the default sid used for the transparency element*/ 
 
341
                static const String& getTransparencyDefaultSid() { return CSWC::CSW_ELEMENT_TRANSPARENCY; }
 
342
 
 
343
        /** Sets the indexOfRefrection to @a indexOfRefrection */
 
344
        void  setIndexOfRefraction( 
 
345
            double indexOfRefrection, 
 
346
            const bool useDefaultSid = false, 
 
347
            const String& sid = "" );
 
348
 
 
349
                /** Returns the default sid used for the indexOfRefrection element*/ 
 
350
                static const String& getIndexOfRefractionSid();
 
351
 
 
352
        /**
 
353
        * Adds extra technique tags to the current effect and writes 
 
354
        * the child element with the given colorOrTexture element in the tags.
 
355
        * @param profileName Name of the technique.
 
356
        * @param childElement Name of the colorOrTexture child element.
 
357
        * @param colorOrTexture The colorOrTexture to set.
 
358
        */
 
359
        void addExtraTechniqueColorOrTexture ( const ColorOrTexture& colorOrTexture, const StringPairList& attributes = StringPairList(), const String& sid = "" );
 
360
 
 
361
        /** Add the sampler required by @a colorOrTexture to the stream*/
 
362
        void addSampler ( const ColorOrTexture &colorOrTexture );
 
363
 
 
364
    private:
 
365
 
 
366
        /** Adds the EffectProfile to the stream*/
 
367
        void addProfileCommon ();
 
368
 
 
369
        /** Adds the EffectProfile to the stream*/
 
370
        void addProfileCG ();
 
371
        void addProfileGLSL ();
 
372
        void addProfileGLES ();
 
373
 
 
374
        /** Add the samplers required by the textures to the stream*/
 
375
        void addSamplers();
 
376
 
 
377
        /** Returns the element name of the profile type. */
 
378
        static const String& getProfileTypeName ( ProfileType profileType );
 
379
 
 
380
        /** Returns the element name of the shader. */
 
381
        static const String& getShaderTypeName ( ShaderType shaderType );
 
382
 
 
383
        /** Returns a reference to the COLLADASW name of the opaque type*/
 
384
        static const String& getOpaqueString ( Opaque opaque );
 
385
 
 
386
        /** Adds element @a elementName and adds @a colorOrTexture to it.*/
 
387
        void addColorOrTexture ( 
 
388
            const String &elementName, 
 
389
            const ColorOrTexture &colorOrTexture, 
 
390
            const String &elementSid, 
 
391
                        StringPairList attributes = StringPairList(),
 
392
            Opaque opaque = UNSPECIFIED_OPAQUE ) const;
 
393
 
 
394
        /** Adds element @a elementName and adds @a number to it.*/
 
395
        void addFloat ( 
 
396
            const String &elementName, 
 
397
            const double &number, 
 
398
            const String &elementSid ) const;
 
399
 
 
400
        /**
 
401
        * Adds extra technique tags to the current effect and writes 
 
402
        * the child element with the given colorOrTexture element in the tags.
 
403
        * @param profileName Name of the technique.
 
404
        * @param childElement Name of the colorOrTexture child element.
 
405
        * @param colorOrTexture The colorOrTexture to set.
 
406
        */
 
407
        void addExtraTechniqueColorOrTextures ( 
 
408
                        const ExtraColorOrTextureEntryByProfileName &entriesByProfileName ) const;
 
409
    };
 
410
 
 
411
 
 
412
} //namespace COLLADASW
 
413
 
 
414
 
 
415
#endif //__COLLADASTREAMWRITER_EFFECT_H__