OgreCommon.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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 __Common_H__
  25. #define __Common_H__
  26. // Common stuff
  27. #include "OgreString.h"
  28. #if defined ( OGRE_GCC_VISIBILITY )
  29. # pragma GCC visibility push(default)
  30. #endif
  31. #include <utility>
  32. #include <sstream>
  33. #if defined ( OGRE_GCC_VISIBILITY )
  34. # pragma GCC visibility pop
  35. #endif
  36. namespace Ogre {
  37. /** \addtogroup Core
  38. * @{
  39. */
  40. /** \addtogroup General
  41. * @{
  42. */
  43. /// Fast general hashing algorithm
  44. uint32 _OgreExport FastHash (const char * data, int len, uint32 hashSoFar = 0);
  45. /// Combine hashes with same style as boost::hash_combine
  46. template <typename T>
  47. uint32 HashCombine (uint32 hashSoFar, const T& data)
  48. {
  49. return FastHash((const char*)&data, sizeof(T), hashSoFar);
  50. }
  51. /** Comparison functions used for the depth/stencil buffer operations and
  52. others. */
  53. enum CompareFunction
  54. {
  55. CMPF_ALWAYS_FAIL,
  56. CMPF_ALWAYS_PASS,
  57. CMPF_LESS,
  58. CMPF_LESS_EQUAL,
  59. CMPF_EQUAL,
  60. CMPF_NOT_EQUAL,
  61. CMPF_GREATER_EQUAL,
  62. CMPF_GREATER
  63. };
  64. /** High-level filtering options providing shortcuts to settings the
  65. minification, magnification and mip filters. */
  66. enum TextureFilterOptions
  67. {
  68. /// Equal to: min=FO_POINT, mag=FO_POINT, mip=FO_NONE
  69. TFO_NONE,
  70. /// Equal to: min=FO_LINEAR, mag=FO_LINEAR, mip=FO_POINT
  71. TFO_BILINEAR,
  72. /// Equal to: min=FO_LINEAR, mag=FO_LINEAR, mip=FO_LINEAR
  73. TFO_TRILINEAR,
  74. /// Equal to: min=FO_ANISOTROPIC, max=FO_ANISOTROPIC, mip=FO_LINEAR
  75. TFO_ANISOTROPIC
  76. };
  77. enum FilterType
  78. {
  79. /// The filter used when shrinking a texture
  80. FT_MIN,
  81. /// The filter used when magnifying a texture
  82. FT_MAG,
  83. /// The filter used when determining the mipmap
  84. FT_MIP
  85. };
  86. /** Filtering options for textures / mipmaps. */
  87. enum FilterOptions
  88. {
  89. /// No filtering, used for FILT_MIP to turn off mipmapping
  90. FO_NONE,
  91. /// Use the closest pixel
  92. FO_POINT,
  93. /// Average of a 2x2 pixel area, denotes bilinear for MIN and MAG, trilinear for MIP
  94. FO_LINEAR,
  95. /// Similar to FO_LINEAR, but compensates for the angle of the texture plane
  96. FO_ANISOTROPIC
  97. };
  98. /** Light shading modes. */
  99. enum ShadeOptions
  100. {
  101. SO_FLAT,
  102. SO_GOURAUD,
  103. SO_PHONG
  104. };
  105. /** Fog modes. */
  106. enum FogMode
  107. {
  108. /// No fog. Duh.
  109. FOG_NONE,
  110. /// Fog density increases exponentially from the camera (fog = 1/e^(distance * density))
  111. FOG_EXP,
  112. /// Fog density increases at the square of FOG_EXP, i.e. even quicker (fog = 1/e^(distance * density)^2)
  113. FOG_EXP2,
  114. /// Fog density increases linearly between the start and end distances
  115. FOG_LINEAR
  116. };
  117. /** Hardware culling modes based on vertex winding.
  118. This setting applies to how the hardware API culls triangles it is sent. */
  119. enum CullingMode
  120. {
  121. /// Hardware never culls triangles and renders everything it receives.
  122. CULL_NONE = 1,
  123. /// Hardware culls triangles whose vertices are listed clockwise in the view (default).
  124. CULL_CLOCKWISE = 2,
  125. /// Hardware culls triangles whose vertices are listed anticlockwise in the view.
  126. CULL_ANTICLOCKWISE = 3
  127. };
  128. /** Manual culling modes based on vertex normals.
  129. This setting applies to how the software culls triangles before sending them to the
  130. hardware API. This culling mode is used by scene managers which choose to implement it -
  131. normally those which deal with large amounts of fixed world geometry which is often
  132. planar (software culling movable variable geometry is expensive). */
  133. enum ManualCullingMode
  134. {
  135. /// No culling so everything is sent to the hardware.
  136. MANUAL_CULL_NONE = 1,
  137. /// Cull triangles whose normal is pointing away from the camera (default).
  138. MANUAL_CULL_BACK = 2,
  139. /// Cull triangles whose normal is pointing towards the camera.
  140. MANUAL_CULL_FRONT = 3
  141. };
  142. /** Enumerates the wave types usable with the Ogre engine. */
  143. enum WaveformType
  144. {
  145. /// Standard sine wave which smoothly changes from low to high and back again.
  146. WFT_SINE,
  147. /// An angular wave with a constant increase / decrease speed with pointed peaks.
  148. WFT_TRIANGLE,
  149. /// Half of the time is spent at the min, half at the max with instant transition between.
  150. WFT_SQUARE,
  151. /// Gradual steady increase from min to max over the period with an instant return to min at the end.
  152. WFT_SAWTOOTH,
  153. /// Gradual steady decrease from max to min over the period, with an instant return to max at the end.
  154. WFT_INVERSE_SAWTOOTH,
  155. /// Pulse Width Modulation. Works like WFT_SQUARE, except the high to low transition is controlled by duty cycle.
  156. /// With a duty cycle of 50% (0.5) will give the same output as WFT_SQUARE.
  157. WFT_PWM
  158. };
  159. /** The polygon mode to use when rasterising. */
  160. enum PolygonMode
  161. {
  162. /// Only points are rendered.
  163. PM_POINTS = 1,
  164. /// Wireframe models are rendered.
  165. PM_WIREFRAME = 2,
  166. /// Solid polygons are rendered.
  167. PM_SOLID = 3
  168. };
  169. /** An enumeration of broad shadow techniques */
  170. enum ShadowTechnique
  171. {
  172. /** No shadows */
  173. SHADOWTYPE_NONE = 0x00,
  174. /** Mask for additive shadows (not for direct use, use SHADOWTYPE_ enum instead)
  175. */
  176. SHADOWDETAILTYPE_ADDITIVE = 0x01,
  177. /** Mask for modulative shadows (not for direct use, use SHADOWTYPE_ enum instead)
  178. */
  179. SHADOWDETAILTYPE_MODULATIVE = 0x02,
  180. /** Mask for integrated shadows (not for direct use, use SHADOWTYPE_ enum instead)
  181. */
  182. SHADOWDETAILTYPE_INTEGRATED = 0x04,
  183. /** Mask for stencil shadows (not for direct use, use SHADOWTYPE_ enum instead)
  184. */
  185. SHADOWDETAILTYPE_STENCIL = 0x10,
  186. /** Mask for texture shadows (not for direct use, use SHADOWTYPE_ enum instead)
  187. */
  188. SHADOWDETAILTYPE_TEXTURE = 0x20,
  189. /** Stencil shadow technique which renders all shadow volumes as
  190. a modulation after all the non-transparent areas have been
  191. rendered. This technique is considerably less fillrate intensive
  192. than the additive stencil shadow approach when there are multiple
  193. lights, but is not an accurate model.
  194. */
  195. SHADOWTYPE_STENCIL_MODULATIVE = 0x12,
  196. /** Stencil shadow technique which renders each light as a separate
  197. additive pass to the scene. This technique can be very fillrate
  198. intensive because it requires at least 2 passes of the entire
  199. scene, more if there are multiple lights. However, it is a more
  200. accurate model than the modulative stencil approach and this is
  201. especially apparent when using coloured lights or bump mapping.
  202. */
  203. SHADOWTYPE_STENCIL_ADDITIVE = 0x11,
  204. /** Texture-based shadow technique which involves a monochrome render-to-texture
  205. of the shadow caster and a projection of that texture onto the
  206. shadow receivers as a modulative pass.
  207. */
  208. SHADOWTYPE_TEXTURE_MODULATIVE = 0x22,
  209. /** Texture-based shadow technique which involves a render-to-texture
  210. of the shadow caster and a projection of that texture onto the
  211. shadow receivers, built up per light as additive passes.
  212. This technique can be very fillrate intensive because it requires numLights + 2
  213. passes of the entire scene. However, it is a more accurate model than the
  214. modulative approach and this is especially apparent when using coloured lights
  215. or bump mapping.
  216. */
  217. SHADOWTYPE_TEXTURE_ADDITIVE = 0x21,
  218. /** Texture-based shadow technique which involves a render-to-texture
  219. of the shadow caster and a projection of that texture on to the shadow
  220. receivers, with the usage of those shadow textures completely controlled
  221. by the materials of the receivers.
  222. This technique is easily the most flexible of all techniques because
  223. the material author is in complete control over how the shadows are
  224. combined with regular rendering. It can perform shadows as accurately
  225. as SHADOWTYPE_TEXTURE_ADDITIVE but more efficiently because it requires
  226. less passes. However it also requires more expertise to use, and
  227. in almost all cases, shader capable hardware to really use to the full.
  228. @note The 'additive' part of this mode means that the colour of
  229. the rendered shadow texture is by default plain black. It does
  230. not mean it does the adding on your receivers automatically though, how you
  231. use that result is up to you.
  232. */
  233. SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED = 0x25,
  234. /** Texture-based shadow technique which involves a render-to-texture
  235. of the shadow caster and a projection of that texture on to the shadow
  236. receivers, with the usage of those shadow textures completely controlled
  237. by the materials of the receivers.
  238. This technique is easily the most flexible of all techniques because
  239. the material author is in complete control over how the shadows are
  240. combined with regular rendering. It can perform shadows as accurately
  241. as SHADOWTYPE_TEXTURE_ADDITIVE but more efficiently because it requires
  242. less passes. However it also requires more expertise to use, and
  243. in almost all cases, shader capable hardware to really use to the full.
  244. @note The 'modulative' part of this mode means that the colour of
  245. the rendered shadow texture is by default the 'shadow colour'. It does
  246. not mean it modulates on your receivers automatically though, how you
  247. use that result is up to you.
  248. */
  249. SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED = 0x26
  250. };
  251. /** An enumeration describing which material properties should track the vertex colours */
  252. typedef int TrackVertexColourType;
  253. enum TrackVertexColourEnum {
  254. TVC_NONE = 0x0,
  255. TVC_AMBIENT = 0x1,
  256. TVC_DIFFUSE = 0x2,
  257. TVC_SPECULAR = 0x4,
  258. TVC_EMISSIVE = 0x8
  259. };
  260. /** Sort mode for billboard-set and particle-system */
  261. enum SortMode
  262. {
  263. /** Sort by direction of the camera */
  264. SM_DIRECTION,
  265. /** Sort by distance from the camera */
  266. SM_DISTANCE
  267. };
  268. /** Defines the frame buffer types. */
  269. enum FrameBufferType {
  270. FBT_COLOUR = 0x1,
  271. FBT_DEPTH = 0x2,
  272. FBT_STENCIL = 0x4
  273. };
  274. /** A hashed vector.
  275. */
  276. template <typename T>
  277. class HashedVector
  278. {
  279. public:
  280. typedef std::vector<T> VectorImpl;
  281. protected:
  282. VectorImpl mList;
  283. mutable uint32 mListHash;
  284. mutable bool mListHashDirty;
  285. void addToHash(const T& newPtr) const
  286. {
  287. mListHash = FastHash((const char*)&newPtr, sizeof(T), mListHash);
  288. }
  289. void recalcHash() const
  290. {
  291. mListHash = 0;
  292. for (const_iterator i = mList.begin(); i != mList.end(); ++i)
  293. addToHash(*i);
  294. mListHashDirty = false;
  295. }
  296. public:
  297. typedef typename VectorImpl::value_type value_type;
  298. typedef typename VectorImpl::pointer pointer;
  299. typedef typename VectorImpl::reference reference;
  300. typedef typename VectorImpl::const_reference const_reference;
  301. typedef typename VectorImpl::size_type size_type;
  302. typedef typename VectorImpl::difference_type difference_type;
  303. typedef typename VectorImpl::iterator iterator;
  304. typedef typename VectorImpl::const_iterator const_iterator;
  305. typedef typename VectorImpl::reverse_iterator reverse_iterator;
  306. typedef typename VectorImpl::const_reverse_iterator const_reverse_iterator;
  307. void dirtyHash()
  308. {
  309. mListHashDirty = true;
  310. }
  311. bool isHashDirty() const
  312. {
  313. return mListHashDirty;
  314. }
  315. iterator begin()
  316. {
  317. // we have to assume that hash needs recalculating on non-const
  318. dirtyHash();
  319. return mList.begin();
  320. }
  321. iterator end() { return mList.end(); }
  322. const_iterator begin() const { return mList.begin(); }
  323. const_iterator end() const { return mList.end(); }
  324. reverse_iterator rbegin()
  325. {
  326. // we have to assume that hash needs recalculating on non-const
  327. dirtyHash();
  328. return mList.rbegin();
  329. }
  330. reverse_iterator rend() { return mList.rend(); }
  331. const_reverse_iterator rbegin() const { return mList.rbegin(); }
  332. const_reverse_iterator rend() const { return mList.rend(); }
  333. size_type size() const { return mList.size(); }
  334. size_type max_size() const { return mList.max_size(); }
  335. size_type capacity() const { return mList.capacity(); }
  336. bool empty() const { return mList.empty(); }
  337. reference operator[](size_type n)
  338. {
  339. // we have to assume that hash needs recalculating on non-const
  340. dirtyHash();
  341. return mList[n];
  342. }
  343. const_reference operator[](size_type n) const { return mList[n]; }
  344. reference at(size_type n)
  345. {
  346. // we have to assume that hash needs recalculating on non-const
  347. dirtyHash();
  348. return mList.const_iterator(n);
  349. }
  350. const_reference at(size_type n) const { return mList.at(n); }
  351. HashedVector() : mListHash(0), mListHashDirty(false) {}
  352. HashedVector(size_type n) : mList(n), mListHash(0), mListHashDirty(n > 0) {}
  353. HashedVector(size_type n, const T& t) : mList(n, t), mListHash(0), mListHashDirty(n > 0) {}
  354. HashedVector(const HashedVector<T>& rhs)
  355. : mList(rhs.mList), mListHash(rhs.mListHash), mListHashDirty(rhs.mListHashDirty) {}
  356. template <class InputIterator>
  357. HashedVector(InputIterator a, InputIterator b)
  358. : mList(a, b), mListHashDirty(false)
  359. {
  360. dirtyHash();
  361. }
  362. ~HashedVector() {}
  363. HashedVector<T>& operator=(const HashedVector<T>& rhs)
  364. {
  365. mList = rhs.mList;
  366. mListHash = rhs.mListHash;
  367. mListHashDirty = rhs.mListHashDirty;
  368. return *this;
  369. }
  370. void reserve(size_t t) { mList.reserve(t); }
  371. reference front()
  372. {
  373. // we have to assume that hash needs recalculating on non-const
  374. dirtyHash();
  375. return mList.front();
  376. }
  377. const_reference front() const { return mList.front(); }
  378. reference back()
  379. {
  380. // we have to assume that hash needs recalculating on non-const
  381. dirtyHash();
  382. return mList.back();
  383. }
  384. const_reference back() const { return mList.back(); }
  385. void push_back(const T& t)
  386. {
  387. mList.push_back(t);
  388. // Quick progressive hash add
  389. if (!isHashDirty())
  390. addToHash(t);
  391. }
  392. void pop_back()
  393. {
  394. mList.pop_back();
  395. dirtyHash();
  396. }
  397. void swap(HashedVector<T>& rhs)
  398. {
  399. mList.swap(rhs.mList);
  400. dirtyHash();
  401. }
  402. iterator insert(iterator pos, const T& t)
  403. {
  404. bool recalc = (pos != end());
  405. iterator ret = mList.insert(pos, t);
  406. if (recalc)
  407. dirtyHash();
  408. else
  409. addToHash(t);
  410. return ret;
  411. }
  412. template <class InputIterator>
  413. void insert(iterator pos,
  414. InputIterator f, InputIterator l)
  415. {
  416. mList.insert(pos, f, l);
  417. dirtyHash();
  418. }
  419. void insert(iterator pos, size_type n, const T& x)
  420. {
  421. mList.insert(pos, n, x);
  422. dirtyHash();
  423. }
  424. iterator erase(iterator pos)
  425. {
  426. iterator ret = mList.erase(pos);
  427. dirtyHash();
  428. return ret;
  429. }
  430. iterator erase(iterator first, iterator last)
  431. {
  432. iterator ret = mList.erase(first, last);
  433. dirtyHash();
  434. return ret;
  435. }
  436. void clear()
  437. {
  438. mList.clear();
  439. mListHash = 0;
  440. mListHashDirty = false;
  441. }
  442. void resize(size_type n, const T& t = T())
  443. {
  444. bool recalc = false;
  445. if (n != size())
  446. recalc = true;
  447. mList.resize(n, t);
  448. if (recalc)
  449. dirtyHash();
  450. }
  451. bool operator==(const HashedVector<T>& b)
  452. { return mListHash == b.mListHash; }
  453. bool operator<(const HashedVector<T>& b)
  454. { return mListHash < b.mListHash; }
  455. /// Get the hash value
  456. uint32 getHash() const
  457. {
  458. if (isHashDirty())
  459. recalcHash();
  460. return mListHash;
  461. }
  462. public:
  463. };
  464. class Light;
  465. typedef HashedVector<Light*> LightList;
  466. typedef map<String, bool>::type UnaryOptionList;
  467. typedef map<String, String>::type BinaryOptionList;
  468. /// Name / value parameter pair (first = name, second = value)
  469. typedef map<String, String>::type NameValuePairList;
  470. /// Alias / Texture name pair (first = alias, second = texture name)
  471. typedef map<String, String>::type AliasTextureNamePairList;
  472. template< typename T > struct TRect
  473. {
  474. T left, top, right, bottom;
  475. TRect() : left(0), top(0), right(0), bottom(0) {}
  476. TRect( T const & l, T const & t, T const & r, T const & b )
  477. : left( l ), top( t ), right( r ), bottom( b )
  478. {
  479. }
  480. TRect( TRect const & o )
  481. : left( o.left ), top( o.top ), right( o.right ), bottom( o.bottom )
  482. {
  483. }
  484. TRect & operator=( TRect const & o )
  485. {
  486. left = o.left;
  487. top = o.top;
  488. right = o.right;
  489. bottom = o.bottom;
  490. return *this;
  491. }
  492. T width() const
  493. {
  494. return right - left;
  495. }
  496. T height() const
  497. {
  498. return bottom - top;
  499. }
  500. bool isNull() const
  501. {
  502. return width() == 0 || height() == 0;
  503. }
  504. void setNull()
  505. {
  506. left = right = top = bottom = 0;
  507. }
  508. TRect & merge(const TRect& rhs)
  509. {
  510. if (isNull())
  511. {
  512. *this = rhs;
  513. }
  514. else if (!rhs.isNull())
  515. {
  516. left = std::min(left, rhs.left);
  517. right = std::max(right, rhs.right);
  518. top = std::min(top, rhs.top);
  519. bottom = std::max(bottom, rhs.bottom);
  520. }
  521. return *this;
  522. }
  523. TRect intersect(const TRect& rhs) const
  524. {
  525. TRect ret;
  526. if (isNull() || rhs.isNull())
  527. {
  528. // empty
  529. return ret;
  530. }
  531. else
  532. {
  533. ret.left = std::max(left, rhs.left);
  534. ret.right = std::min(right, rhs.right);
  535. ret.top = std::max(top, rhs.top);
  536. ret.bottom = std::min(bottom, rhs.bottom);
  537. }
  538. if (ret.left > ret.right || ret.top > ret.bottom)
  539. {
  540. // no intersection, return empty
  541. ret.left = ret.top = ret.right = ret.bottom = 0;
  542. }
  543. return ret;
  544. }
  545. };
  546. template<typename T>
  547. std::ostream& operator<<(std::ostream& o, const TRect<T>& r)
  548. {
  549. o << "TRect<>(l:" << r.left << ", t:" << r.top << ", r:" << r.right << ", b:" << r.bottom << ")";
  550. return o;
  551. }
  552. /** Structure used to define a rectangle in a 2-D floating point space.
  553. */
  554. typedef TRect<float> FloatRect;
  555. /** Structure used to define a rectangle in a 2-D floating point space,
  556. subject to double / single floating point settings.
  557. */
  558. typedef TRect<Real> RealRect;
  559. /** Structure used to define a rectangle in a 2-D integer space.
  560. */
  561. typedef TRect< long > Rect;
  562. /** Structure used to define a box in a 3-D integer space.
  563. Note that the left, top, and front edges are included but the right,
  564. bottom and back ones are not.
  565. */
  566. struct Box
  567. {
  568. size_t left, top, right, bottom, front, back;
  569. /// Parameterless constructor for setting the members manually
  570. Box()
  571. : left(0), top(0), right(1), bottom(1), front(0), back(1)
  572. {
  573. }
  574. /** Define a box from left, top, right and bottom coordinates
  575. This box will have depth one (front=0 and back=1).
  576. @param l x value of left edge
  577. @param t y value of top edge
  578. @param r x value of right edge
  579. @param b y value of bottom edge
  580. @note Note that the left, top, and front edges are included
  581. but the right, bottom and back ones are not.
  582. */
  583. Box( size_t l, size_t t, size_t r, size_t b ):
  584. left(l),
  585. top(t),
  586. right(r),
  587. bottom(b),
  588. front(0),
  589. back(1)
  590. {
  591. assert(right >= left && bottom >= top && back >= front);
  592. }
  593. /** Define a box from left, top, front, right, bottom and back
  594. coordinates.
  595. @param l x value of left edge
  596. @param t y value of top edge
  597. @param ff z value of front edge
  598. @param r x value of right edge
  599. @param b y value of bottom edge
  600. @param bb z value of back edge
  601. @note Note that the left, top, and front edges are included
  602. but the right, bottom and back ones are not.
  603. */
  604. Box( size_t l, size_t t, size_t ff, size_t r, size_t b, size_t bb ):
  605. left(l),
  606. top(t),
  607. right(r),
  608. bottom(b),
  609. front(ff),
  610. back(bb)
  611. {
  612. assert(right >= left && bottom >= top && back >= front);
  613. }
  614. /// Return true if the other box is a part of this one
  615. bool contains(const Box &def) const
  616. {
  617. return (def.left >= left && def.top >= top && def.front >= front &&
  618. def.right <= right && def.bottom <= bottom && def.back <= back);
  619. }
  620. /// Get the width of this box
  621. size_t getWidth() const { return right-left; }
  622. /// Get the height of this box
  623. size_t getHeight() const { return bottom-top; }
  624. /// Get the depth of this box
  625. size_t getDepth() const { return back-front; }
  626. };
  627. /** Locate command-line options of the unary form '-blah' and of the
  628. binary form '-blah foo', passing back the index of the next non-option.
  629. @param numargs, argv The standard parameters passed to the main method
  630. @param unaryOptList Map of unary options (i.e. those that do not require a parameter).
  631. Should be pre-populated with, for example '-e' in the key and false in the
  632. value. Options which are found will be set to true on return.
  633. @param binOptList Map of binary options (i.e. those that require a parameter
  634. e.g. '-e afile.txt').
  635. Should be pre-populated with, for example '-e' and the default setting.
  636. Options which are found will have the value updated.
  637. */
  638. int _OgreExport findCommandLineOpts(int numargs, char** argv, UnaryOptionList& unaryOptList,
  639. BinaryOptionList& binOptList);
  640. /// Generic result of clipping
  641. enum ClipResult
  642. {
  643. /// Nothing was clipped
  644. CLIPPED_NONE = 0,
  645. /// Partially clipped
  646. CLIPPED_SOME = 1,
  647. /// Everything was clipped away
  648. CLIPPED_ALL = 2
  649. };
  650. /// Render window creation parameters.
  651. struct RenderWindowDescription
  652. {
  653. String name;
  654. unsigned int width;
  655. unsigned int height;
  656. bool useFullScreen;
  657. NameValuePairList miscParams;
  658. };
  659. /// Render window creation parameters container.
  660. typedef vector<RenderWindowDescription>::type RenderWindowDescriptionList;
  661. /// Render window container.
  662. typedef vector<RenderWindow*>::type RenderWindowList;
  663. /// Utility class to generate a sequentially numbered series of names
  664. class _OgreExport NameGenerator
  665. {
  666. protected:
  667. String mPrefix;
  668. unsigned long long int mNext;
  669. OGRE_AUTO_MUTEX
  670. public:
  671. NameGenerator(const NameGenerator& rhs)
  672. : mPrefix(rhs.mPrefix), mNext(rhs.mNext) {}
  673. NameGenerator(const String& prefix) : mPrefix(prefix), mNext(1) {}
  674. /// Generate a new name
  675. String generate()
  676. {
  677. OGRE_LOCK_AUTO_MUTEX
  678. std::ostringstream s;
  679. s << mPrefix << mNext++;
  680. return s.str();
  681. }
  682. /// Reset the internal counter
  683. void reset()
  684. {
  685. OGRE_LOCK_AUTO_MUTEX
  686. mNext = 1ULL;
  687. }
  688. /// Manually set the internal counter (use caution)
  689. void setNext(unsigned long long int val)
  690. {
  691. OGRE_LOCK_AUTO_MUTEX
  692. mNext = val;
  693. }
  694. /// Get the internal counter
  695. unsigned long long int getNext() const
  696. {
  697. // lock even on get because 64-bit may not be atomic read
  698. OGRE_LOCK_AUTO_MUTEX
  699. return mNext;
  700. }
  701. };
  702. /** Template class describing a simple pool of items.
  703. */
  704. template <typename T>
  705. class Pool
  706. {
  707. protected:
  708. typedef typename list<T>::type ItemList;
  709. ItemList mItems;
  710. OGRE_AUTO_MUTEX
  711. public:
  712. Pool() {}
  713. virtual ~Pool() {}
  714. /** Get the next item from the pool.
  715. @returns pair indicating whether there was a free item, and the item if so
  716. */
  717. virtual std::pair<bool, T> removeItem()
  718. {
  719. OGRE_LOCK_AUTO_MUTEX
  720. std::pair<bool, T> ret;
  721. if (mItems.empty())
  722. {
  723. ret.first = false;
  724. }
  725. else
  726. {
  727. ret.first = true;
  728. ret.second = mItems.front();
  729. mItems.pop_front();
  730. }
  731. return ret;
  732. }
  733. /** Add a new item to the pool.
  734. */
  735. virtual void addItem(const T& i)
  736. {
  737. OGRE_LOCK_AUTO_MUTEX
  738. mItems.push_front(i);
  739. }
  740. /// Clear the pool
  741. virtual void clear()
  742. {
  743. OGRE_LOCK_AUTO_MUTEX
  744. mItems.clear();
  745. }
  746. };
  747. /** @} */
  748. /** @} */
  749. }
  750. #endif