VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trpage_write.h
Go to the documentation of this file.
1 /* ************************
2  Copyright Terrain Experts Inc.
3  Terrain Experts Inc (TERREX) reserves all rights to this source code
4  unless otherwise specified in writing by the President of TERREX.
5  This copyright may be updated in the future, in which case that version
6  supercedes this one.
7  -------------------
8  Terrex Experts Inc.
9  4400 East Broadway #314
10  Tucson, AZ 85711
11  info@terrex.com
12  Tel: (520) 323-7990
13  ************************
14  */
15 
16 #ifndef _txpage_write_h_
17 
18 #define _txpage_write_h_
19 
20 /* trpage_write.h
21  Classes that are used to write paging archives.
22  */
23 
25 #include <osgdb_vrftxp/trpage_io.h>
28 
29 /* Geometry Stats
30  Used with a Geometry Helper to keep track of what go built.
31  {group:Archive Writing}
32  */
34 public:
35  trpgwGeomStats(void);
36  ~trpgwGeomStats(void);
37 
38  int totalTri;
39 
40  int totalQuad;
41 
46 
47  int numStrip;
48  int numFan;
49 
50  int stripStat[15];
51  int fanStat[15];
52 
53  int stripGeom;
54  int fanGeom;
55  int bagGeom;
56 
58 
60  inline void AddStripStat(int val) { stripStat[MIN(14,val)]++; totalStripTri += val; totalTri += val; numStrip++;}
61  inline void AddFanStat(int val) { fanStat[MIN(14,val)]++; totalFanTri += val; totalTri += val; numFan++;}
62  inline void AddBagStat(int val) { totalBagTri += val; totalTri += val;}
63  inline void AddQuadStat(int val) { totalQuad += val; }
64 };
65 
66 /* Geometry Helper
67  Collects up geometry and tries to form triangle strips, fans,
68  and groups of triangles.
69  Right now this looks for a very careful ordering. If that ordering
70  isn't there you won't get useful tristrips or fans. You can, however
71  use this class as a starting point and build something more akin
72  to the geometry builder in Performer.
73  {group:Archive Writing}
74  */
76 public:
77  trpgwGeomHelper(void);
78  virtual ~trpgwGeomHelper(void);
79  enum {UseDouble,UseFloat};
80  trpgwGeomHelper(trpgWriteBuffer *,int dataType=UseDouble);
81  void init(trpgWriteBuffer *,int dataType=UseDouble);
82  virtual void SetMode(int);
83  virtual void Reset(void);
85  virtual void StartPolygon(void);
86  virtual void EndPolygon(void);
87  virtual void ResetPolygon(void);
88 
89 
90  virtual void SetColor(trpgColor &);
91  virtual void SetTexCoord(trpg2dPoint &);
92  virtual void AddTexCoord(trpg2dPoint &);
93  virtual void SetNormal(trpg3dPoint &);
94  virtual void SetMaterial(int32);
95  virtual void AddMaterial(int32);
96 
97  virtual void AddVertex(trpg3dPoint &);
98 
100  virtual void FlushGeom(void);
101 
103  virtual void GetZMinMax(double &min,double &max);
104 
106  trpgwGeomStats *GetStats(void) { return &stats; }
107 protected:
108  int mode;
109  int dataType;
111 
112  /* Builds strips and fans from the triangle array.
113  We (TERREX) are assuming a certain ordering in our vertex array
114  because we do this optimization elsewhere. This won't work well
115  for anyone else. What you will need to do if you want good
116  performance is to implement a more generic form of this method.
117  All you should have to do is override Optimize(). You've
118  got the triangle arrays and a guarantee that the triangles
119  have the same material. All you really need is a decent fan/strip
120  algorithm.
121  */
122  virtual void Optimize(void);
123 
125  virtual void ResetTri(void);
126 
128  trpgGeometry strips,fans,bags;
129 
131  std::vector<int32> matTri;
132  std::vector<trpg2dPoint> tex;
133  std::vector<trpg3dPoint> norm,vert;
135  std::vector<int32> matPoly;
136  std::vector<trpg2dPoint> polyTex;
137  std::vector<trpg3dPoint> polyNorm,polyVert;
139  std::vector<trpg2dPoint> tmpTex;
142 
145 
147  double zmin,zmax;
148 };
149 
150 /* Image Write Helper.
151  Used to manage textures being added to a TerraPage archive.
152  It can write Local and Tile Local textures and also manages
153  the names of External textures (but you have to write those yourself).
154  */
156 public:
158  trpgwImageHelper(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
160  virtual void Init(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
161 
162  virtual ~trpgwImageHelper(void);
163 
165  virtual bool AddExternal(char *name,int &texID,bool lookForExisting=true);
166 
167  /* Adds an entry to the texture table for a local texture and
168  writes the data for that texture out to one of our texture
169  archive files.
170  */
171  virtual bool AddLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data,int &texID,bool deferWrite);
172 
173  /* Replaces texture table information for a local texture and
174  writes the data for that texture out to one of our texture
175  archive files.
176  Up to you to ensure data is appropriate for the texture.
177  */
178  virtual bool ReplaceLocal(char *data,int &texID);
179 
180  /* Write a Tile Local texture out to one of our texture archive files.
181  Also creates a texture template, if necessary.
182  Caller is responsible for creating the Tile Local material and
183  placing it in the appropriate tile.
184  */
185  virtual bool AddTileLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data, int &texID,trpgwAppAddress &addr);
186 
187  /* Sets the maximum advised length for a texture archive file.
188  Once the length is exceeded, the image write helper will move
189  on to the next tex file.
190  */
191  virtual void SetMaxTexFileLength(int len);
192 
193  /* Texture archive files are managed by this class and will
194  be created as needed. This method will increment to
195  the next texture file.
196  Note: This may create more files than we really need.
197  */
198  virtual trpgwAppFile * IncrementTextureFile(bool geotyp);
199 
200  /* Close the current texture file and go on to one with the
201  given base name. This is used for regenerate.
202  */
203  virtual bool DesignateTextureFile(int);
204 
206  virtual bool Flush(void);
207 
209  virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
210 
212  bool WriteToArchive(const trpgTexture &tex,char *data,trpgwAppAddress &addr,bool geotyp=false);
214 
215 protected:
216 
217 
219  char dir[1024];
221  std::vector<int> texFileIDs;
223  std::vector<int> geotypFileIDs;
227 };
228 
229 /* Paging Archive
230  This is a writeable paging archive.
231  It organizes where things get written and how.
232  {group:Archive Writing}
233  */
235 public:
237  enum TileMode {TileLocal,TileExternal,TileExternalSaved};
238 
241  trpgwArchive(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
242  virtual void Init(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
244  trpgwArchive(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
245  virtual void Init(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
247  trpgwArchive(int ) {;};
248  virtual ~trpgwArchive(void);
249 
252  virtual void SetMaxTileFileLength(int len);
253 
255  virtual bool SetHeader(const trpgHeader &);
256  virtual bool SetMaterialTable(const trpgMatTable &);
257  virtual bool SetTextureTable(const trpgTexTable &);
258  virtual bool SetModelTable(const trpgModelTable &);
259  virtual bool SetLightTable(const trpgLightTable &);
260  virtual bool SetRangeTable(const trpgRangeTable &);
261  virtual bool SetLabelPropertyTable(const trpgLabelPropertyTable &);
262  virtual bool SetSupportStyleTable(const trpgSupportStyleTable &);
263  virtual bool SetTextStyleTable(const trpgTextStyleTable &);
264 
266  virtual trpgHeader *GetHeader();
267  virtual trpgMatTable *GetMatTable();
268  virtual trpgTexTable *GetTextureTable();
269  virtual trpgModelTable *GetModelTable();
270  virtual trpgLightTable *GetLightTable();
271  virtual trpgRangeTable *GetRangeTable();
272  virtual trpgLabelPropertyTable *GetLabelPropertyTable();
273  virtual trpgTextStyleTable *GetTextStyleTable();
274  virtual trpgSupportStyleTable *GetSupportStyleTable();
275 
276 
277 
278  virtual bool IncrementTileFile(void);
279  virtual bool DesignateTileFile(int);
280 
283 
284  virtual bool OpenFile(const char *,const char *);
285  virtual void CloseFile(void);
286  virtual bool WriteHeader(void);
287  virtual bool CheckpointHeader(void);
288  virtual bool WriteTile(unsigned int,unsigned int,unsigned int,float zmin,float zmax,
289  const trpgMemWriteBuffer *,const trpgMemWriteBuffer *, int32& fileId, int32& fileOffset);
291 
292  bool isValid(void) const;
293  const char *getErrMess() const;
294  char* getDir(void){return dir;};
295  virtual trpgwImageHelper* GetNewWImageHelper(trpgEndian ness,char *dir,trpgTexTable &);
296  virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
297  virtual trpgr_Archive* GetArchiveReader() {return new trpgr_Archive();};
298  virtual int32 WriteHeaderData(const char *dataPtr,int32 length,FILE *filehandle);
299  virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
300 protected:
302  bool isRegenerate;
303 
306  public:
307  int x,y,lod;
308  float zmin,zmax;
310  };
311  class TileFile {
312  public:
313  int id;
314  std::vector<TileFileEntry> tiles;
315  };
316 
317  trpgEndian ness,cpuNess;
318  int majorVersion, minorVersion;
320  char dir[1024];
321 
323 
333 
334 
336 
337  int numLod;
339 
342 
343  std::vector<TileFile> tileFiles;
344 
345  std::vector<TileFileEntry> externalTiles;
346 
348 
351 
352  FILE *fp;
353 
355 
356  mutable char errMess[512];
357 };
358 
359 #endif

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)