root/OpenSceneGraph/trunk/src/osgPlugins/txp/trpage_read.h @ 13041

Revision 13041, 9.5 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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_read_h_
17// {secret}
18#define _txpage_read_h_
19
20/* txpage_read.h
21   Classes used to represent read objects for paging files.
22*/
23
24#include <trpage_sys.h>
25
26#include <trpage_geom.h>
27
28/* Callback base class
29   Called when a given token is found.
30   {group:Archive Reading}
31*/
32TX_EXDECL class TX_CLDECL trpgr_Callback
33{
34public:
35    virtual ~trpgr_Callback(void) { };
36    virtual void *Parse(trpgToken,trpgReadBuffer &) { return (void *)1; };
37};
38
39/* Paging Token
40   Stores callback info associated with a given token.
41   {group:Archive Reading}
42*/
43TX_EXDECL class TX_CLDECL trpgr_Token
44{
45public:
46    trpgr_Token(void);
47    trpgr_Token(int,trpgr_Callback *,bool destroy=true);
48    ~trpgr_Token(void);
49    void init(int,trpgr_Callback *,bool destroy=true);
50    int Token;            // Constant token value
51    trpgr_Callback *cb; // Callback when we hit this token
52    bool destroy;       // Should we call delete on the callback or not
53    void Destruct(void);    // Not quite like delete
54};
55
56/* Parse class for paging data structures.
57   This executes callbacks
58   {group:Archive Reading}
59*/
60TX_EXDECL class TX_CLDECL trpgr_Parser
61{
62public:
63    trpgr_Parser(void);
64    virtual ~trpgr_Parser(void);
65    bool isValid(void) const;
66
67    // Add and remove token callbacks
68    virtual void AddCallback(trpgToken,trpgr_Callback *,bool destroy = true);
69    virtual void AddCallback(trpgToken,trpgReadWriteable *);
70    virtual const trpgr_Callback *GetCallback(trpgToken tok) const;
71    virtual trpgr_Callback *GetCallback(trpgToken tok);
72    virtual void RemoveCallback(trpgToken);
73    virtual void SetDefaultCallback(trpgr_Callback *,bool destroy = true);
74    // Parse a read buffer
75    virtual bool Parse(trpgReadBuffer &);
76    virtual bool TokenIsValid(trpgToken);  // Check token validity
77protected:
78    void *lastObject;
79private:
80    // Note: Just how slow is a map<> anyway?
81    //         This usage is self-contained and could be replaced with an array
82#if defined(_WIN32)
83    typedef std::map<trpgToken,trpgr_Token> tok_map;
84#else
85    typedef std::map< trpgToken,trpgr_Token,std::less<trpgToken> > tok_map;
86#endif
87    tok_map tokenMap;
88    trpgr_Token defCb;     // Call this when no others are called
89};
90
91/* Image Read Helper.
92   Used to help read Local and Tile Local textures into
93   memory (in OpenGL format).  You're on your own for External
94   textures.
95   If you want to add additional ways to read textures, feel free
96   to subclass this object.
97*/
98class trpgwImageHelper;
99TX_EXDECL class TX_CLDECL trpgrImageHelper
100{
101 public:
102    trpgrImageHelper() {;};
103    trpgrImageHelper(trpgEndian ness,char *dir,const trpgMatTable &,const trpgTexTable &,bool separateGeoTyp);
104    // real construction is here
105    virtual void Init(trpgEndian ness,char *dir,const trpgMatTable &,const trpgTexTable &,bool separateGeoTyp);
106    virtual ~trpgrImageHelper(void);
107
108    /* Fetch the bytes for the given texture.
109       This is only valid for Local textures.
110    */
111    virtual bool GetLocalGL(const trpgTexture *,char *data,int32 dataSize);
112
113    /* Fetch the bytes for the given mip level of a given texture.
114       This is only valid for Local textures.
115    */
116    virtual bool GetMipLevelLocalGL(int miplevel, const trpgTexture *,char *data,int32 dataSize);
117
118    /* Do the lookups to figure out the correct material
119       and Template (or Local) texture for a given Local Material.
120       You'll need this for sizes (among other things).
121       This routine also calculates the total size, including mipmaps if they're there.
122    */
123    virtual bool GetImageInfoForLocalMat(const trpgLocalMaterial *locMat,
124                     const trpgMaterial **retMat,const trpgTexture **retTex,
125                     int &totSize);
126
127    /* Same as above, but gets info for nth image associated with this local material
128     */
129    virtual bool GetNthImageInfoForLocalMat(const trpgLocalMaterial *locMat, int index,
130                        const trpgMaterial **retMat,const trpgTexture **retTex,
131                        int &totSize);
132
133    /* Fetch the bytes for the given Local Material (and
134       associated texture).  This is for Tile Local and
135       Global textures.
136       Data is a pre-allocated buffer for the data and
137       dataSize is the size of that buffer.
138    */
139    virtual bool GetImageForLocalMat(const trpgLocalMaterial *locMat,char *data,int dataSize);
140
141    /* Same as above, but gets nth image associated with this local material
142     */
143    virtual bool GetNthImageForLocalMat(const trpgLocalMaterial *locMat, int index, char *data,int dataSize);
144
145    /* Same as the one above, just fetch single mip levels
146     */
147    virtual bool GetMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat,char *data,int dataSize);
148
149    /* Get mip levels for one of multiple images
150     */
151    virtual bool GetNthImageMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat, int index, char *data,int dataSize);
152
153    /* Determine the full path of the image in the given
154       trpgTexture class.
155       Only useful for External images.
156    */
157    virtual bool GetImagePath(const trpgTexture *,char *,int len);
158
159    virtual trpgrAppFileCache* GetNewRAppFileCache(const char *fullBase,const char *ext);
160
161    trpgrAppFileCache *GetGeoTypCache()
162    {
163    return geotypCache;
164    }
165    void SetTexTable(trpgTexTable *texTable)
166    {
167    this->texTable = texTable;
168    }
169 protected:
170    char dir[1024];
171    trpgEndian ness;
172    const trpgMatTable *matTable;
173    const trpgTexTable *texTable;
174
175    trpgrAppFileCache *texCache;
176    trpgrAppFileCache *geotypCache;
177    bool separateGeoTyp;
178};
179
180/* Paging Archive (read version)
181   This just reads the first bits of the file (and the header)
182   and lets you parse from there.
183   {group:Archive Reading}
184*/
185TX_EXDECL class TX_CLDECL trpgr_Archive : public trpgCheckable
186{
187public:
188    trpgr_Archive(void);
189    virtual ~trpgr_Archive(void);
190
191    virtual void SetDirectory(const char *);
192    virtual bool OpenFile(const char *);    // Open File
193    virtual void CloseFile(void);
194    virtual bool ReadHeader(void);        // Read header (materials, tile table. etc..)
195    //overload that lets you specify if you want to read all the blocks now,
196    //or defer reading them for later.
197    virtual bool ReadHeader(bool readAllBlocks);
198    bool ReadSubArchive(int row, int col, trpgEndian cpuNess);
199    // In version 2.1, only tile at lod 0 are fetchable via the tile table
200    virtual bool ReadTile(uint32 x, uint32 y, uint32 lod,trpgMemReadBuffer &);
201    virtual bool ReadTile(const trpgwAppAddress& addr, trpgMemReadBuffer &buf);
202    virtual bool ReadExternalTile(uint32 x,uint32 y,uint32 lod,trpgMemReadBuffer &buf);
203
204    // Get access to header info
205    virtual const trpgHeader *GetHeader(void) const;
206    virtual const trpgMatTable *GetMaterialTable(void) const;
207    virtual trpgTexTable *GetTexTable(void) ;
208    virtual const trpgModelTable *GetModelTable(void) const;
209    virtual const trpgTileTable *GetTileTable(void) const;
210    virtual const trpgLightTable *GetLightTable(void) const;
211    virtual const trpgRangeTable *GetRangeTable(void) const;
212    virtual const trpgLabelPropertyTable *GetLabelPropertyTable() const;
213    virtual const trpgTextStyleTable *GetTextStyleTable() const;
214    virtual const trpgSupportStyleTable *GetSupportStyleTable() const;
215
216    // Utility routine to calculate the MBR of a given tile
217    virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
218                trpg3dPoint &ll,trpg3dPoint &ur) const;
219
220    trpgEndian GetEndian(void) const;
221    char* getDir(void){return dir;};
222    virtual trpgrImageHelper* GetNewRImageHelper(trpgEndian ness,char *dir,const trpgMatTable &matTable,const trpgTexTable &texTable);
223    virtual trpgrAppFileCache* GetNewRAppFileCache(const char *fullBase, const char *ext);
224    virtual int32 GetHeaderData(char *dataPtr,int32 length,FILE *filehandle);
225    virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
226protected:
227    bool headerRead;
228    trpgEndian ness;
229    FILE *fp;
230    int fid;
231    // Header info
232    char dir[1024];
233    trpgHeader header;
234    trpgMatTable materialTable;
235    trpgTexTable texTable;
236    trpgModelTable modelTable;
237    trpgTileTable tileTable;
238    trpgLightTable lightTable;
239    trpgRangeTable rangeTable;
240    trpgTextStyleTable textStyleTable;
241    trpgSupportStyleTable supportStyleTable;
242    trpgLabelPropertyTable labelPropertyTable;
243
244    trpgrAppFileCache *tileCache;
245};
246
247class trpgSceneHelperPush;
248class trpgSceneHelperPop;
249class trpgSceneHelperDefault;
250/* Scene Parser
251   This class assists in parsing a scene graph structure (tiles and models).
252   To use it, do an archive ReadTile and pass the resulting Read Buffer to this
253   parser.
254   {group:Archive Reading}
255*/
256TX_EXDECL class TX_CLDECL trpgSceneParser : public trpgr_Parser
257{
258    friend class trpgSceneHelperPush;
259    friend class trpgSceneHelperPop;
260    friend class trpgSceneHelperDefault;
261public:
262    trpgSceneParser(void);
263    virtual ~trpgSceneParser(void);
264protected:
265    // Start defining children for the given object
266    virtual bool StartChildren(void *) { return true;};
267    virtual bool EndChildren(void *) { return true;};
268
269    // List of objects whose children we're working on
270    std::vector<void *> parents;
271};
272
273#endif
Note: See TracBrowser for help on using the browser.