00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_PS_ATTRIB_MAKER_H
00027 #define NL_PS_ATTRIB_MAKER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "3d/ps_attrib.h"
00031 #include "3d/ps_located.h"
00032 #include "nel/misc/stream.h"
00033
00034
00035
00036
00037
00038
00039 namespace NL3D {
00040
00041
00045 struct CPSInputType
00046 {
00048 CPSInputType() : InputType(attrDate)
00049 {
00050 }
00051
00053 enum TInputType
00054 {
00055 attrDate = 0,
00056 attrPosition = 1,
00057 attrInverseMass = 2,
00058 attrSpeed = 3,
00059 attrUniformRandom = 4,
00060 attrUserParam = 5,
00061 attrLOD = 6,
00062 attrSquareLOD = 7,
00063 attrClampedLOD = 8,
00064 attrClampedSquareLOD = 9,
00065 } InputType ;
00066
00067 union
00068 {
00070 uint32 UserParamNum ;
00071 } ;
00072
00073 void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00074 {
00075 f.serialEnum(InputType) ;
00076 switch(InputType)
00077 {
00078 case attrUserParam:
00079 f.serial(UserParamNum) ;
00080 break ;
00081 default: break;
00082 }
00083 }
00084 } ;
00085
00086
00095
00096 const float MaxInputValue = 1.0f ;
00097
00102 class CPSAttribMakerBase : public NLMISC::IStreamable
00103 {
00104 public:
00105
00106 virtual const char *getType() = 0;
00107
00108 virtual CPSAttribMakerBase *clone() const = 0;
00109 };
00110
00111
00112
00113
00122 template <typename T> class CPSAttribMaker : public CPSAttribMakerBase
00123 {
00124 public:
00126
00127
00130 CPSAttribMaker(float nbCycles = 1.f) : _NbCycles(nbCycles), _HasMemory(false)
00131 {
00132 }
00133
00135 virtual void serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00136 {
00137 f.serialVersion(1) ;
00138 f.serial(_NbCycles) ;
00139 }
00140
00142 virtual const char *getType() { return "UNKNOWN"; }
00143
00145 virtual ~CPSAttribMaker() {}
00147
00149
00150
00151 virtual T get(CPSLocated *loc, uint32 index) = 0 ;
00152
00156 virtual T get(float input) { nlassert(0); return T(); }
00157
00158
00174 virtual void *make(CPSLocated *loc,
00175 uint32 startIndex,
00176 void *tab,
00177 uint32 stride,
00178 uint32 numAttrib,
00179 bool allowNoCopy = false,
00180 uint32 srcStep = (1 << 16)
00181 ) const = 0 ;
00182
00186 virtual void make4(CPSLocated *loc,
00187 uint32 startIndex,
00188 void *tab,
00189 uint32 stride,
00190 uint32 numAttrib,
00191 uint32 srcStep = (1 << 16)
00192 ) const = 0 ;
00193
00197 virtual void makeN(CPSLocated *loc,
00198 uint32 startIndex,
00199 void *tab,
00200 uint32 stride,
00201 uint32 numAttrib,
00202 uint32 nbReplicate,
00203 uint32 srcStep = (1 << 16)
00204 ) const = 0 ;
00206
00207
00208
00210 virtual T getMaxValue(void) const { return T() ; }
00211
00212
00214
00215
00220 void setNbCycles(float nbCycles)
00221 {
00222 nlassert(nbCycles >= 0) ;
00223 _NbCycles = nbCycles ;
00224 }
00225
00229 float getNbCycles(void) const { return _NbCycles ; }
00230
00232 virtual bool hasCustomInput(void) { return false ; }
00233
00234
00238 virtual void setInput(const CPSInputType &input) {}
00239
00240
00244 virtual CPSInputType getInput(void) const { return CPSInputType() ; }
00245
00246
00247
00251 virtual bool isClampingSupported(void) const { return false ; }
00252
00253
00258 virtual void setClamping(bool enable = true) {} ;
00259
00260
00265 virtual bool getClamping(void) const { return false ; }
00267
00268
00270
00271
00275 bool hasMemory(void) const { return _HasMemory ; }
00276
00278 virtual void deleteElement(uint32 index) { nlassert(false) ; }
00279
00283 virtual void newElement(CPSLocated *emitterLocated, uint32 emitterIndex) { nlassert(false) ; }
00284
00289 virtual void resize(uint32 capacity, uint32 nbPresentElements) { nlassert(false) ; }
00291
00292 protected:
00293
00294 float _NbCycles ;
00295
00296
00297 bool _HasMemory ;
00298
00299 };
00300
00301
00302
00303
00304
00305
00306 }
00307
00308
00309
00310 #endif // NL_PS_ATTRIB_MAKER_H
00311
00312