OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
globalmap.hpp
Go to the documentation of this file.
1 #ifndef GAME_RENDER_GLOBALMAP_H
2 #define GAME_RENDER_GLOBALMAP_H
3 
4 #include <string>
5 #include <vector>
6 
7 #include <osg/ref_ptr>
8 
9 namespace osg
10 {
11  class Texture2D;
12  class Image;
13  class Group;
14  class Camera;
15 }
16 
17 namespace Loading
18 {
19  class Listener;
20 }
21 
22 namespace ESM
23 {
24  struct GlobalMap;
25 }
26 
27 namespace MWRender
28 {
29 
30  class GlobalMap
31  {
32  public:
33  GlobalMap(osg::Group* root);
34  ~GlobalMap();
35 
36  void render(Loading::Listener* loadingListener);
37 
38  int getWidth() const { return mWidth; }
39  int getHeight() const { return mHeight; }
40 
41  int getCellSize() const { return mCellSize; }
42 
43  void worldPosToImageSpace(float x, float z, float& imageX, float& imageY);
44 
45  void cellTopLeftCornerToImageSpace(int x, int y, float& imageX, float& imageY);
46 
47  void exploreCell (int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture);
48 
50  void clear();
51 
57  void cleanupCameras();
58 
59  void removeCamera(osg::Camera* cam);
60 
64  void markForRemoval(osg::Camera* camera);
65 
66  void write (ESM::GlobalMap& map);
67  void read (ESM::GlobalMap& map);
68 
69  osg::ref_ptr<osg::Texture2D> getBaseTexture();
70  osg::ref_ptr<osg::Texture2D> getOverlayTexture();
71 
72  private:
78  void requestOverlayTextureUpdate(int x, int y, int width, int height, osg::ref_ptr<osg::Texture2D> texture, bool clear, bool cpuCopy,
79  float srcLeft = 0.f, float srcTop = 0.f, float srcRight = 1.f, float srcBottom = 1.f);
80 
81  int mCellSize;
82 
83  osg::ref_ptr<osg::Group> mRoot;
84 
85  typedef std::vector<osg::ref_ptr<osg::Camera> > CameraVector;
87 
89 
90  struct ImageDest
91  {
93  : mX(0), mY(0)
94  , mFramesUntilDone(3) // wait an extra frame to ensure the draw thread has completed its frame.
95  {
96  }
97 
98  osg::ref_ptr<osg::Image> mImage;
99  int mX, mY;
101  };
102 
103  typedef std::vector<ImageDest> ImageDestVector;
104 
106 
107  std::vector< std::pair<int,int> > mExploredCells;
108 
109  osg::ref_ptr<osg::Texture2D> mBaseTexture;
110  osg::ref_ptr<osg::Texture2D> mAlphaTexture;
111 
112  // GPU copy of overlay
113  // Note, uploads are pushed through a Camera, instead of through mOverlayImage
114  osg::ref_ptr<osg::Texture2D> mOverlayTexture;
115 
116  // CPU copy of overlay
117  osg::ref_ptr<osg::Image> mOverlayImage;
118 
119  int mWidth;
120  int mHeight;
121 
123  };
124 
125 }
126 
127 #endif
128 
int mWidth
Definition: globalmap.hpp:119
int getCellSize() const
Definition: globalmap.hpp:41
void exploreCell(int cellX, int cellY, osg::ref_ptr< osg::Texture2D > localMapTexture)
Definition: globalmap.cpp:347
GlobalMap(osg::Group *root)
Definition: globalmap.cpp:98
int mX
Definition: globalmap.hpp:99
osg::ref_ptr< osg::Image > mImage
Definition: globalmap.hpp:98
int mY
Definition: globalmap.hpp:99
osg::ref_ptr< osg::Texture2D > getOverlayTexture()
Definition: globalmap.cpp:531
int mMaxY
Definition: globalmap.hpp:122
void requestOverlayTextureUpdate(int x, int y, int width, int height, osg::ref_ptr< osg::Texture2D > texture, bool clear, bool cpuCopy, float srcLeft=0.f, float srcTop=0.f, float srcRight=1.f, float srcBottom=1.f)
Definition: globalmap.cpp:262
int mMinY
Definition: globalmap.hpp:122
~GlobalMap()
Definition: globalmap.cpp:109
CameraVector mCamerasPendingRemoval
Definition: globalmap.hpp:88
Definition: loadinglistener.hpp:8
void cleanupCameras()
Definition: globalmap.cpp:548
void markForRemoval(osg::Camera *camera)
Definition: globalmap.cpp:536
std::vector< std::pair< int, int > > mExploredCells
Definition: globalmap.hpp:107
void write(ESM::GlobalMap &map)
Definition: globalmap.cpp:390
osg::ref_ptr< osg::Texture2D > getBaseTexture()
Definition: globalmap.cpp:526
int mMaxX
Definition: globalmap.hpp:122
void clear()
Clears the overlay.
Definition: globalmap.cpp:361
CameraVector mActiveCameras
Definition: globalmap.hpp:86
int mCellSize
Definition: globalmap.hpp:81
std::vector< ImageDest > ImageDestVector
Definition: globalmap.hpp:103
std::vector< osg::ref_ptr< osg::Camera > > CameraVector
Definition: globalmap.hpp:85
int mHeight
Definition: globalmap.hpp:120
osg::ref_ptr< osg::Texture2D > mOverlayTexture
Definition: globalmap.hpp:114
osg::ref_ptr< osg::Image > mOverlayImage
Definition: globalmap.hpp:117
<
Definition: globalmap.hpp:15
void removeCamera(osg::Camera *cam)
Definition: globalmap.cpp:570
osg::ref_ptr< osg::Texture2D > mAlphaTexture
Definition: globalmap.hpp:110
osg::ref_ptr< osg::Group > mRoot
Definition: globalmap.hpp:83
int getHeight() const
Definition: globalmap.hpp:39
void worldPosToImageSpace(float x, float z, float &imageX, float &imageY)
Definition: globalmap.cpp:247
ImageDestVector mPendingImageDest
Definition: globalmap.hpp:105
void cellTopLeftCornerToImageSpace(int x, int y, float &imageX, float &imageY)
Definition: globalmap.cpp:254
int mMinX
Definition: globalmap.hpp:122
void read(ESM::GlobalMap &map)
Definition: globalmap.cpp:430
void render(Loading::Listener *loadingListener)
Definition: globalmap.cpp:117
ImageDest()
Definition: globalmap.hpp:92
osg::ref_ptr< osg::Texture2D > mBaseTexture
Definition: globalmap.hpp:109
int mFramesUntilDone
Definition: globalmap.hpp:100
int getWidth() const
Definition: globalmap.hpp:38
Definition: globalmap.hpp:90
Definition: globalmap.hpp:30