00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __Ogre_TerrainLodManager_H__ 00030 #define __Ogre_TerrainLodManager_H__ 00031 00032 #include "OgreTerrainPrerequisites.h" 00033 #include "OgreWorkQueue.h" 00034 00035 00036 namespace Ogre 00037 { 00038 class Terrain; 00052 class _OgreTerrainExport TerrainLodManager : public WorkQueue::RequestHandler, public WorkQueue::ResponseHandler, public TerrainAlloc 00053 { 00054 public: 00055 static const uint32 TERRAINLODDATA_CHUNK_ID; 00056 static const uint16 TERRAINLODDATA_CHUNK_VERSION; 00057 typedef vector<float>::type LodData; 00058 typedef vector<LodData>::type LodsData; 00059 00060 struct LoadLodRequest 00061 { 00062 LoadLodRequest( TerrainLodManager* r, uint16 preparedLod, uint16 loadedLod, uint16 target ) 00063 : requestee(r) 00064 , currentPreparedLod(preparedLod) 00065 , currentLoadedLod(loadedLod) 00066 , requestedLod(target) 00067 { 00068 } 00069 TerrainLodManager* requestee; 00070 uint16 currentPreparedLod; 00071 uint16 currentLoadedLod; 00072 uint16 requestedLod; 00073 _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadLodRequest& r) 00074 { return o; } 00075 }; 00076 00077 struct LodInfo 00078 { 00079 uint treeStart; 00080 uint treeEnd; 00081 bool isLast; 00082 uint16 resolution; 00083 uint size; 00084 }; 00085 public: 00086 TerrainLodManager(Terrain* t, DataStreamPtr& stream); 00087 TerrainLodManager(Terrain* t, const String& filename = ""); 00088 virtual ~TerrainLodManager(); 00089 00090 static const uint16 WORKQUEUE_LOAD_LOD_DATA_REQUEST; 00091 virtual bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); 00092 virtual bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); 00093 virtual WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ); 00094 virtual void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ); 00095 00096 void updateToLodLevel(int lodLevel, bool synchronous = false); 00098 static void saveLodData(StreamSerialiser& stream, Terrain* terrain); 00099 00106 void fillBufferAtLod(uint lodLevel, const float* data, uint dataSize ); 00113 void readLodData(uint16 lowerLodBound, uint16 higherLodBound); 00114 void waitForDerivedProcesses(); 00115 00116 int getHighestLodPrepared(){ return mHighestLodPrepared; } 00117 int getHighestLodLoaded(){ return mHighestLodLoaded; } 00118 int getTargetLodLevel(){ return mTargetLodLevel; } 00119 00120 LodInfo& getLodInfo(uint lodLevel) 00121 { 00122 if(!mLodInfoTable) 00123 buildLodInfoTable(); 00124 return mLodInfoTable[lodLevel]; 00125 } 00126 private: 00127 void init(); 00128 void buildLodInfoTable(); 00129 00147 static void separateData(float* data, uint16 size, uint16 numLodLevels, LodsData& lods ); 00148 private: 00149 Terrain* mTerrain; 00150 DataStreamPtr mDataStream; 00151 size_t mStreamOffset; 00152 uint16 mWorkQueueChannel; 00153 00154 LodInfo* mLodInfoTable; 00155 int mTargetLodLevel; 00156 int mHighestLodPrepared; 00157 int mHighestLodLoaded; 00158 00159 bool mIncreaseLodLevelInProgress; 00160 bool mLastRequestSynchronous; 00161 }; 00164 } 00165 00166 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48