#ifndef GAME_RENDER_GLOBALMAP_H #define GAME_RENDER_GLOBALMAP_H #include #include #include namespace osg { class Texture2D; class Image; class Group; class Camera; } namespace ESM { struct GlobalMap; } namespace SceneUtil { class WorkQueue; } namespace MWRender { class CreateMapWorkItem; class GlobalMap { public: GlobalMap(osg::Group* root, SceneUtil::WorkQueue* workQueue); ~GlobalMap(); void render(); int getWidth() const { return mWidth; } int getHeight() const { return mHeight; } int getCellSize() const { return mCellSize; } void worldPosToImageSpace(float x, float z, float& imageX, float& imageY); void cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY); void exploreCell (int cellX, int cellY, osg::ref_ptr localMapTexture); /// Clears the overlay void clear(); /** * Removes cameras that have already been rendered. Should be called every frame to ensure that * we do not render the same map more than once. Note, this cleanup is difficult to implement in an * automated fashion, since we can't alter the scene graph structure from within an update callback. */ void cleanupCameras(); void removeCamera(osg::Camera* cam); /* Start of tes3mp addition Allow the setting of the image data for a global map tile from elsewhere in the code */ void setImage(int cellX, int cellY, const std::vector& imageData); /* End of tes3mp addition */ /** * Mark a camera for cleanup in the next update. For internal use only. */ void markForRemoval(osg::Camera* camera); void write (ESM::GlobalMap& map); void read (ESM::GlobalMap& map); osg::ref_ptr getBaseTexture(); osg::ref_ptr getOverlayTexture(); void ensureLoaded(); private: /** * Request rendering a 2d quad onto mOverlayTexture. * x, y, width and height are the destination coordinates (top-left coordinate origin) * @param cpuCopy copy the resulting render onto mOverlayImage as well? */ void requestOverlayTextureUpdate(int x, int y, int width, int height, osg::ref_ptr texture, bool clear, bool cpuCopy, float srcLeft = 0.f, float srcTop = 0.f, float srcRight = 1.f, float srcBottom = 1.f); int mCellSize; osg::ref_ptr mRoot; typedef std::vector > CameraVector; CameraVector mActiveCameras; CameraVector mCamerasPendingRemoval; struct ImageDest { ImageDest() : mX(0), mY(0) , mFramesUntilDone(3) // wait an extra frame to ensure the draw thread has completed its frame. { } osg::ref_ptr mImage; int mX, mY; int mFramesUntilDone; }; typedef std::vector ImageDestVector; ImageDestVector mPendingImageDest; std::vector< std::pair > mExploredCells; osg::ref_ptr mBaseTexture; osg::ref_ptr mAlphaTexture; // GPU copy of overlay // Note, uploads are pushed through a Camera, instead of through mOverlayImage osg::ref_ptr mOverlayTexture; // CPU copy of overlay osg::ref_ptr mOverlayImage; osg::ref_ptr mWorkQueue; osg::ref_ptr mWorkItem; int mWidth; int mHeight; int mMinX, mMaxX, mMinY, mMaxY; }; } #endif