OgreGpuProgramParams.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __GpuProgramParams_H_
  25. #define __GpuProgramParams_H_
  26. // Precompiler options
  27. #include "OgrePrerequisites.h"
  28. #include "OgreSharedPtr.h"
  29. #include "OgreRenderOperation.h"
  30. namespace Ogre {
  31. /** \addtogroup Core
  32. * @{
  33. */
  34. /** \addtogroup Materials
  35. * @{
  36. */
  37. /** Enumeration of the types of constant we may encounter in programs.
  38. @note Low-level programs, by definition, will always use either
  39. float4 or int4 constant types since that is the fundamental underlying
  40. type in assembler.
  41. */
  42. enum GpuConstantType
  43. {
  44. GCT_FLOAT1 = 1,
  45. GCT_FLOAT2 = 2,
  46. GCT_FLOAT3 = 3,
  47. GCT_FLOAT4 = 4,
  48. GCT_SAMPLER1D = 5,
  49. GCT_SAMPLER2D = 6,
  50. GCT_SAMPLER3D = 7,
  51. GCT_SAMPLERCUBE = 8,
  52. GCT_SAMPLER1DSHADOW = 9,
  53. GCT_SAMPLER2DSHADOW = 10,
  54. GCT_MATRIX_2X2 = 11,
  55. GCT_MATRIX_2X3 = 12,
  56. GCT_MATRIX_2X4 = 13,
  57. GCT_MATRIX_3X2 = 14,
  58. GCT_MATRIX_3X3 = 15,
  59. GCT_MATRIX_3X4 = 16,
  60. GCT_MATRIX_4X2 = 17,
  61. GCT_MATRIX_4X3 = 18,
  62. GCT_MATRIX_4X4 = 19,
  63. GCT_INT1 = 20,
  64. GCT_INT2 = 21,
  65. GCT_INT3 = 22,
  66. GCT_INT4 = 23,
  67. GCT_UNKNOWN = 99
  68. };
  69. /** The variability of a GPU parameter, as derived from auto-params targetting it.
  70. These values must be powers of two since they are used in masks.
  71. */
  72. enum GpuParamVariability
  73. {
  74. /// No variation except by manual setting - the default
  75. GPV_GLOBAL = 1,
  76. /// Varies per object (based on an auto param usually), but not per light setup
  77. GPV_PER_OBJECT = 2,
  78. /// Varies with light setup
  79. GPV_LIGHTS = 4,
  80. /// Varies with pass iteration number
  81. GPV_PASS_ITERATION_NUMBER = 8,
  82. /// Full mask (16-bit)
  83. GPV_ALL = 0xFFFF
  84. };
  85. /** Information about predefined program constants.
  86. @note Only available for high-level programs but is referenced generically
  87. by GpuProgramParameters.
  88. */
  89. struct _OgreExport GpuConstantDefinition
  90. {
  91. /// Data type
  92. GpuConstantType constType;
  93. /// Physical start index in buffer (either float or int buffer)
  94. size_t physicalIndex;
  95. /// Logical index - used to communicate this constant to the rendersystem
  96. size_t logicalIndex;
  97. /** Number of raw buffer slots per element
  98. (some programs pack each array element to float4, some do not) */
  99. size_t elementSize;
  100. /// Length of array
  101. size_t arraySize;
  102. /// How this parameter varies (bitwise combination of GpuProgramVariability)
  103. mutable uint16 variability;
  104. bool isFloat() const
  105. {
  106. return isFloat(constType);
  107. }
  108. static bool isFloat(GpuConstantType c)
  109. {
  110. switch(c)
  111. {
  112. case GCT_INT1:
  113. case GCT_INT2:
  114. case GCT_INT3:
  115. case GCT_INT4:
  116. case GCT_SAMPLER1D:
  117. case GCT_SAMPLER2D:
  118. case GCT_SAMPLER3D:
  119. case GCT_SAMPLERCUBE:
  120. case GCT_SAMPLER1DSHADOW:
  121. case GCT_SAMPLER2DSHADOW:
  122. return false;
  123. default:
  124. return true;
  125. };
  126. }
  127. bool isSampler() const
  128. {
  129. return isSampler(constType);
  130. }
  131. static bool isSampler(GpuConstantType c)
  132. {
  133. switch(c)
  134. {
  135. case GCT_SAMPLER1D:
  136. case GCT_SAMPLER2D:
  137. case GCT_SAMPLER3D:
  138. case GCT_SAMPLERCUBE:
  139. case GCT_SAMPLER1DSHADOW:
  140. case GCT_SAMPLER2DSHADOW:
  141. return true;
  142. default:
  143. return false;
  144. };
  145. }
  146. /** Get the element size of a given type, including whether to pad the
  147. elements into multiples of 4 (e.g. SM1 and D3D does, GLSL doesn't)
  148. */
  149. static size_t getElementSize(GpuConstantType ctype, bool padToMultiplesOf4)
  150. {
  151. if (padToMultiplesOf4)
  152. {
  153. switch(ctype)
  154. {
  155. case GCT_FLOAT1:
  156. case GCT_INT1:
  157. case GCT_SAMPLER1D:
  158. case GCT_SAMPLER2D:
  159. case GCT_SAMPLER3D:
  160. case GCT_SAMPLERCUBE:
  161. case GCT_SAMPLER1DSHADOW:
  162. case GCT_SAMPLER2DSHADOW:
  163. case GCT_FLOAT2:
  164. case GCT_INT2:
  165. case GCT_FLOAT3:
  166. case GCT_INT3:
  167. case GCT_FLOAT4:
  168. case GCT_INT4:
  169. return 4;
  170. case GCT_MATRIX_2X2:
  171. case GCT_MATRIX_2X3:
  172. case GCT_MATRIX_2X4:
  173. return 8; // 2 float4s
  174. case GCT_MATRIX_3X2:
  175. case GCT_MATRIX_3X3:
  176. case GCT_MATRIX_3X4:
  177. return 12; // 3 float4s
  178. case GCT_MATRIX_4X2:
  179. case GCT_MATRIX_4X3:
  180. case GCT_MATRIX_4X4:
  181. return 16; // 4 float4s
  182. default:
  183. return 4;
  184. };
  185. }
  186. else
  187. {
  188. switch(ctype)
  189. {
  190. case GCT_FLOAT1:
  191. case GCT_INT1:
  192. case GCT_SAMPLER1D:
  193. case GCT_SAMPLER2D:
  194. case GCT_SAMPLER3D:
  195. case GCT_SAMPLERCUBE:
  196. case GCT_SAMPLER1DSHADOW:
  197. case GCT_SAMPLER2DSHADOW:
  198. return 1;
  199. case GCT_FLOAT2:
  200. case GCT_INT2:
  201. return 2;
  202. case GCT_FLOAT3:
  203. case GCT_INT3:
  204. return 3;
  205. case GCT_FLOAT4:
  206. case GCT_INT4:
  207. return 4;
  208. case GCT_MATRIX_2X2:
  209. return 4;
  210. case GCT_MATRIX_2X3:
  211. case GCT_MATRIX_3X2:
  212. return 6;
  213. case GCT_MATRIX_2X4:
  214. case GCT_MATRIX_4X2:
  215. return 8;
  216. case GCT_MATRIX_3X3:
  217. return 9;
  218. case GCT_MATRIX_3X4:
  219. case GCT_MATRIX_4X3:
  220. return 12;
  221. case GCT_MATRIX_4X4:
  222. return 16;
  223. default:
  224. return 4;
  225. };
  226. }
  227. }
  228. GpuConstantDefinition()
  229. : constType(GCT_UNKNOWN)
  230. , physicalIndex((std::numeric_limits<size_t>::max)())
  231. , elementSize(0)
  232. , arraySize(1)
  233. , variability(GPV_GLOBAL) {}
  234. };
  235. typedef map<String, GpuConstantDefinition>::type GpuConstantDefinitionMap;
  236. typedef GpuConstantDefinitionMap::const_iterator GpuConstantDefinitionIterator;
  237. /// Struct collecting together the information for named constants.
  238. struct _OgreExport GpuNamedConstants
  239. {
  240. /// Total size of the float buffer required
  241. size_t floatBufferSize;
  242. /// Total size of the int buffer required
  243. size_t intBufferSize;
  244. /// Map of parameter names to GpuConstantDefinition
  245. GpuConstantDefinitionMap map;
  246. GpuNamedConstants() : floatBufferSize(0), intBufferSize(0) {}
  247. /** Generate additional constant entries for arrays based on a base definition.
  248. @remarks
  249. Array uniforms will be added just with their base name with no array
  250. suffix. This method will add named entries for array suffixes too
  251. so individual array entries can be addressed. Note that we only
  252. individually index array elements if the array size is up to 16
  253. entries in size. Anything larger than that only gets a [0] entry
  254. as well as the main entry, to save cluttering up the name map. After
  255. all, you can address the larger arrays in a bulk fashion much more
  256. easily anyway.
  257. */
  258. void generateConstantDefinitionArrayEntries(const String& paramName,
  259. const GpuConstantDefinition& baseDef);
  260. /// Indicates whether all array entries will be generated and added to the definitions map
  261. static bool getGenerateAllConstantDefinitionArrayEntries();
  262. /** Sets whether all array entries will be generated and added to the definitions map.
  263. @remarks
  264. Usually, array entries can only be individually indexed if they're up to 16 entries long,
  265. to save memory - arrays larger than that can be set but only via the bulk setting
  266. methods. This option allows you to choose to individually index every array entry.
  267. */
  268. static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
  269. protected:
  270. /** Indicates whether all array entries will be generated and added to the definitions map
  271. @remarks
  272. Normally, the number of array entries added to the definitions map is capped at 16
  273. to save memory. Setting this value to <code>true</code> allows all of the entries
  274. to be generated and added to the map.
  275. */
  276. static bool msGenerateAllConstantDefinitionArrayEntries;
  277. };
  278. typedef SharedPtr<GpuNamedConstants> GpuNamedConstantsPtr;
  279. /** Structure recording the use of a physical buffer by a logical parameter
  280. index. Only used for low-level programs.
  281. */
  282. struct _OgreExport GpuLogicalIndexUse
  283. {
  284. /// Physical buffer index
  285. size_t physicalIndex;
  286. /// Current physical size allocation
  287. size_t currentSize;
  288. /// How the contents of this slot vary
  289. mutable uint16 variability;
  290. GpuLogicalIndexUse()
  291. : physicalIndex(99999), currentSize(0), variability(GPV_GLOBAL) {}
  292. GpuLogicalIndexUse(size_t bufIdx, size_t curSz, uint16 v)
  293. : physicalIndex(bufIdx), currentSize(curSz), variability(v) {}
  294. };
  295. typedef map<size_t, GpuLogicalIndexUse>::type GpuLogicalIndexUseMap;
  296. /// Container struct to allow params to safely & update shared list of logical buffer assignments
  297. struct _OgreExport GpuLogicalBufferStruct
  298. {
  299. OGRE_MUTEX(mutex)
  300. /// Map from logical index to physical buffer location
  301. GpuLogicalIndexUseMap map;
  302. /// Shortcut to know the buffer size needs
  303. size_t bufferSize;
  304. GpuLogicalBufferStruct() : bufferSize(0) {}
  305. };
  306. typedef SharedPtr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
  307. /** Definition of container that holds the current float constants.
  308. @note Not necessarily in direct index order to constant indexes, logical
  309. to physical index map is derived from GpuProgram
  310. */
  311. typedef vector<float>::type FloatConstantList;
  312. /** Definition of container that holds the current float constants.
  313. @note Not necessarily in direct index order to constant indexes, logical
  314. to physical index map is derived from GpuProgram
  315. */
  316. typedef vector<int>::type IntConstantList;
  317. /** A group of manually updated parameters that are shared between many parameter sets.
  318. @remarks
  319. Sometimes you want to set some common parameters across many otherwise
  320. different parameter sets, and keep them all in sync together. This class
  321. allows you to define a set of parameters that you can share across many
  322. parameter sets and have the parameters that match automatically be pulled
  323. from the shared set, rather than you having to set them on all the parameter
  324. sets individually.
  325. @par
  326. Parameters in a shared set are matched up with instances in a GpuProgramParameters
  327. structure by matching names. It is up to you to define the named parameters
  328. that a shared set contains, and ensuring the definition matches.
  329. @note
  330. Shared parameter sets can be named, and looked up using the GpuProgramManager.
  331. */
  332. class _OgreExport GpuSharedParameters
  333. {
  334. protected:
  335. GpuNamedConstants mNamedConstants;
  336. FloatConstantList mFloatConstants;
  337. IntConstantList mIntConstants;
  338. String mName;
  339. // Optional data the rendersystem might want to store
  340. // TODO PORT - Commented out because I don't think anything uses this and it requires an extra include
  341. //mutable Any mRenderSystemData;
  342. /// Not used when copying data, but might be useful to RS using shared buffers
  343. size_t mFrameLastUpdated;
  344. /// Version number of the definitions in this buffer
  345. unsigned long mVersion;
  346. public:
  347. GpuSharedParameters(const String& name);
  348. virtual ~GpuSharedParameters();
  349. /// Get the name of this shared parameter set
  350. const String& getName() { return mName; }
  351. /** Add a new constant definition to this shared set of parameters.
  352. @remarks
  353. Unlike GpuProgramParameters, where the parameter list is defined by the
  354. program being compiled, this shared parameter set is defined by the
  355. user. Only parameters which have been predefined here may be later
  356. updated.
  357. */
  358. void addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize = 1);
  359. /** Remove a constant definition from this shared set of parameters.
  360. */
  361. void removeConstantDefinition(const String& name);
  362. /** Remove a constant definition from this shared set of parameters.
  363. */
  364. void removeAllConstantDefinitions();
  365. /** Get the version number of this shared parameter set, can be used to identify when
  366. changes have occurred.
  367. */
  368. unsigned long getVersion() const { return mVersion; }
  369. /** Mark the shared set as being dirty (values modified).
  370. @remarks
  371. You do not need to call this yourself, set is marked as dirty whenever
  372. setNamedConstant or (non const) getFloatPointer et al are called.
  373. */
  374. void _markDirty();
  375. /// Get the frame in which this shared parameter set was last updated
  376. size_t getFrameLastUpdated() const { return mFrameLastUpdated; }
  377. /** Gets an iterator over the named GpuConstantDefinition instances as defined
  378. by the user.
  379. */
  380. GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
  381. /** Get a specific GpuConstantDefinition for a named parameter.
  382. */
  383. const GpuConstantDefinition& getConstantDefinition(const String& name) const;
  384. /** Get the full list of GpuConstantDefinition instances.
  385. */
  386. const GpuNamedConstants& getConstantDefinitions() const;
  387. /** @copydoc GpuProgramParameters::setNamedConstant */
  388. void setNamedConstant(const String& name, Real val);
  389. /** @copydoc GpuProgramParameters::setNamedConstant */
  390. void setNamedConstant(const String& name, int val);
  391. /** @copydoc GpuProgramParameters::setNamedConstant */
  392. void setNamedConstant(const String& name, const Vector4& vec);
  393. /** @copydoc GpuProgramParameters::setNamedConstant */
  394. void setNamedConstant(const String& name, const Vector3& vec);
  395. /** @copydoc GpuProgramParameters::setNamedConstant */
  396. void setNamedConstant(const String& name, const Matrix4& m);
  397. /** @copydoc GpuProgramParameters::setNamedConstant */
  398. void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
  399. /** @copydoc GpuProgramParameters::setNamedConstant */
  400. void setNamedConstant(const String& name, const float *val, size_t count);
  401. /** @copydoc GpuProgramParameters::setNamedConstant */
  402. void setNamedConstant(const String& name, const double *val, size_t count);
  403. /** @copydoc GpuProgramParameters::setNamedConstant */
  404. void setNamedConstant(const String& name, const ColourValue& colour);
  405. /** @copydoc GpuProgramParameters::setNamedConstant */
  406. void setNamedConstant(const String& name, const int *val, size_t count);
  407. /// Get a pointer to the 'nth' item in the float buffer
  408. float* getFloatPointer(size_t pos) { _markDirty(); return &mFloatConstants[pos]; }
  409. /// Get a pointer to the 'nth' item in the float buffer
  410. const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
  411. /// Get a pointer to the 'nth' item in the int buffer
  412. int* getIntPointer(size_t pos) { _markDirty(); return &mIntConstants[pos]; }
  413. /// Get a pointer to the 'nth' item in the int buffer
  414. const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
  415. // TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
  416. ///** Internal method that the RenderSystem might use to store optional data. */
  417. //void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
  418. ///** Internal method that the RenderSystem might use to store optional data. */
  419. //const Any& _getRenderSystemData() const { return mRenderSystemData; }
  420. };
  421. /// Shared pointer used to hold references to GpuProgramParameters instances
  422. typedef SharedPtr<GpuSharedParameters> GpuSharedParametersPtr;
  423. class GpuProgramParameters;
  424. /** This class records the usage of a set of shared parameters in a concrete
  425. set of GpuProgramParameters.
  426. */
  427. class _OgreExport GpuSharedParametersUsage
  428. {
  429. protected:
  430. GpuSharedParametersPtr mSharedParams;
  431. // Not a shared pointer since this is also parent
  432. GpuProgramParameters* mParams;
  433. // list of physical mappings that we are going to bring in
  434. struct CopyDataEntry
  435. {
  436. const GpuConstantDefinition* srcDefinition;
  437. const GpuConstantDefinition* dstDefinition;
  438. };
  439. typedef vector<CopyDataEntry>::type CopyDataList;
  440. CopyDataList mCopyDataList;
  441. // Optional data the rendersystem might want to store
  442. // TODO PORT - Commented out because I don't think its used
  443. //mutable Any mRenderSystemData;
  444. /// Version of shared params we based the copydata on
  445. unsigned long mCopyDataVersion;
  446. void initCopyData();
  447. public:
  448. /// Construct usage
  449. GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams,
  450. GpuProgramParameters* params);
  451. /** Update the target parameters by copying the data from the shared
  452. parameters.
  453. @note This method may not actually be called if the RenderSystem
  454. supports using shared parameters directly in their own shared buffer; in
  455. which case the values should not be copied out of the shared area
  456. into the individual parameter set, but bound separately.
  457. */
  458. void _copySharedParamsToTargetParams();
  459. /// Get the name of the shared parameter set
  460. const String& getName() const { return mSharedParams->getName(); }
  461. GpuSharedParametersPtr getSharedParams() const { return mSharedParams; }
  462. GpuProgramParameters* getTargetParams() const { return mParams; }
  463. // TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
  464. ///** Internal method that the RenderSystem might use to store optional data. */
  465. //void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
  466. ///** Internal method that the RenderSystem might use to store optional data. */
  467. //const Any& _getRenderSystemData() const { return mRenderSystemData; }
  468. };
  469. /** Collects together the program parameters used for a GpuProgram.
  470. @remarks
  471. Gpu program state includes constant parameters used by the program, and
  472. bindings to render system state which is propagated into the constants
  473. by the engine automatically if requested.
  474. @par
  475. GpuProgramParameters objects should be created through the GpuProgram and
  476. may be shared between multiple Pass instances. For this reason they
  477. are managed using a shared pointer, which will ensure they are automatically
  478. deleted when no Pass is using them anymore.
  479. @par
  480. High-level programs use named parameters (uniforms), low-level programs
  481. use indexed constants. This class supports both, but you can tell whether
  482. named constants are supported by calling hasNamedParameters(). There are
  483. references in the documentation below to 'logical' and 'physical' indexes;
  484. logical indexes are the indexes used by low-level programs and represent
  485. indexes into an array of float4's, some of which may be settable, some of
  486. which may be predefined constants in the program. We only store those
  487. constants which have actually been set, therefore our buffer could have
  488. gaps if we used the logical indexes in our own buffers. So instead we map
  489. these logical indexes to physical indexes in our buffer. When using
  490. high-level programs, logical indexes don't necessarily exist, although they
  491. might if the high-level program has a direct, exposed mapping from parameter
  492. names to logical indexes. In addition, high-level languages may or may not pack
  493. arrays of elements that are smaller than float4 (e.g. float2/vec2) contiguously.
  494. This kind of information is held in the ConstantDefinition structure which
  495. is only populated for high-level programs. You don't have to worry about
  496. any of this unless you intend to read parameters back from this structure
  497. rather than just setting them.
  498. */
  499. class _OgreExport GpuProgramParameters
  500. {
  501. public:
  502. /** Defines the types of automatically updated values that may be bound to GpuProgram
  503. parameters, or used to modify parameters on a per-object basis.
  504. */
  505. enum AutoConstantType
  506. {
  507. /// The current world matrix
  508. ACT_WORLD_MATRIX,
  509. /// The current world matrix, inverted
  510. ACT_INVERSE_WORLD_MATRIX,
  511. /** Provides transpose of world matrix.
  512. Equivalent to RenderMonkey's "WorldTranspose".
  513. */
  514. ACT_TRANSPOSE_WORLD_MATRIX,
  515. /// The current world matrix, inverted & transposed
  516. ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
  517. /// The current array of world matrices, as a 3x4 matrix, used for blending
  518. ACT_WORLD_MATRIX_ARRAY_3x4,
  519. /// The current array of world matrices, used for blending
  520. ACT_WORLD_MATRIX_ARRAY,
  521. /// The current view matrix
  522. ACT_VIEW_MATRIX,
  523. /// The current view matrix, inverted
  524. ACT_INVERSE_VIEW_MATRIX,
  525. /** Provides transpose of view matrix.
  526. Equivalent to RenderMonkey's "ViewTranspose".
  527. */
  528. ACT_TRANSPOSE_VIEW_MATRIX,
  529. /** Provides inverse transpose of view matrix.
  530. Equivalent to RenderMonkey's "ViewInverseTranspose".
  531. */
  532. ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
  533. /// The current projection matrix
  534. ACT_PROJECTION_MATRIX,
  535. /** Provides inverse of projection matrix.
  536. Equivalent to RenderMonkey's "ProjectionInverse".
  537. */
  538. ACT_INVERSE_PROJECTION_MATRIX,
  539. /** Provides transpose of projection matrix.
  540. Equivalent to RenderMonkey's "ProjectionTranspose".
  541. */
  542. ACT_TRANSPOSE_PROJECTION_MATRIX,
  543. /** Provides inverse transpose of projection matrix.
  544. Equivalent to RenderMonkey's "ProjectionInverseTranspose".
  545. */
  546. ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
  547. /// The current view & projection matrices concatenated
  548. ACT_VIEWPROJ_MATRIX,
  549. /** Provides inverse of concatenated view and projection matrices.
  550. Equivalent to RenderMonkey's "ViewProjectionInverse".
  551. */
  552. ACT_INVERSE_VIEWPROJ_MATRIX,
  553. /** Provides transpose of concatenated view and projection matrices.
  554. Equivalent to RenderMonkey's "ViewProjectionTranspose".
  555. */
  556. ACT_TRANSPOSE_VIEWPROJ_MATRIX,
  557. /** Provides inverse transpose of concatenated view and projection matrices.
  558. Equivalent to RenderMonkey's "ViewProjectionInverseTranspose".
  559. */
  560. ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
  561. /// The current world & view matrices concatenated
  562. ACT_WORLDVIEW_MATRIX,
  563. /// The current world & view matrices concatenated, then inverted
  564. ACT_INVERSE_WORLDVIEW_MATRIX,
  565. /** Provides transpose of concatenated world and view matrices.
  566. Equivalent to RenderMonkey's "WorldViewTranspose".
  567. */
  568. ACT_TRANSPOSE_WORLDVIEW_MATRIX,
  569. /// The current world & view matrices concatenated, then inverted & transposed
  570. ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
  571. /// view matrices.
  572. /// The current world, view & projection matrices concatenated
  573. ACT_WORLDVIEWPROJ_MATRIX,
  574. /** Provides inverse of concatenated world, view and projection matrices.
  575. Equivalent to RenderMonkey's "WorldViewProjectionInverse".
  576. */
  577. ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
  578. /** Provides transpose of concatenated world, view and projection matrices.
  579. Equivalent to RenderMonkey's "WorldViewProjectionTranspose".
  580. */
  581. ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
  582. /** Provides inverse transpose of concatenated world, view and projection
  583. matrices. Equivalent to RenderMonkey's "WorldViewProjectionInverseTranspose".
  584. */
  585. ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
  586. /// render target related values
  587. /** -1 if requires texture flipping, +1 otherwise. It's useful when you bypassed
  588. projection matrix transform, still able use this value to adjust transformed y position.
  589. */
  590. ACT_RENDER_TARGET_FLIPPING,
  591. /** -1 if the winding has been inverted (e.g. for reflections), +1 otherwise.
  592. */
  593. ACT_VERTEX_WINDING,
  594. /// Fog colour
  595. ACT_FOG_COLOUR,
  596. /// Fog params: density, linear start, linear end, 1/(end-start)
  597. ACT_FOG_PARAMS,
  598. /// Surface ambient colour, as set in Pass::setAmbient
  599. ACT_SURFACE_AMBIENT_COLOUR,
  600. /// Surface diffuse colour, as set in Pass::setDiffuse
  601. ACT_SURFACE_DIFFUSE_COLOUR,
  602. /// Surface specular colour, as set in Pass::setSpecular
  603. ACT_SURFACE_SPECULAR_COLOUR,
  604. /// Surface emissive colour, as set in Pass::setSelfIllumination
  605. ACT_SURFACE_EMISSIVE_COLOUR,
  606. /// Surface shininess, as set in Pass::setShininess
  607. ACT_SURFACE_SHININESS,
  608. /// The number of active light sources (better than gl_MaxLights)
  609. ACT_LIGHT_COUNT,
  610. /// The ambient light colour set in the scene
  611. ACT_AMBIENT_LIGHT_COLOUR,
  612. /// Light diffuse colour (index determined by setAutoConstant call)
  613. ACT_LIGHT_DIFFUSE_COLOUR,
  614. /// Light specular colour (index determined by setAutoConstant call)
  615. ACT_LIGHT_SPECULAR_COLOUR,
  616. /// Light attenuation parameters, Vector4(range, constant, linear, quadric)
  617. ACT_LIGHT_ATTENUATION,
  618. /** Spotlight parameters, Vector4(innerFactor, outerFactor, falloff, isSpot)
  619. innerFactor and outerFactor are cos(angle/2)
  620. The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
  621. Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively
  622. */
  623. ACT_SPOTLIGHT_PARAMS,
  624. /// A light position in world space (index determined by setAutoConstant call)
  625. ACT_LIGHT_POSITION,
  626. /// A light position in object space (index determined by setAutoConstant call)
  627. ACT_LIGHT_POSITION_OBJECT_SPACE,
  628. /// A light position in view space (index determined by setAutoConstant call)
  629. ACT_LIGHT_POSITION_VIEW_SPACE,
  630. /// A light direction in world space (index determined by setAutoConstant call)
  631. ACT_LIGHT_DIRECTION,
  632. /// A light direction in object space (index determined by setAutoConstant call)
  633. ACT_LIGHT_DIRECTION_OBJECT_SPACE,
  634. /// A light direction in view space (index determined by setAutoConstant call)
  635. ACT_LIGHT_DIRECTION_VIEW_SPACE,
  636. /** The distance of the light from the center of the object
  637. a useful approximation as an alternative to per-vertex distance
  638. calculations.
  639. */
  640. ACT_LIGHT_DISTANCE_OBJECT_SPACE,
  641. /** Light power level, a single scalar as set in Light::setPowerScale (index determined by setAutoConstant call) */
  642. ACT_LIGHT_POWER_SCALE,
  643. /// Light diffuse colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
  644. ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
  645. /// Light specular colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
  646. ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
  647. /// Array of light diffuse colours (count set by extra param)
  648. ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
  649. /// Array of light specular colours (count set by extra param)
  650. ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
  651. /// Array of light diffuse colours scaled by light power (count set by extra param)
  652. ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
  653. /// Array of light specular colours scaled by light power (count set by extra param)
  654. ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
  655. /// Array of light attenuation parameters, Vector4(range, constant, linear, quadric) (count set by extra param)
  656. ACT_LIGHT_ATTENUATION_ARRAY,
  657. /// Array of light positions in world space (count set by extra param)
  658. ACT_LIGHT_POSITION_ARRAY,
  659. /// Array of light positions in object space (count set by extra param)
  660. ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
  661. /// Array of light positions in view space (count set by extra param)
  662. ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
  663. /// Array of light directions in world space (count set by extra param)
  664. ACT_LIGHT_DIRECTION_ARRAY,
  665. /// Array of light directions in object space (count set by extra param)
  666. ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
  667. /// Array of light directions in view space (count set by extra param)
  668. ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
  669. /** Array of distances of the lights from the center of the object
  670. a useful approximation as an alternative to per-vertex distance
  671. calculations. (count set by extra param)
  672. */
  673. ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
  674. /** Array of light power levels, a single scalar as set in Light::setPowerScale
  675. (count set by extra param)
  676. */
  677. ACT_LIGHT_POWER_SCALE_ARRAY,
  678. /** Spotlight parameters array of Vector4(innerFactor, outerFactor, falloff, isSpot)
  679. innerFactor and outerFactor are cos(angle/2)
  680. The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
  681. Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively.
  682. (count set by extra param)
  683. */
  684. ACT_SPOTLIGHT_PARAMS_ARRAY,
  685. /** The derived ambient light colour, with 'r', 'g', 'b' components filled with
  686. product of surface ambient colour and ambient light colour, respectively,
  687. and 'a' component filled with surface ambient alpha component.
  688. */
  689. ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
  690. /** The derived scene colour, with 'r', 'g' and 'b' components filled with sum
  691. of derived ambient light colour and surface emissive colour, respectively,
  692. and 'a' component filled with surface diffuse alpha component.
  693. */
  694. ACT_DERIVED_SCENE_COLOUR,
  695. /** The derived light diffuse colour (index determined by setAutoConstant call),
  696. with 'r', 'g' and 'b' components filled with product of surface diffuse colour,
  697. light power scale and light diffuse colour, respectively, and 'a' component filled with surface
  698. diffuse alpha component.
  699. */
  700. ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
  701. /** The derived light specular colour (index determined by setAutoConstant call),
  702. with 'r', 'g' and 'b' components filled with product of surface specular colour
  703. and light specular colour, respectively, and 'a' component filled with surface
  704. specular alpha component.
  705. */
  706. ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
  707. /// Array of derived light diffuse colours (count set by extra param)
  708. ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
  709. /// Array of derived light specular colours (count set by extra param)
  710. ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
  711. /** The absolute light number of a local light index. Each pass may have
  712. a number of lights passed to it, and each of these lights will have
  713. an index in the overall light list, which will differ from the local
  714. light index due to factors like setStartLight and setIteratePerLight.
  715. This binding provides the global light index for a local index.
  716. */
  717. ACT_LIGHT_NUMBER,
  718. /// Returns (int) 1 if the given light casts shadows, 0 otherwise (index set in extra param)
  719. ACT_LIGHT_CASTS_SHADOWS,
  720. /** The distance a shadow volume should be extruded when using
  721. finite extrusion programs.
  722. */
  723. ACT_SHADOW_EXTRUSION_DISTANCE,
  724. /// The current camera's position in world space
  725. ACT_CAMERA_POSITION,
  726. /// The current camera's position in object space
  727. ACT_CAMERA_POSITION_OBJECT_SPACE,
  728. /// The view/projection matrix of the assigned texture projection frustum
  729. ACT_TEXTURE_VIEWPROJ_MATRIX,
  730. /// Array of view/projection matrices of the first n texture projection frustums
  731. ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
  732. /** The view/projection matrix of the assigned texture projection frustum,
  733. combined with the current world matrix
  734. */
  735. ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
  736. /// Array of world/view/projection matrices of the first n texture projection frustums
  737. ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
  738. /// The view/projection matrix of a given spotlight
  739. ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
  740. /// Array of view/projection matrix of a given spotlight
  741. ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY,
  742. /** The view/projection matrix of a given spotlight projection frustum,
  743. combined with the current world matrix
  744. */
  745. ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
  746. /// A custom parameter which will come from the renderable, using 'data' as the identifier
  747. ACT_CUSTOM,
  748. /** provides current elapsed time
  749. */
  750. ACT_TIME,
  751. /** Single float value, which repeats itself based on given as
  752. parameter "cycle time". Equivalent to RenderMonkey's "Time0_X".
  753. */
  754. ACT_TIME_0_X,
  755. /// Cosine of "Time0_X". Equivalent to RenderMonkey's "CosTime0_X".
  756. ACT_COSTIME_0_X,
  757. /// Sine of "Time0_X". Equivalent to RenderMonkey's "SinTime0_X".
  758. ACT_SINTIME_0_X,
  759. /// Tangent of "Time0_X". Equivalent to RenderMonkey's "TanTime0_X".
  760. ACT_TANTIME_0_X,
  761. /** Vector of "Time0_X", "SinTime0_X", "CosTime0_X",
  762. "TanTime0_X". Equivalent to RenderMonkey's "Time0_X_Packed".
  763. */
  764. ACT_TIME_0_X_PACKED,
  765. /** Single float value, which represents scaled time value [0..1],
  766. which repeats itself based on given as parameter "cycle time".
  767. Equivalent to RenderMonkey's "Time0_1".
  768. */
  769. ACT_TIME_0_1,
  770. /// Cosine of "Time0_1". Equivalent to RenderMonkey's "CosTime0_1".
  771. ACT_COSTIME_0_1,
  772. /// Sine of "Time0_1". Equivalent to RenderMonkey's "SinTime0_1".
  773. ACT_SINTIME_0_1,
  774. /// Tangent of "Time0_1". Equivalent to RenderMonkey's "TanTime0_1".
  775. ACT_TANTIME_0_1,
  776. /** Vector of "Time0_1", "SinTime0_1", "CosTime0_1",
  777. "TanTime0_1". Equivalent to RenderMonkey's "Time0_1_Packed".
  778. */
  779. ACT_TIME_0_1_PACKED,
  780. /** Single float value, which represents scaled time value [0..2*Pi],
  781. which repeats itself based on given as parameter "cycle time".
  782. Equivalent to RenderMonkey's "Time0_2PI".
  783. */
  784. ACT_TIME_0_2PI,
  785. /// Cosine of "Time0_2PI". Equivalent to RenderMonkey's "CosTime0_2PI".
  786. ACT_COSTIME_0_2PI,
  787. /// Sine of "Time0_2PI". Equivalent to RenderMonkey's "SinTime0_2PI".
  788. ACT_SINTIME_0_2PI,
  789. /// Tangent of "Time0_2PI". Equivalent to RenderMonkey's "TanTime0_2PI".
  790. ACT_TANTIME_0_2PI,
  791. /** Vector of "Time0_2PI", "SinTime0_2PI", "CosTime0_2PI",
  792. "TanTime0_2PI". Equivalent to RenderMonkey's "Time0_2PI_Packed".
  793. */
  794. ACT_TIME_0_2PI_PACKED,
  795. /// provides the scaled frame time, returned as a floating point value.
  796. ACT_FRAME_TIME,
  797. /// provides the calculated frames per second, returned as a floating point value.
  798. ACT_FPS,
  799. /// viewport-related values
  800. /** Current viewport width (in pixels) as floating point value.
  801. Equivalent to RenderMonkey's "ViewportWidth".
  802. */
  803. ACT_VIEWPORT_WIDTH,
  804. /** Current viewport height (in pixels) as floating point value.
  805. Equivalent to RenderMonkey's "ViewportHeight".
  806. */
  807. ACT_VIEWPORT_HEIGHT,
  808. /** This variable represents 1.0/ViewportWidth.
  809. Equivalent to RenderMonkey's "ViewportWidthInverse".
  810. */
  811. ACT_INVERSE_VIEWPORT_WIDTH,
  812. /** This variable represents 1.0/ViewportHeight.
  813. Equivalent to RenderMonkey's "ViewportHeightInverse".
  814. */
  815. ACT_INVERSE_VIEWPORT_HEIGHT,
  816. /** Packed of "ViewportWidth", "ViewportHeight", "ViewportWidthInverse",
  817. "ViewportHeightInverse".
  818. */
  819. ACT_VIEWPORT_SIZE,
  820. /// view parameters
  821. /** This variable provides the view direction vector (world space).
  822. Equivalent to RenderMonkey's "ViewDirection".
  823. */
  824. ACT_VIEW_DIRECTION,
  825. /** This variable provides the view side vector (world space).
  826. Equivalent to RenderMonkey's "ViewSideVector".
  827. */
  828. ACT_VIEW_SIDE_VECTOR,
  829. /** This variable provides the view up vector (world space).
  830. Equivalent to RenderMonkey's "ViewUpVector".
  831. */
  832. ACT_VIEW_UP_VECTOR,
  833. /** This variable provides the field of view as a floating point value.
  834. Equivalent to RenderMonkey's "FOV".
  835. */
  836. ACT_FOV,
  837. /** This variable provides the near clip distance as a floating point value.
  838. Equivalent to RenderMonkey's "NearClipPlane".
  839. */
  840. ACT_NEAR_CLIP_DISTANCE,
  841. /** This variable provides the far clip distance as a floating point value.
  842. Equivalent to RenderMonkey's "FarClipPlane".
  843. */
  844. ACT_FAR_CLIP_DISTANCE,
  845. /** provides the pass index number within the technique
  846. of the active materil.
  847. */
  848. ACT_PASS_NUMBER,
  849. /** provides the current iteration number of the pass. The iteration
  850. number is the number of times the current render operation has
  851. been drawn for the active pass.
  852. */
  853. ACT_PASS_ITERATION_NUMBER,
  854. /** Provides a parametric animation value [0..1], only available
  855. where the renderable specifically implements it.
  856. */
  857. ACT_ANIMATION_PARAMETRIC,
  858. /** Provides the texel offsets required by this rendersystem to map
  859. texels to pixels. Packed as
  860. float4(absoluteHorizontalOffset, absoluteVerticalOffset,
  861. horizontalOffset / viewportWidth, verticalOffset / viewportHeight)
  862. */
  863. ACT_TEXEL_OFFSETS,
  864. /** Provides information about the depth range of the scene as viewed
  865. from the current camera.
  866. Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
  867. */
  868. ACT_SCENE_DEPTH_RANGE,
  869. /** Provides information about the depth range of the scene as viewed
  870. from a given shadow camera. Requires an index parameter which maps
  871. to a light index relative to the current light list.
  872. Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
  873. */
  874. ACT_SHADOW_SCENE_DEPTH_RANGE,
  875. /** Provides the fixed shadow colour as configured via SceneManager::setShadowColour;
  876. useful for integrated modulative shadows.
  877. */
  878. ACT_SHADOW_COLOUR,
  879. /** Provides texture size of the texture unit (index determined by setAutoConstant
  880. call). Packed as float4(width, height, depth, 1)
  881. */
  882. ACT_TEXTURE_SIZE,
  883. /** Provides inverse texture size of the texture unit (index determined by setAutoConstant
  884. call). Packed as float4(1 / width, 1 / height, 1 / depth, 1)
  885. */
  886. ACT_INVERSE_TEXTURE_SIZE,
  887. /** Provides packed texture size of the texture unit (index determined by setAutoConstant
  888. call). Packed as float4(width, height, 1 / width, 1 / height)
  889. */
  890. ACT_PACKED_TEXTURE_SIZE,
  891. /** Provides the current transform matrix of the texture unit (index determined by setAutoConstant
  892. call), as seen by the fixed-function pipeline.
  893. */
  894. ACT_TEXTURE_MATRIX,
  895. /** Provides the position of the LOD camera in world space, allowing you
  896. to perform separate LOD calculations in shaders independent of the rendering
  897. camera. If there is no separate LOD camera then this is the real camera
  898. position. See Camera::setLodCamera.
  899. */
  900. ACT_LOD_CAMERA_POSITION,
  901. /** Provides the position of the LOD camera in object space, allowing you
  902. to perform separate LOD calculations in shaders independent of the rendering
  903. camera. If there is no separate LOD camera then this is the real camera
  904. position. See Camera::setLodCamera.
  905. */
  906. ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,
  907. /** Binds custom per-light constants to the shaders. */
  908. ACT_LIGHT_CUSTOM
  909. };
  910. /** Defines the type of the extra data item used by the auto constant.
  911. */
  912. enum ACDataType {
  913. /// no data is required
  914. ACDT_NONE,
  915. /// the auto constant requires data of type int
  916. ACDT_INT,
  917. /// the auto constant requires data of type real
  918. ACDT_REAL
  919. };
  920. /** Defines the base element type of the auto constant
  921. */
  922. enum ElementType {
  923. ET_INT,
  924. ET_REAL
  925. };
  926. /** Structure defining an auto constant that's available for use in
  927. a parameters object.
  928. */
  929. struct AutoConstantDefinition
  930. {
  931. AutoConstantType acType;
  932. String name;
  933. size_t elementCount;
  934. /// The type of the constant in the program
  935. ElementType elementType;
  936. /// The type of any extra data
  937. ACDataType dataType;
  938. AutoConstantDefinition(AutoConstantType _acType, const String& _name,
  939. size_t _elementCount, ElementType _elementType,
  940. ACDataType _dataType)
  941. :acType(_acType), name(_name), elementCount(_elementCount),
  942. elementType(_elementType), dataType(_dataType)
  943. {
  944. }
  945. };
  946. /** Structure recording the use of an automatic parameter. */
  947. class AutoConstantEntry
  948. {
  949. public:
  950. /// The type of parameter
  951. AutoConstantType paramType;
  952. /// The target (physical) constant index
  953. size_t physicalIndex;
  954. /** The number of elements per individual entry in this constant
  955. Used in case people used packed elements smaller than 4 (e.g. GLSL)
  956. and bind an auto which is 4-element packed to it */
  957. size_t elementCount;
  958. /// Additional information to go with the parameter
  959. union{
  960. size_t data;
  961. Real fData;
  962. };
  963. /// The variability of this parameter (see GpuParamVariability)
  964. uint16 variability;
  965. AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData,
  966. uint16 theVariability, size_t theElemCount = 4)
  967. : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
  968. data(theData), variability(theVariability) {}
  969. AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData,
  970. uint16 theVariability, size_t theElemCount = 4)
  971. : paramType(theType), physicalIndex(theIndex), elementCount(theElemCount),
  972. fData(theData), variability(theVariability) {}
  973. };
  974. // Auto parameter storage
  975. typedef vector<AutoConstantEntry>::type AutoConstantList;
  976. typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
  977. protected:
  978. static AutoConstantDefinition AutoConstantDictionary[];
  979. /// Packed list of floating-point constants (physical indexing)
  980. FloatConstantList mFloatConstants;
  981. /// Packed list of integer constants (physical indexing)
  982. IntConstantList mIntConstants;
  983. /** Logical index to physical index map - for low-level programs
  984. or high-level programs which pass params this way. */
  985. GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
  986. /** Logical index to physical index map - for low-level programs
  987. or high-level programs which pass params this way. */
  988. GpuLogicalBufferStructPtr mIntLogicalToPhysical;
  989. /// Mapping from parameter names to def - high-level programs are expected to populate this
  990. GpuNamedConstantsPtr mNamedConstants;
  991. /// List of automatically updated parameters
  992. AutoConstantList mAutoConstants;
  993. /// The combined variability masks of all parameters
  994. uint16 mCombinedVariability;
  995. /// Do we need to transpose matrices?
  996. bool mTransposeMatrices;
  997. /// flag to indicate if names not found will be ignored
  998. bool mIgnoreMissingParams;
  999. /// physical index for active pass iteration parameter real constant entry;
  1000. size_t mActivePassIterationIndex;
  1001. /** Gets the low-level structure for a logical index.
  1002. */
  1003. GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
  1004. /** Gets the physical buffer index associated with a logical int constant index.
  1005. */
  1006. GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
  1007. /// Return the variability for an auto constant
  1008. uint16 deriveVariability(AutoConstantType act);
  1009. void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
  1010. GpuSharedParamUsageList mSharedParamSets;
  1011. //// Optional data the rendersystem might want to store
  1012. // TODO PORT - Commented out because I dont think its used
  1013. //mutable Any mRenderSystemData;
  1014. public:
  1015. GpuProgramParameters();
  1016. ~GpuProgramParameters() {}
  1017. /// Copy constructor
  1018. GpuProgramParameters(const GpuProgramParameters& oth);
  1019. /// Operator = overload
  1020. GpuProgramParameters& operator=(const GpuProgramParameters& oth);
  1021. /** Internal method for providing a link to a name->definition map for parameters. */
  1022. void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
  1023. /** Internal method for providing a link to a logical index->physical index map for parameters. */
  1024. void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap,
  1025. const GpuLogicalBufferStructPtr& intIndexMap);
  1026. /// Does this parameter set include named parameters?
  1027. bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
  1028. /** Does this parameter set include logically indexed parameters?
  1029. @note Not mutually exclusive with hasNamedParameters since some high-level
  1030. programs still use logical indexes to set the parameters on the
  1031. rendersystem.
  1032. */
  1033. bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
  1034. /** Sets a 4-element floating-point parameter to the program.
  1035. @param index The logical constant index at which to place the parameter
  1036. (each constant is a 4D float)
  1037. @param vec The value to set
  1038. */
  1039. void setConstant(size_t index, const Vector4& vec);
  1040. /** Sets a single floating-point parameter to the program.
  1041. @note This is actually equivalent to calling
  1042. setConstant(index Vector4(val, 0, 0, 0)) since all constants are 4D.
  1043. @param index The logical constant index at which to place the parameter (each constant is
  1044. a 4D float)
  1045. @param val The value to set
  1046. */
  1047. void setConstant(size_t index, Real val);
  1048. /** Sets a 4-element floating-point parameter to the program via Vector3.
  1049. @param index The logical constant index at which to place the parameter (each constant is
  1050. a 4D float).
  1051. Note that since you're passing a Vector3, the last element of the 4-element
  1052. value will be set to 1 (a homogeneous vector)
  1053. @param vec The value to set
  1054. */
  1055. void setConstant(size_t index, const Vector3& vec);
  1056. /** Sets a Matrix4 parameter to the program.
  1057. @param index The logical constant index at which to place the parameter (each constant is
  1058. a 4D float).
  1059. NB since a Matrix4 is 16 floats long, this parameter will take up 4 indexes.
  1060. @param m The value to set
  1061. */
  1062. void setConstant(size_t index, const Matrix4& m);
  1063. /** Sets a list of Matrix4 parameters to the program.
  1064. @param index The logical constant index at which to start placing the parameter (each constant is
  1065. a 4D float).
  1066. NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
  1067. @param m Pointer to an array of matrices to set
  1068. @param numEntries Number of Matrix4 entries
  1069. */
  1070. void setConstant(size_t index, const Matrix4* m, size_t numEntries);
  1071. /** Sets a multiple value constant floating-point parameter to the program.
  1072. @param index The logical constant index at which to start placing parameters (each constant is
  1073. a 4D float)
  1074. @param val Pointer to the values to write, must contain 4*count floats
  1075. @param count The number of groups of 4 floats to write
  1076. */
  1077. void setConstant(size_t index, const float *val, size_t count);
  1078. /** Sets a multiple value constant floating-point parameter to the program.
  1079. @param index The logical constant index at which to start placing parameters (each constant is
  1080. a 4D float)
  1081. @param val Pointer to the values to write, must contain 4*count floats
  1082. @param count The number of groups of 4 floats to write
  1083. */
  1084. void setConstant(size_t index, const double *val, size_t count);
  1085. /** Sets a ColourValue parameter to the program.
  1086. @param index The logical constant index at which to place the parameter (each constant is
  1087. a 4D float)
  1088. @param colour The value to set
  1089. */
  1090. void setConstant(size_t index, const ColourValue& colour);
  1091. /** Sets a multiple value constant integer parameter to the program.
  1092. @remarks
  1093. Different types of GPU programs support different types of constant parameters.
  1094. For example, it's relatively common to find that vertex programs only support
  1095. floating point constants, and that fragment programs only support integer (fixed point)
  1096. parameters. This can vary depending on the program version supported by the
  1097. graphics card being used. You should consult the documentation for the type of
  1098. low level program you are using, or alternatively use the methods
  1099. provided on RenderSystemCapabilities to determine the options.
  1100. @param index The logical constant index at which to place the parameter (each constant is
  1101. a 4D integer)
  1102. @param val Pointer to the values to write, must contain 4*count ints
  1103. @param count The number of groups of 4 ints to write
  1104. */
  1105. void setConstant(size_t index, const int *val, size_t count);
  1106. /** Write a series of floating point values into the underlying float
  1107. constant buffer at the given physical index.
  1108. @param physicalIndex The buffer position to start writing
  1109. @param val Pointer to a list of values to write
  1110. @param count The number of floats to write
  1111. */
  1112. void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
  1113. /** Write a series of floating point values into the underlying float
  1114. constant buffer at the given physical index.
  1115. @param physicalIndex The buffer position to start writing
  1116. @param val Pointer to a list of values to write
  1117. @param count The number of floats to write
  1118. */
  1119. void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
  1120. /** Write a series of integer values into the underlying integer
  1121. constant buffer at the given physical index.
  1122. @param physicalIndex The buffer position to start writing
  1123. @param val Pointer to a list of values to write
  1124. @param count The number of ints to write
  1125. */
  1126. void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
  1127. /** Read a series of floating point values from the underlying float
  1128. constant buffer at the given physical index.
  1129. @param physicalIndex The buffer position to start reading
  1130. @param count The number of floats to read
  1131. @param dest Pointer to a buffer to receive the values
  1132. */
  1133. void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
  1134. /** Read a series of integer values from the underlying integer
  1135. constant buffer at the given physical index.
  1136. @param physicalIndex The buffer position to start reading
  1137. @param count The number of ints to read
  1138. @param dest Pointer to a buffer to receive the values
  1139. */
  1140. void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
  1141. /** Write a 4-element floating-point parameter to the program directly to
  1142. the underlying constants buffer.
  1143. @note You can use these methods if you have already derived the physical
  1144. constant buffer location, for a slight speed improvement over using
  1145. the named / logical index versions.
  1146. @param physicalIndex The physical buffer index at which to place the parameter
  1147. @param vec The value to set
  1148. @param count The number of floats to write; if for example
  1149. the uniform constant 'slot' is smaller than a Vector4
  1150. */
  1151. void _writeRawConstant(size_t physicalIndex, const Vector4& vec,
  1152. size_t count = 4);
  1153. /** Write a single floating-point parameter to the program.
  1154. @note You can use these methods if you have already derived the physical
  1155. constant buffer location, for a slight speed improvement over using
  1156. the named / logical index versions.
  1157. @param physicalIndex The physical buffer index at which to place the parameter
  1158. @param val The value to set
  1159. */
  1160. void _writeRawConstant(size_t physicalIndex, Real val);
  1161. /** Write a single integer parameter to the program.
  1162. @note You can use these methods if you have already derived the physical
  1163. constant buffer location, for a slight speed improvement over using
  1164. the named / logical index versions.
  1165. @param physicalIndex The physical buffer index at which to place the parameter
  1166. @param val The value to set
  1167. */
  1168. void _writeRawConstant(size_t physicalIndex, int val);
  1169. /** Write a 3-element floating-point parameter to the program via Vector3.
  1170. @note You can use these methods if you have already derived the physical
  1171. constant buffer location, for a slight speed improvement over using
  1172. the named / logical index versions.
  1173. @param physicalIndex The physical buffer index at which to place the parameter
  1174. @param vec The value to set
  1175. */
  1176. void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
  1177. /** Write a Matrix4 parameter to the program.
  1178. @note You can use these methods if you have already derived the physical
  1179. constant buffer location, for a slight speed improvement over using
  1180. the named / logical index versions.
  1181. @param physicalIndex The physical buffer index at which to place the parameter
  1182. @param m The value to set
  1183. @param elementCount actual element count used with shader
  1184. */
  1185. void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
  1186. /** Write a list of Matrix4 parameters to the program.
  1187. @note You can use these methods if you have already derived the physical
  1188. constant buffer location, for a slight speed improvement over using
  1189. the named / logical index versions.
  1190. @param physicalIndex The physical buffer index at which to place the parameter
  1191. @param numEntries Number of Matrix4 entries
  1192. */
  1193. void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
  1194. /** Write a ColourValue parameter to the program.
  1195. @note You can use these methods if you have already derived the physical
  1196. constant buffer location, for a slight speed improvement over using
  1197. the named / logical index versions.
  1198. @param physicalIndex The physical buffer index at which to place the parameter
  1199. @param colour The value to set
  1200. @param count The number of floats to write; if for example
  1201. the uniform constant 'slot' is smaller than a Vector4
  1202. */
  1203. void _writeRawConstant(size_t physicalIndex, const ColourValue& colour,
  1204. size_t count = 4);
  1205. /** Gets an iterator over the named GpuConstantDefinition instances as defined
  1206. by the program for which these parameters exist.
  1207. @note
  1208. Only available if this parameters object has named parameters.
  1209. */
  1210. GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
  1211. /** Get a specific GpuConstantDefinition for a named parameter.
  1212. @note
  1213. Only available if this parameters object has named parameters.
  1214. */
  1215. const GpuConstantDefinition& getConstantDefinition(const String& name) const;
  1216. /** Get the full list of GpuConstantDefinition instances.
  1217. @note
  1218. Only available if this parameters object has named parameters.
  1219. */
  1220. const GpuNamedConstants& getConstantDefinitions() const;
  1221. /** Get the current list of mappings from low-level logical param indexes
  1222. to physical buffer locations in the float buffer.
  1223. @note
  1224. Only applicable to low-level programs.
  1225. */
  1226. const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
  1227. /** Retrieves the logical index relating to a physical index in the float
  1228. buffer, for programs which support that (low-level programs and
  1229. high-level programs which use logical parameter indexes).
  1230. @returns std::numeric_limits<size_t>::max() if not found
  1231. */
  1232. size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
  1233. /** Retrieves the logical index relating to a physical index in the int
  1234. buffer, for programs which support that (low-level programs and
  1235. high-level programs which use logical parameter indexes).
  1236. @returns std::numeric_limits<size_t>::max() if not found
  1237. */
  1238. size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
  1239. /** Get the current list of mappings from low-level logical param indexes
  1240. to physical buffer locations in the integer buffer.
  1241. @note
  1242. Only applicable to low-level programs.
  1243. */
  1244. const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
  1245. /// Get a reference to the list of float constants
  1246. const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
  1247. /// Get a pointer to the 'nth' item in the float buffer
  1248. float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
  1249. /// Get a pointer to the 'nth' item in the float buffer
  1250. const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
  1251. /// Get a reference to the list of int constants
  1252. const IntConstantList& getIntConstantList() const { return mIntConstants; }
  1253. /// Get a pointer to the 'nth' item in the int buffer
  1254. int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
  1255. /// Get a pointer to the 'nth' item in the int buffer
  1256. const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
  1257. /// Get a reference to the list of auto constant bindings
  1258. const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
  1259. /** Sets up a constant which will automatically be updated by the system.
  1260. @remarks
  1261. Vertex and fragment programs often need parameters which are to do with the
  1262. current render state, or particular values which may very well change over time,
  1263. and often between objects which are being rendered. This feature allows you
  1264. to set up a certain number of predefined parameter mappings that are kept up to
  1265. date for you.
  1266. @param index The location in the constant list to place this updated constant every time
  1267. it is changed. Note that because of the nature of the types, we know how big the
  1268. parameter details will be so you don't need to set that like you do for manual constants.
  1269. @param acType The type of automatic constant to set
  1270. @param extraInfo If the constant type needs more information (like a light index) put it here.
  1271. */
  1272. void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
  1273. void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
  1274. /** Sets up a constant which will automatically be updated by the system.
  1275. @remarks
  1276. Vertex and fragment programs often need parameters which are to do with the
  1277. current render state, or particular values which may very well change over time,
  1278. and often between objects which are being rendered. This feature allows you
  1279. to set up a certain number of predefined parameter mappings that are kept up to
  1280. date for you.
  1281. @param index The location in the constant list to place this updated constant every time
  1282. it is changed. Note that because of the nature of the types, we know how big the
  1283. parameter details will be so you don't need to set that like you do for manual constants.
  1284. @param acType The type of automatic constant to set
  1285. @param extraInfo1 The first extra parameter required by the auto constant type
  1286. @param extraInfo2 The first extra parameter required by the auto constant type
  1287. */
  1288. void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
  1289. /** As setAutoConstant, but sets up the auto constant directly against a
  1290. physical buffer index.
  1291. */
  1292. void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo,
  1293. uint16 variability, size_t elementSize = 4);
  1294. /** As setAutoConstantReal, but sets up the auto constant directly against a
  1295. physical buffer index.
  1296. */
  1297. void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData,
  1298. uint16 variability, size_t elementSize = 4);
  1299. /** Unbind an auto constant so that the constant is manually controlled again. */
  1300. void clearAutoConstant(size_t index);
  1301. /** Sets a named parameter up to track a derivation of the current time.
  1302. @param index The index of the parameter
  1303. @param factor The amount by which to scale the time value
  1304. */
  1305. void setConstantFromTime(size_t index, Real factor);
  1306. /** Clears all the existing automatic constants. */
  1307. void clearAutoConstants(void);
  1308. typedef AutoConstantList::const_iterator AutoConstantIterator;
  1309. /** Gets an iterator over the automatic constant bindings currently in place. */
  1310. AutoConstantIterator getAutoConstantIterator(void) const;
  1311. /// Gets the number of int constants that have been set
  1312. size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
  1313. /** Gets a specific Auto Constant entry if index is in valid range
  1314. otherwise returns a NULL
  1315. @param index which entry is to be retrieved
  1316. */
  1317. AutoConstantEntry* getAutoConstantEntry(const size_t index);
  1318. /** Returns true if this instance has any automatic constants. */
  1319. bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
  1320. /** Finds an auto constant that's affecting a given logical parameter
  1321. index for floating-point values.
  1322. @note Only applicable for low-level programs.
  1323. */
  1324. const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
  1325. /** Finds an auto constant that's affecting a given logical parameter
  1326. index for integer values.
  1327. @note Only applicable for low-level programs.
  1328. */
  1329. const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
  1330. /** Finds an auto constant that's affecting a given named parameter index.
  1331. @note Only applicable to high-level programs.
  1332. */
  1333. const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
  1334. /** Finds an auto constant that's affecting a given physical position in
  1335. the floating-point buffer
  1336. */
  1337. const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
  1338. /** Finds an auto constant that's affecting a given physical position in
  1339. the integer buffer
  1340. */
  1341. const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
  1342. /** Tells the program whether to ignore missing parameters or not.
  1343. */
  1344. void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
  1345. /** Sets a single value constant floating-point parameter to the program.
  1346. @remarks
  1347. Different types of GPU programs support different types of constant parameters.
  1348. For example, it's relatively common to find that vertex programs only support
  1349. floating point constants, and that fragment programs only support integer (fixed point)
  1350. parameters. This can vary depending on the program version supported by the
  1351. graphics card being used. You should consult the documentation for the type of
  1352. low level program you are using, or alternatively use the methods
  1353. provided on RenderSystemCapabilities to determine the options.
  1354. @par
  1355. Another possible limitation is that some systems only allow constants to be set
  1356. on certain boundaries, e.g. in sets of 4 values for example. Again, see
  1357. RenderSystemCapabilities for full details.
  1358. @note
  1359. This named option will only work if you are using a parameters object created
  1360. from a high-level program (HighLevelGpuProgram).
  1361. @param name The name of the parameter
  1362. @param val The value to set
  1363. */
  1364. void setNamedConstant(const String& name, Real val);
  1365. /** Sets a single value constant integer parameter to the program.
  1366. @remarks
  1367. Different types of GPU programs support different types of constant parameters.
  1368. For example, it's relatively common to find that vertex programs only support
  1369. floating point constants, and that fragment programs only support integer (fixed point)
  1370. parameters. This can vary depending on the program version supported by the
  1371. graphics card being used. You should consult the documentation for the type of
  1372. low level program you are using, or alternatively use the methods
  1373. provided on RenderSystemCapabilities to determine the options.
  1374. @par
  1375. Another possible limitation is that some systems only allow constants to be set
  1376. on certain boundaries, e.g. in sets of 4 values for example. Again, see
  1377. RenderSystemCapabilities for full details.
  1378. @note
  1379. This named option will only work if you are using a parameters object created
  1380. from a high-level program (HighLevelGpuProgram).
  1381. @param name The name of the parameter
  1382. @param val The value to set
  1383. */
  1384. void setNamedConstant(const String& name, int val);
  1385. /** Sets a Vector4 parameter to the program.
  1386. @param name The name of the parameter
  1387. @param vec The value to set
  1388. */
  1389. void setNamedConstant(const String& name, const Vector4& vec);
  1390. /** Sets a Vector3 parameter to the program.
  1391. @note
  1392. This named option will only work if you are using a parameters object created
  1393. from a high-level program (HighLevelGpuProgram).
  1394. @param index The index at which to place the parameter
  1395. NB this index refers to the number of floats, so a Vector3 is 3. Note that many
  1396. rendersystems & programs assume that every floating point parameter is passed in
  1397. as a vector of 4 items, so you are strongly advised to check with
  1398. RenderSystemCapabilities before using this version - if in doubt use Vector4
  1399. or ColourValue instead (both are 4D).
  1400. @param vec The value to set
  1401. */
  1402. void setNamedConstant(const String& name, const Vector3& vec);
  1403. /** Sets a Matrix4 parameter to the program.
  1404. @param name The name of the parameter
  1405. @param m The value to set
  1406. */
  1407. void setNamedConstant(const String& name, const Matrix4& m);
  1408. /** Sets a list of Matrix4 parameters to the program.
  1409. @param name The name of the parameter; this must be the first index of an array,
  1410. for examples 'matrices[0]'
  1411. NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
  1412. @param m Pointer to an array of matrices to set
  1413. @param numEntries Number of Matrix4 entries
  1414. */
  1415. void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
  1416. /** Sets a multiple value constant floating-point parameter to the program.
  1417. @par
  1418. Some systems only allow constants to be set on certain boundaries,
  1419. e.g. in sets of 4 values for example. The 'multiple' parameter allows
  1420. you to control that although you should only change it if you know
  1421. your chosen language supports that (at the time of writing, only
  1422. GLSL allows constants which are not a multiple of 4).
  1423. @note
  1424. This named option will only work if you are using a parameters object created
  1425. from a high-level program (HighLevelGpuProgram).
  1426. @param name The name of the parameter
  1427. @param val Pointer to the values to write
  1428. @param count The number of 'multiples' of floats to write
  1429. @param multiple The number of raw entries in each element to write,
  1430. the default is 4 so count = 1 would write 4 floats.
  1431. */
  1432. void setNamedConstant(const String& name, const float *val, size_t count,
  1433. size_t multiple = 4);
  1434. /** Sets a multiple value constant floating-point parameter to the program.
  1435. @par
  1436. Some systems only allow constants to be set on certain boundaries,
  1437. e.g. in sets of 4 values for example. The 'multiple' parameter allows
  1438. you to control that although you should only change it if you know
  1439. your chosen language supports that (at the time of writing, only
  1440. GLSL allows constants which are not a multiple of 4).
  1441. @note
  1442. This named option will only work if you are using a parameters object created
  1443. from a high-level program (HighLevelGpuProgram).
  1444. @param name The name of the parameter
  1445. @param val Pointer to the values to write
  1446. @param count The number of 'multiples' of floats to write
  1447. @param multiple The number of raw entries in each element to write,
  1448. the default is 4 so count = 1 would write 4 floats.
  1449. */
  1450. void setNamedConstant(const String& name, const double *val, size_t count,
  1451. size_t multiple = 4);
  1452. /** Sets a ColourValue parameter to the program.
  1453. @param name The name of the parameter
  1454. @param colour The value to set
  1455. */
  1456. void setNamedConstant(const String& name, const ColourValue& colour);
  1457. /** Sets a multiple value constant floating-point parameter to the program.
  1458. @par
  1459. Some systems only allow constants to be set on certain boundaries,
  1460. e.g. in sets of 4 values for example. The 'multiple' parameter allows
  1461. you to control that although you should only change it if you know
  1462. your chosen language supports that (at the time of writing, only
  1463. GLSL allows constants which are not a multiple of 4).
  1464. @note
  1465. This named option will only work if you are using a parameters object created
  1466. from a high-level program (HighLevelGpuProgram).
  1467. @param name The name of the parameter
  1468. @param val Pointer to the values to write
  1469. @param count The number of 'multiples' of floats to write
  1470. @param multiple The number of raw entries in each element to write,
  1471. the default is 4 so count = 1 would write 4 floats.
  1472. */
  1473. void setNamedConstant(const String& name, const int *val, size_t count,
  1474. size_t multiple = 4);
  1475. /** Sets up a constant which will automatically be updated by the system.
  1476. @remarks
  1477. Vertex and fragment programs often need parameters which are to do with the
  1478. current render state, or particular values which may very well change over time,
  1479. and often between objects which are being rendered. This feature allows you
  1480. to set up a certain number of predefined parameter mappings that are kept up to
  1481. date for you.
  1482. @note
  1483. This named option will only work if you are using a parameters object created
  1484. from a high-level program (HighLevelGpuProgram).
  1485. @param name The name of the parameter
  1486. @param acType The type of automatic constant to set
  1487. @param extraInfo If the constant type needs more information (like a light index) put it here.
  1488. */
  1489. void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
  1490. void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
  1491. /** Sets up a constant which will automatically be updated by the system.
  1492. @remarks
  1493. Vertex and fragment programs often need parameters which are to do with the
  1494. current render state, or particular values which may very well change over time,
  1495. and often between objects which are being rendered. This feature allows you
  1496. to set up a certain number of predefined parameter mappings that are kept up to
  1497. date for you.
  1498. @note
  1499. This named option will only work if you are using a parameters object created
  1500. from a high-level program (HighLevelGpuProgram).
  1501. @param name The name of the parameter
  1502. @param acType The type of automatic constant to set
  1503. @param extraInfo1 The first extra info required by this auto constant type
  1504. @param extraInfo2 The first extra info required by this auto constant type
  1505. */
  1506. void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
  1507. /** Sets a named parameter up to track a derivation of the current time.
  1508. @note
  1509. This named option will only work if you are using a parameters object created
  1510. from a high-level program (HighLevelGpuProgram).
  1511. @param name The name of the parameter
  1512. @param factor The amount by which to scale the time value
  1513. */
  1514. void setNamedConstantFromTime(const String& name, Real factor);
  1515. /** Unbind an auto constant so that the constant is manually controlled again. */
  1516. void clearNamedAutoConstant(const String& name);
  1517. /** Find a constant definition for a named parameter.
  1518. @remarks
  1519. This method returns null if the named parameter did not exist, unlike
  1520. getConstantDefinition which is more strict; unless you set the
  1521. last parameter to true.
  1522. @param name The name to look up
  1523. @param throwExceptionIfMissing If set to true, failure to find an entry
  1524. will throw an exception.
  1525. */
  1526. const GpuConstantDefinition* _findNamedConstantDefinition(
  1527. const String& name, bool throwExceptionIfMissing = false) const;
  1528. /** Gets the physical buffer index associated with a logical float constant index.
  1529. @note Only applicable to low-level programs.
  1530. @param logicalIndex The logical parameter index
  1531. @param requestedSize The requested size - pass 0 to ignore missing entries
  1532. and return std::numeric_limits<size_t>::max()
  1533. */
  1534. size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
  1535. /** Gets the physical buffer index associated with a logical int constant index.
  1536. @note Only applicable to low-level programs.
  1537. @param logicalIndex The logical parameter index
  1538. @param requestedSize The requested size - pass 0 to ignore missing entries
  1539. and return std::numeric_limits<size_t>::max()
  1540. */
  1541. size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
  1542. /** Sets whether or not we need to transpose the matrices passed in from the rest of OGRE.
  1543. @remarks
  1544. D3D uses transposed matrices compared to GL and OGRE; this is not important when you
  1545. use programs which are written to process row-major matrices, such as those generated
  1546. by Cg, but if you use a program written to D3D's matrix layout you will need to enable
  1547. this flag.
  1548. */
  1549. void setTransposeMatrices(bool val) { mTransposeMatrices = val; }
  1550. /// Gets whether or not matrices are to be transposed when set
  1551. bool getTransposeMatrices(void) const { return mTransposeMatrices; }
  1552. /** Copies the values of all constants (including auto constants) from another
  1553. GpuProgramParameters object.
  1554. @note This copes the internal storage of the paarameters object and therefore
  1555. can only be used for parameters objects created from the same GpuProgram.
  1556. To merge parameters that match from different programs, use copyMatchingNamedConstantsFrom.
  1557. */
  1558. void copyConstantsFrom(const GpuProgramParameters& source);
  1559. /** Copies the values of all matching named constants (including auto constants) from
  1560. another GpuProgramParameters object.
  1561. @remarks
  1562. This method iterates over the named constants in another parameters object
  1563. and copies across the values where they match. This method is safe to
  1564. use when the 2 parameters objects came from different programs, but only
  1565. works for named parameters.
  1566. */
  1567. void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
  1568. /** gets the auto constant definition associated with name if found else returns NULL
  1569. @param name The name of the auto constant
  1570. */
  1571. static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
  1572. /** gets the auto constant definition using an index into the auto constant definition array.
  1573. If the index is out of bounds then NULL is returned;
  1574. @param idx The auto constant index
  1575. */
  1576. static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
  1577. /** Returns the number of auto constant definitions
  1578. */
  1579. static size_t getNumAutoConstantDefinitions(void);
  1580. /** increments the multipass number entry by 1 if it exists
  1581. */
  1582. void incPassIterationNumber(void);
  1583. /** Does this parameters object have a pass iteration number constant? */
  1584. bool hasPassIterationNumber() const
  1585. { return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
  1586. /** Get the physical buffer index of the pass iteration number constant */
  1587. size_t getPassIterationNumberIndex() const
  1588. { return mActivePassIterationIndex; }
  1589. /** Use a set of shared parameters in this parameters object.
  1590. @remarks
  1591. Allows you to use a set of shared parameters to automatically update
  1592. this parameter set.
  1593. */
  1594. void addSharedParameters(GpuSharedParametersPtr sharedParams);
  1595. /** Use a set of shared parameters in this parameters object.
  1596. @remarks
  1597. Allows you to use a set of shared parameters to automatically update
  1598. this parameter set.
  1599. @param sharedParamsName The name of a shared parameter set as defined in
  1600. GpuProgramManager
  1601. */
  1602. void addSharedParameters(const String& sharedParamsName);
  1603. /** Returns whether this parameter set is using the named shared parameter set. */
  1604. bool isUsingSharedParameters(const String& sharedParamsName) const;
  1605. /** Stop using the named shared parameter set. */
  1606. void removeSharedParameters(const String& sharedParamsName);
  1607. /** Stop using all shared parameter sets. */
  1608. void removeAllSharedParameters();
  1609. /** Get the list of shared parameter sets. */
  1610. const GpuSharedParamUsageList& getSharedParameters() const;
  1611. // TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
  1612. ///** Internal method that the RenderSystem might use to store optional data. */
  1613. //void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
  1614. ///** Internal method that the RenderSystem might use to store optional data. */
  1615. //const Any& _getRenderSystemData() const { return mRenderSystemData; }
  1616. /** Update the parameters by copying the data from the shared
  1617. parameters.
  1618. @note This method may not actually be called if the RenderSystem
  1619. supports using shared parameters directly in their own shared buffer; in
  1620. which case the values should not be copied out of the shared area
  1621. into the individual parameter set, but bound separately.
  1622. */
  1623. void _copySharedParams();
  1624. };
  1625. /// Shared pointer used to hold references to GpuProgramParameters instances
  1626. typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
  1627. /** @} */
  1628. /** @} */
  1629. }
  1630. #endif