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