OgreTerrainLodManager.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_TerrainLodManager_H__
#define __Ogre_TerrainLodManager_H__
#include "OgreTerrainPrerequisites.h"
#include "OgreWorkQueue.h"
namespace Ogre
{
class Terrain;
class _OgreTerrainExport TerrainLodManager : public WorkQueue::RequestHandler, public WorkQueue::ResponseHandler, public TerrainAlloc
{
public:
static const uint32 TERRAINLODDATA_CHUNK_ID;
static const uint16 TERRAINLODDATA_CHUNK_VERSION;
typedef vector<float>::type LodData;
typedef vector<LodData>::type LodsData;
struct LoadLodRequest
{
LoadLodRequest( TerrainLodManager* r, uint16 preparedLod, uint16 loadedLod, uint16 target )
: requestee(r)
, currentPreparedLod(preparedLod)
, currentLoadedLod(loadedLod)
, requestedLod(target)
{
}
TerrainLodManager* requestee;
uint16 currentPreparedLod;
uint16 currentLoadedLod;
uint16 requestedLod;
_OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadLodRequest& r)
{ return o; }
};
struct LodInfo
{
uint treeStart;
uint treeEnd;
bool isLast;
uint16 resolution;
uint size;
};
public:
TerrainLodManager(Terrain* t, DataStreamPtr& stream);
TerrainLodManager(Terrain* t, const String& filename = "");
virtual ~TerrainLodManager();
static const uint16 WORKQUEUE_LOAD_LOD_DATA_REQUEST;
virtual bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
virtual bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
virtual WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
virtual void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
void updateToLodLevel(int lodLevel, bool synchronous = false);
static void saveLodData(StreamSerialiser& stream, Terrain* terrain);
void fillBufferAtLod(uint lodLevel, const float* data, uint dataSize );
void readLodData(uint16 lowerLodBound, uint16 higherLodBound);
void waitForDerivedProcesses();
int getHighestLodPrepared(){ return mHighestLodPrepared; }
int getHighestLodLoaded(){ return mHighestLodLoaded; }
int getTargetLodLevel(){ return mTargetLodLevel; }
LodInfo& getLodInfo(uint lodLevel)
{
if(!mLodInfoTable)
buildLodInfoTable();
return mLodInfoTable[lodLevel];
}
private:
void init();
void buildLodInfoTable();
static void separateData(float* data, uint16 size, uint16 numLodLevels, LodsData& lods );
private:
Terrain* mTerrain;
DataStreamPtr mDataStream;
size_t mStreamOffset;
uint16 mWorkQueueChannel;
LodInfo* mLodInfoTable;
int mTargetLodLevel;
int mHighestLodPrepared;
int mHighestLodLoaded;
bool mIncreaseLodLevelInProgress;
bool mLastRequestSynchronous;
};
}
#endif
Ogre::TerrainLodManager::TERRAINLODDATA_CHUNK_ID
static const uint32 TERRAINLODDATA_CHUNK_ID
Definition: OgreTerrainLodManager.h:55
OgreWorkQueue.h
Ogre::TerrainLodManager::mDataStream
DataStreamPtr mDataStream
Definition: OgreTerrainLodManager.h:150
Ogre::TerrainLodManager::WORKQUEUE_LOAD_LOD_DATA_REQUEST
static const uint16 WORKQUEUE_LOAD_LOD_DATA_REQUEST
Definition: OgreTerrainLodManager.h:90
Ogre::TerrainLodManager::LoadLodRequest::requestee
TerrainLodManager * requestee
Definition: OgreTerrainLodManager.h:69
Ogre::TerrainLodManager::getTargetLodLevel
int getTargetLodLevel()
Definition: OgreTerrainLodManager.h:118
Ogre::TerrainLodManager::LoadLodRequest::operator<<
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const LoadLodRequest &r)
Definition: OgreTerrainLodManager.h:73
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::TerrainLodManager::LodInfo
Definition: OgreTerrainLodManager.h:77
Ogre::TerrainLodManager::getLodInfo
LodInfo & getLodInfo(uint lodLevel)
Definition: OgreTerrainLodManager.h:120
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::WorkQueue
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:70
Ogre::TerrainLodManager::LoadLodRequest::currentLoadedLod
uint16 currentLoadedLod
Definition: OgreTerrainLodManager.h:71
Ogre::TerrainLodManager::mLastRequestSynchronous
bool mLastRequestSynchronous
Is increaseLodLevel() running?
Definition: OgreTerrainLodManager.h:160
Ogre::TerrainLodManager::LodInfo::isLast
bool isLast
Definition: OgreTerrainLodManager.h:81
Ogre::TerrainLodManager::LodsData
vector< LodData >::type LodsData
Definition: OgreTerrainLodManager.h:58
Ogre::TerrainLodManager::mLodInfoTable
LodInfo * mLodInfoTable
Definition: OgreTerrainLodManager.h:154
Ogre::Terrain
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Ogre::TerrainLodManager::LoadLodRequest::requestedLod
uint16 requestedLod
Definition: OgreTerrainLodManager.h:72
Ogre::TerrainLodManager::mHighestLodPrepared
int mHighestLodPrepared
Which LOD level is demanded.
Definition: OgreTerrainLodManager.h:156
Ogre::WorkQueue::Request
General purpose request structure.
Definition: OgreWorkQueue.h:83
Ogre::TerrainLodManager::LodInfo::treeEnd
uint treeEnd
Definition: OgreTerrainLodManager.h:80
Ogre::TerrainLodManager::mWorkQueueChannel
uint16 mWorkQueueChannel
Definition: OgreTerrainLodManager.h:152
Ogre::TerrainLodManager::LodInfo::size
uint size
Definition: OgreTerrainLodManager.h:83
Ogre::WorkQueue::Response
General purpose response structure.
Definition: OgreWorkQueue.h:122
Ogre::TerrainLodManager::mHighestLodLoaded
int mHighestLodLoaded
Highest LOD level stored in memory i.e. mHeightData/mDeltaData.
Definition: OgreTerrainLodManager.h:157
_OgreTerrainExport
#define _OgreTerrainExport
Definition: OgreTerrainPrerequisites.h:58
Ogre::TerrainLodManager
Terrain LOD data manager.
Definition: OgreTerrainLodManager.h:52
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::TerrainLodManager::LodInfo::resolution
uint16 resolution
Definition: OgreTerrainLodManager.h:82
Ogre::TerrainLodManager::LodData
vector< float >::type LodData
Definition: OgreTerrainLodManager.h:57
Ogre::StreamSerialiser
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Definition: OgreStreamSerialiser.h:66
Ogre::TerrainLodManager::mTargetLodLevel
int mTargetLodLevel
Definition: OgreTerrainLodManager.h:155
Ogre::TerrainLodManager::TERRAINLODDATA_CHUNK_VERSION
static const uint16 TERRAINLODDATA_CHUNK_VERSION
Definition: OgreTerrainLodManager.h:56
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::WorkQueue::ResponseHandler
Interface definition for a handler of responses.
Definition: OgreWorkQueue.h:196
Ogre::TerrainLodManager::getHighestLodLoaded
int getHighestLodLoaded()
Definition: OgreTerrainLodManager.h:117
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::TerrainLodManager::mTerrain
Terrain * mTerrain
Definition: OgreTerrainLodManager.h:149
Ogre::SharedPtr< DataStream >
Ogre::TerrainLodManager::mIncreaseLodLevelInProgress
bool mIncreaseLodLevelInProgress
Highest LOD level loaded in GPU.
Definition: OgreTerrainLodManager.h:159
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::TerrainLodManager::LoadLodRequest
Definition: OgreTerrainLodManager.h:60
Ogre::TerrainLodManager::getHighestLodPrepared
int getHighestLodPrepared()
Definition: OgreTerrainLodManager.h:116
Ogre::TerrainLodManager::LoadLodRequest::currentPreparedLod
uint16 currentPreparedLod
Definition: OgreTerrainLodManager.h:70
OgreTerrainPrerequisites.h
Ogre::TerrainLodManager::mStreamOffset
size_t mStreamOffset
Definition: OgreTerrainLodManager.h:151
Ogre::TerrainLodManager::LoadLodRequest::LoadLodRequest
LoadLodRequest(TerrainLodManager *r, uint16 preparedLod, uint16 loadedLod, uint16 target)
Definition: OgreTerrainLodManager.h:62
Ogre::WorkQueue::RequestHandler
Interface definition for a handler of requests.
Definition: OgreWorkQueue.h:161
Ogre::TerrainLodManager::LodInfo::treeStart
uint treeStart
Definition: OgreTerrainLodManager.h:79
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.