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