2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAStreamWriter.
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
11
#ifndef __COLLADASTREAMWRITER_EFFECT_H__
12
#define __COLLADASTREAMWRITER_EFFECT_H__
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"
28
/** A class to write a @a \<profile_COMMON\> element to the stream*/
29
class EffectProfile : public ElementWriter, public BaseExtraTechnique
34
/** The possible profile types. */
43
/** The list of the lighting models supported by the COMMON profile of COLLADASW. */
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.*/
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). */
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. */
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. */
73
/** Not a valid lighting model. */
86
typedef std::list< std::pair<String, String> > StringPairList;
90
friend class LibraryEffects;
92
struct ExtraColorOrTextureEntry
94
ColorOrTexture colorOrTexture;
96
StringPairList attributes;
99
typedef std::map<String, std::vector<ExtraColorOrTextureEntry> > ExtraColorOrTextureEntryByProfileName;
102
* A text string containing the unique identifier of the element.
103
* This value must be unique within the instance document. Optional.
105
String mEffectProfileId;
107
/** The include sid and uri for the cg profile. */
111
/** For writing code directly into code tags. */
115
/** The technique sid that is used, if no other is specified*/
116
static const String DEFAULT_TECHNIQUE_SID;
118
/** The sid of the technique element*/
119
String mTechniqueSid;
121
TagCloser mTechniqueCloser;
123
/** The current profile type. */
124
ProfileType mProfileType;
126
TagCloser mProfileCloser;
128
/** The current shader type. */
129
ShaderType mShaderType;
131
/** The ColorOrTexture-values can be sampled. */
132
ColorOrTexture mEmission;
135
ColorOrTexture mAmbient;
138
ColorOrTexture mDiffuse;
141
ColorOrTexture mSpecular;
144
ColorOrTexture mTransparent;
145
String mTransparentSid;
147
ColorOrTexture mReflective;
148
String mReflectiveSid;
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;
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;
159
String mShininessSid;
161
double mReflectivity;
162
String mReflectivitySid;
166
double mTransparency;
167
String mTransparencySid;
169
double mIndexOfRefraction;
170
String mIndexOfRefractionSid;
172
/** The extra tag elements under the effect profile. */
173
BaseExtraTechnique mProfileExtra;
175
/** The extra tag elements under the effect profile's technique element. */
176
BaseExtraTechnique mProfileTechniqueExtra;
178
/** The extra tag elements under the effect profile's technique element. */
179
BaseExtraTechnique mProfileTechniqueTextureExtra;
184
@param streamWriter The stream writer the @a \<profile_COMMON\> element should be written to
186
EffectProfile ( StreamWriter* streamWriter, const String& effectProfileId = "" );
187
virtual ~EffectProfile(){};
189
/** The extra tag elements under the effect profile. */
190
BaseExtraTechnique& getProfileExtra () { return mProfileExtra; }
192
/** The extra tag elements under the effect profile's technique element. */
193
BaseExtraTechnique& getProfileTechniqueExtra () { return mProfileTechniqueExtra; }
196
* A text string containing the unique identifier of the element.
197
* This value must be unique within the instance document. Optional.
199
const COLLADASW::String& getEffectProfileId () const { return mEffectProfileId; }
200
void setEffectProfileId ( const COLLADASW::String& val ) { mEffectProfileId = val; }
202
/** The current profile type. */
203
const EffectProfile::ProfileType& getProfileType () const { return mProfileType; }
205
/** The current profile type. */
206
void setProfileType ( const EffectProfile::ProfileType& val ) { mProfileType = val; }
208
/** Opens the current profile. */
211
/** Close the current profile. */
212
void closeProfile ();
214
/** Adds the EffectProfile to the stream*/
215
void addProfileElements ();
217
/** Opens a technique element with the given sid. */
218
void openTechnique ( const String& techniqueSid );
220
/** Close the current technique element. */
221
void closeTechnique ();
223
/** Sets the sid of the @a \<technique\> element*/
224
void setTechniqueSid ( const String& techniqueSid );
226
/** Returns the sid of the @a \<technique\> element*/
227
const String& getTechniqueSid () const;
229
/** Sets the shader type to @a shaderType */
230
void setShaderType( ShaderType shaderType );
232
/** Returns the shader type */
233
ShaderType getShaderType() const;
235
/** Reference to the included file. */
236
void setInclude ( const URI &includeUri, const String &sid="" );
238
const URI & getIncludeURI() { return mIncludeURI; }
240
/** For writing code directly into code tags. */
241
const String& getCode () const;
242
void setCode ( const String &code, const String &sid="" );
244
/** Sets the emission to @a emission */
246
const ColorOrTexture& emission,
247
const bool useDefaultSid = false,
248
const String& sid = "" );
250
/** Returns the default sid used for the emission element*/
251
static const String& getEmissionDefaultSid();
253
/** Returns a reference to the emission*/
254
ColorOrTexture& getEmission();
256
/** Sets the ambient to @a ambient */
258
const ColorOrTexture& ambient,
259
const bool useDefaultSid = false,
260
const String& sid = "" );
262
/** Returns the default sid used for the ambient element*/
263
static const String& getAmbientDefaultSid();
265
/** Returns a reference to ambient*/
266
ColorOrTexture& getAmbient();
268
/** Sets the diffuse to @a diffuse */
270
const ColorOrTexture& diffuse,
271
const bool useDefaultSid = false,
272
const String& sid = "" );
274
/** Returns the default sid used for the diffuse element*/
275
static const String& getDiffuseDefaultSid();
277
/** Returns a reference to diffuse*/
278
ColorOrTexture& getDiffuse();
280
/** Sets the specular to @a specular */
282
const ColorOrTexture& specular,
283
const bool useDefaultSid = false,
284
const String& sid = "" );
286
/** Returns the default sid used for the specular element*/
287
static const String& getSpecularDefaultSid();
289
/** Returns a reference to specular*/
290
ColorOrTexture& getSpecular();
292
/** Sets the shininess to @a shininess */
293
void setShininess( double shininess, const bool useDefaultSid = false, const String& sid = "" );
295
/** Returns the default sid used for the shininess element*/
296
static const String& getShininessDefaultSid() { return CSWC::CSW_ELEMENT_SHININESS; }
298
/** Returns the shininess*/
299
double getShininess() const;
301
/** Sets the reflective to @a reflective */
303
const ColorOrTexture& reflective,
304
const bool useDefaultSid = false,
305
const String& sid = "" );
307
/** Returns the default sid used for the reflective element*/
308
static const String& getReflectiveDefaultSid();
310
/** Returns a reference to reflective*/
311
ColorOrTexture& getReflective();
313
/** Sets the reflectivity to @a reflectivity */
314
void setReflectivity( double reflectivity, const bool useDefaultSid = false, const String& sid = "" );
316
/** Returns the default sid used for the reflectivity element*/
317
static const String& getReflectivityDefaultSid();
319
/** Sets the transparent to @a transparent */
321
const ColorOrTexture& transparent,
322
const bool useDefaultSid = false,
323
const String& sid = "" );
325
/** Returns the default sid used for the transparent element*/
326
static const String& getTransparentDefaultSid();
328
/** Returns a reference to transparent*/
329
ColorOrTexture& getTransparent();
331
/** Sets the opaque attribute of transparent to @a opaque */
332
void setOpaque( Opaque opaque);
334
/** Sets the opaque attribute of transparent to @a opaque */
337
/** Sets the transparency to @a transparency */
338
void setTransparency( double transparency, const bool useDefaultSid = false, const String& sid = "" );
340
/** Returns the default sid used for the transparency element*/
341
static const String& getTransparencyDefaultSid() { return CSWC::CSW_ELEMENT_TRANSPARENCY; }
343
/** Sets the indexOfRefrection to @a indexOfRefrection */
344
void setIndexOfRefraction(
345
double indexOfRefrection,
346
const bool useDefaultSid = false,
347
const String& sid = "" );
349
/** Returns the default sid used for the indexOfRefrection element*/
350
static const String& getIndexOfRefractionSid();
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.
359
void addExtraTechniqueColorOrTexture ( const ColorOrTexture& colorOrTexture, const StringPairList& attributes = StringPairList(), const String& sid = "" );
361
/** Add the sampler required by @a colorOrTexture to the stream*/
362
void addSampler ( const ColorOrTexture &colorOrTexture );
366
/** Adds the EffectProfile to the stream*/
367
void addProfileCommon ();
369
/** Adds the EffectProfile to the stream*/
370
void addProfileCG ();
371
void addProfileGLSL ();
372
void addProfileGLES ();
374
/** Add the samplers required by the textures to the stream*/
377
/** Returns the element name of the profile type. */
378
static const String& getProfileTypeName ( ProfileType profileType );
380
/** Returns the element name of the shader. */
381
static const String& getShaderTypeName ( ShaderType shaderType );
383
/** Returns a reference to the COLLADASW name of the opaque type*/
384
static const String& getOpaqueString ( Opaque opaque );
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;
394
/** Adds element @a elementName and adds @a number to it.*/
396
const String &elementName,
397
const double &number,
398
const String &elementSid ) const;
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.
407
void addExtraTechniqueColorOrTextures (
408
const ExtraColorOrTextureEntryByProfileName &entriesByProfileName ) const;
412
} //namespace COLLADASW
415
#endif //__COLLADASTREAMWRITER_EFFECT_H__