CmGpuProgramParams.h 74 KB

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