/src/ogre/OgreMain/include/OgreLodStrategy.h
Line | Count | Source (jump to first uncovered line) |
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-2014 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 __Lod_Strategy_H__ |
29 | | #define __Lod_Strategy_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | |
33 | | #include "OgreMesh.h" |
34 | | #include "OgreMaterial.h" |
35 | | |
36 | | #include "OgreHeaderPrefix.h" |
37 | | |
38 | | namespace Ogre { |
39 | | |
40 | | /** \addtogroup Core |
41 | | * @{ |
42 | | */ |
43 | | /** \defgroup LOD Level of Detail |
44 | | * @{ |
45 | | */ |
46 | | /** Strategy for determining level of detail. |
47 | | |
48 | | Generally, to create a new LOD strategy, all of the following will |
49 | | need to be implemented: getValueImpl, getBaseValue, transformBias, |
50 | | getIndex, sort, and isSorted. |
51 | | In addition, transformUserValue may be overridden. |
52 | | */ |
53 | | class _OgreExport LodStrategy : public LodAlloc |
54 | | { |
55 | | private: |
56 | | /** Name of this strategy. */ |
57 | | String mName; |
58 | | |
59 | | /** Compute the LOD value for a given movable object relative to a given camera. */ |
60 | | virtual Real getValueImpl(const MovableObject *movableObject, const Camera *camera) const = 0; |
61 | | |
62 | | public: |
63 | | /** Constructor accepting name. */ |
64 | | LodStrategy(const String& name); |
65 | | |
66 | | /** Virtual destructor. */ |
67 | | virtual ~LodStrategy(); |
68 | | |
69 | | /** Get the value of the first (highest) level of detail. */ |
70 | | virtual Real getBaseValue() const = 0; |
71 | | |
72 | | /** Transform LOD bias so it only needs to be multiplied by the LOD value. */ |
73 | | virtual Real transformBias(Real factor) const = 0; |
74 | | |
75 | | /** Transform user supplied value to internal value. |
76 | | |
77 | | By default, performs no transformation. |
78 | | |
79 | | Do not throw exceptions for invalid values here, as the LOD strategy |
80 | | may be changed such that the values become valid. |
81 | | */ |
82 | | virtual Real transformUserValue(Real userValue) const; |
83 | | |
84 | | /** Compute the LOD value for a given movable object relative to a given camera. */ |
85 | | Real getValue(const MovableObject *movableObject, const Camera *camera) const; |
86 | | |
87 | | /** Get the index of the LOD usage which applies to a given value. */ |
88 | | virtual ushort getIndex(Real value, const Mesh::MeshLodUsageList& meshLodUsageList) const = 0; |
89 | | |
90 | | /** Get the index of the LOD usage which applies to a given value. */ |
91 | | virtual ushort getIndex(Real value, const Material::LodValueList& materialLodValueList) const = 0; |
92 | | |
93 | | /** Sort mesh LOD usage list from greatest to least detail */ |
94 | | virtual void sort(Mesh::MeshLodUsageList& meshLodUsageList) const = 0; |
95 | | |
96 | | /** Determine if the LOD values are sorted from greatest detail to least detail. */ |
97 | | virtual bool isSorted(const Mesh::LodValueList& values) const = 0; |
98 | | |
99 | | /** Assert that the LOD values are sorted from greatest detail to least detail. */ |
100 | | void assertSorted(const Mesh::LodValueList& values) const; |
101 | | |
102 | | /** Get the name of this strategy. */ |
103 | 0 | const String& getName() const { return mName; } |
104 | | |
105 | | protected: |
106 | | /** Implementation of isSorted suitable for ascending values. */ |
107 | | static bool isSortedAscending(const Mesh::LodValueList& values); |
108 | | /** Implementation of isSorted suitable for descending values. */ |
109 | | static bool isSortedDescending(const Mesh::LodValueList& values); |
110 | | |
111 | | /** Implementation of sort suitable for ascending values. */ |
112 | | static void sortAscending(Mesh::MeshLodUsageList& meshLodUsageList); |
113 | | /** Implementation of sort suitable for descending values. */ |
114 | | static void sortDescending(Mesh::MeshLodUsageList& meshLodUsageList); |
115 | | |
116 | | /** Implementation of getIndex suitable for ascending values. */ |
117 | | static ushort getIndexAscending(Real value, const Mesh::MeshLodUsageList& meshLodUsageList); |
118 | | /** Implementation of getIndex suitable for descending values. */ |
119 | | static ushort getIndexDescending(Real value, const Mesh::MeshLodUsageList& meshLodUsageList); |
120 | | |
121 | | /** Implementation of getIndex suitable for ascending values. */ |
122 | | static ushort getIndexAscending(Real value, const Material::LodValueList& materialLodValueList); |
123 | | /** Implementation of getIndex suitable for descending values. */ |
124 | | static ushort getIndexDescending(Real value, const Material::LodValueList& materialLodValueList); |
125 | | |
126 | | }; |
127 | | /** @} */ |
128 | | /** @} */ |
129 | | |
130 | | } // namespace |
131 | | |
132 | | #include "OgreHeaderSuffix.h" |
133 | | |
134 | | #endif |