Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

virtualtex.h

Go to the documentation of this file.
00001 // virtualtex.h
00002 //
00003 // Copyright (C) 2003, Chris Laurel
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _CELENGINE_VIRTUALTEX_H_
00011 #define _CELENGINE_VIRTUALTEX_H_
00012 
00013 #include <string>
00014 #include "celutil/basictypes.h"
00015 #include <celengine/texture.h>
00016 
00017 
00018 class VirtualTexture : public Texture
00019 {
00020  public:
00021     VirtualTexture(const std::string& _tilePath,
00022                    unsigned int _baseSplit,
00023                    unsigned int _tileSize,
00024                    const std::string& tilePrefix,
00025                    const std::string& tileType);
00026     ~VirtualTexture();
00027 
00028     virtual const TextureTile getTile(int lod, int u, int v);
00029     virtual void bind();
00030 
00031     virtual int getLODCount() const;
00032     virtual int getUTileCount(int lod) const;
00033     virtual int getVTileCount(int lod) const;
00034     virtual void beginUsage();
00035     virtual void endUsage();
00036 
00037  private:
00038     struct Tile
00039     {
00040         Tile() : lastUsed(0), tex(NULL), loadFailed(false) {};
00041         unsigned int lastUsed;
00042         ImageTexture* tex;
00043         bool loadFailed;
00044     };
00045 
00046     struct TileQuadtreeNode
00047     {
00048         TileQuadtreeNode() :
00049             tile(NULL)
00050         {
00051             for (int i = 0; i < 4; i++)
00052                 children[i] = NULL;
00053         };
00054                 
00055         Tile* tile;
00056         TileQuadtreeNode* children[4];
00057     };
00058 
00059     void populateTileTree();
00060     void addTileToTree(Tile* tile, uint lod, uint v, uint u);
00061     void makeResident(Tile* tile, uint lod, uint v, uint u);
00062     ImageTexture* loadTileTexture(uint lod, uint u, uint v);
00063 
00064     Tile* tiles;
00065     Tile* findTile(unsigned int lod,
00066                    unsigned int u, unsigned int v);
00067 
00068  private:
00069     std::string tilePath;
00070     std::string tileExt;
00071     std::string tilePrefix;
00072     unsigned int baseSplit;
00073     unsigned int tileSize;
00074     unsigned int ticks;
00075     unsigned int tilesRequested;
00076     unsigned int nResolutionLevels;
00077 
00078     enum {
00079         TileNotLoaded  = -1,
00080         TileLoadFailed = -2,
00081     };
00082 
00083     TileQuadtreeNode* tileTree[2];
00084 };
00085 
00086 
00087 VirtualTexture* LoadVirtualTexture(const std::string& filename);
00088 
00089 #endif // _CELENGINE_VIRTUALTEX_H_

Generated on Sat Jan 14 22:30:29 2006 for Celestia by  doxygen 1.4.1