/src/ogre/Components/Terrain/include/OgreTerrainLodManager.h
Line | Count | Source |
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 | | |
29 | | #ifndef __Ogre_TerrainLodManager_H__ |
30 | | #define __Ogre_TerrainLodManager_H__ |
31 | | |
32 | | #include "OgreTerrainPrerequisites.h" |
33 | | #include "OgreWorkQueue.h" |
34 | | |
35 | | |
36 | | namespace Ogre |
37 | | { |
38 | | class Terrain; |
39 | | /** \addtogroup Optional |
40 | | * @{ |
41 | | */ |
42 | | /** \addtogroup Terrain |
43 | | * Some details on the terrain LOD manager |
44 | | * @{ |
45 | | */ |
46 | | |
47 | | /** Terrain LOD data manager |
48 | | @par |
49 | | This class is used for managing terrain LOD data's loading, unloading. |
50 | | */ |
51 | | |
52 | | class _OgreTerrainExport TerrainLodManager |
53 | | { |
54 | | public: |
55 | | static const uint32 TERRAINLODDATA_CHUNK_ID; |
56 | | static const uint16 TERRAINLODDATA_CHUNK_VERSION; |
57 | | typedef std::vector<float> LodData; |
58 | | typedef std::vector<LodData> LodsData; |
59 | | |
60 | | struct LoadLodRequest |
61 | | { |
62 | | LoadLodRequest( TerrainLodManager* r, uint16 preparedLod, uint16 loadedLod, uint16 target ) |
63 | 0 | : requestee(r) |
64 | 0 | , currentPreparedLod(preparedLod) |
65 | 0 | , currentLoadedLod(loadedLod) |
66 | 0 | , requestedLod(target) |
67 | 0 | { |
68 | 0 | } |
69 | | TerrainLodManager* requestee; |
70 | | uint16 currentPreparedLod; |
71 | | uint16 currentLoadedLod; |
72 | | uint16 requestedLod; |
73 | | }; |
74 | | |
75 | | struct LodInfo |
76 | | { |
77 | | uint treeStart; |
78 | | uint treeEnd; |
79 | | bool isLast; |
80 | | uint16 resolution; |
81 | | uint size; |
82 | | }; |
83 | | public: |
84 | | TerrainLodManager(Terrain* t, DataStreamPtr& stream); |
85 | | TerrainLodManager(Terrain* t, const String& filename = ""); |
86 | | virtual ~TerrainLodManager(); |
87 | | |
88 | | void open(const String& filename); |
89 | | void close(); |
90 | | bool isOpen() const; |
91 | | |
92 | | void updateToLodLevel(int lodLevel, bool synchronous = false); |
93 | | /// Save each LOD level separately compressed so seek is possible |
94 | | static void saveLodData(StreamSerialiser& stream, Terrain* terrain); |
95 | | |
96 | | /** Copy geometry data from buffer to mHeightData/mDeltaData |
97 | | @param lodLevel A LOD level to work with |
98 | | @param data, dataSize Buffer which holds geometry data if separated form |
99 | | @remarks Data in buffer has to be both height and delta data. First half is height data. |
100 | | Seconds half is delta data. |
101 | | */ |
102 | | void fillBufferAtLod(uint lodLevel, const float* data, uint dataSize ); |
103 | | /** Read separated geometry data from file into allocated memory |
104 | | @param lowerLodBound Lower bound of LOD levels to load |
105 | | @param higherLodBound Upper bound of LOD levels to load |
106 | | @remarks Geometry data are uncompressed using inflate() and stored into |
107 | | allocated buffer |
108 | | */ |
109 | | void readLodData(uint16 lowerLodBound, uint16 higherLodBound); |
110 | | void waitForDerivedProcesses(); |
111 | | |
112 | 0 | int getHighestLodPrepared(){ return mHighestLodPrepared; } |
113 | 0 | int getHighestLodLoaded(){ return mHighestLodLoaded; } |
114 | 0 | int getTargetLodLevel(){ return mTargetLodLevel; } |
115 | | |
116 | | LodInfo& getLodInfo(uint lodLevel) |
117 | 0 | { |
118 | 0 | if(!mLodInfoTable) |
119 | 0 | buildLodInfoTable(); |
120 | 0 | return mLodInfoTable[lodLevel]; |
121 | 0 | } |
122 | | private: |
123 | | WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); |
124 | | void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); |
125 | | |
126 | | void init(); |
127 | | void buildLodInfoTable(); |
128 | | |
129 | | /** Separate geometry data by LOD level |
130 | | @param data A geometry data to separate i.e. mHeightData/mDeltaData |
131 | | @param size Dimension of the input data |
132 | | @param numLodLevels Number of LOD levels in the input data |
133 | | @param lods The separated LOD data |
134 | | @remarks Allocates new array and fills it with geometry data coupled by LOD level from lowest LOD level to highest. Example: |
135 | | before separation: |
136 | | 00 01 02 03 04 |
137 | | 05 06 07 08 09 |
138 | | 10 11 12 13 14 |
139 | | 15 16 17 18 19 |
140 | | 20 21 22 23 24 |
141 | | after separation: |
142 | | 2: 00 04 20 24 |
143 | | 1: 02 10 12 14 22 |
144 | | 0: 01 03 05 06 07 08 09 11 13 15 16 17 18 19 21 23 |
145 | | */ |
146 | | static void separateData(float* data, uint16 size, uint16 numLodLevels, LodsData& lods ); |
147 | | private: |
148 | | Terrain* mTerrain; |
149 | | DataStreamPtr mDataStream; |
150 | | size_t mStreamOffset; |
151 | | |
152 | | LodInfo* mLodInfoTable; |
153 | | int mTargetLodLevel; /// Which LOD level is demanded |
154 | | int mHighestLodPrepared; /// Highest LOD level stored in memory i.e. mHeightData/mDeltaData |
155 | | int mHighestLodLoaded; /// Highest LOD level loaded in GPU |
156 | | |
157 | | bool mIncreaseLodLevelInProgress; /// Is increaseLodLevel() running? |
158 | | bool mLastRequestSynchronous; |
159 | | }; |
160 | | /** @} */ |
161 | | /** @} */ |
162 | | } |
163 | | |
164 | | #endif |