#ifndef OPENMW_MWRENDER_OBJECTPAGING_H #define OPENMW_MWRENDER_OBJECTPAGING_H #include #include #include #include namespace Resource { class SceneManager; } namespace MWRender { typedef std::tuple ChunkId; // Center, Size, ActiveGrid class ObjectPaging : public Resource::GenericResourceManager, public Terrain::QuadTreeWorld::ChunkManager { public: ObjectPaging(Resource::SceneManager* sceneManager, ESM::RefId worldspace); ~ObjectPaging() = default; osg::ref_ptr getChunk(float size, const osg::Vec2f& center, unsigned char lod, unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile) override; osg::ref_ptr createChunk(float size, const osg::Vec2f& center, bool activeGrid, const osg::Vec3f& viewPoint, bool compile, unsigned char lod); unsigned int getNodeMask() override; /// @return true if view needs rebuild bool enableObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled); /// @return true if view needs rebuild bool blacklistObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell); void clear(); /// Must be called after clear() before rendering starts. /// @return true if view needs rebuild bool unlockCache(); void reportStats(unsigned int frameNumber, osg::Stats* stats) const override; void getPagedRefnums(const osg::Vec4i& activeGrid, std::vector& out); private: Resource::SceneManager* mSceneManager; bool mActiveGrid; bool mDebugBatches; float mMergeFactor; float mMinSize; float mMinSizeMergeFactor; float mMinSizeCostMultiplier; std::mutex mRefTrackerMutex; struct RefTracker { std::set mDisabled; std::set mBlacklist; bool operator==(const RefTracker& other) const { return mDisabled == other.mDisabled && mBlacklist == other.mBlacklist; } }; RefTracker mRefTracker; RefTracker mRefTrackerNew; bool mRefTrackerLocked; const RefTracker& getRefTracker() const { return mRefTracker; } RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; } std::mutex mSizeCacheMutex; typedef std::map SizeCache; SizeCache mSizeCache; std::mutex mLODNameCacheMutex; typedef std::pair LODNameCacheKey; // Key: mesh name, lod level typedef std::map LODNameCache; // Cache: key, mesh name to use LODNameCache mLODNameCache; }; class RefnumMarker : public osg::Object { public: RefnumMarker() : mNumVertices(0) { } RefnumMarker(const RefnumMarker& copy, osg::CopyOp co) : mRefnum(copy.mRefnum) , mNumVertices(copy.mNumVertices) { } META_Object(MWRender, RefnumMarker) ESM::RefNum mRefnum; unsigned int mNumVertices; }; } #endif