MipMapPatchIndexs.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_MipMapPatchIndexsh_INCLUDE__)
00022 #define __INCLUDE_MipMapPatchIndexsh_INCLUDE__
00023 
00024 #include <geomipmap/MipMapPatchIndex.h>
00025 #include <common/DefinesAssert.h>
00026 #include <common/DefinesMath.h>
00027 #include <vector>
00028 
00029 class GLVertexBufferObject;
00030 class MipMapPatchIndexs
00031 {
00032 protected:
00033 
00034         class IndexLevel // One per LOD
00035         {
00036         public:
00037                 IndexLevel();
00038                 ~IndexLevel();
00039 
00040                 std::vector<MipMapPatchIndex *> borderIndexs_;
00041         };
00042 
00043 public:
00044         MipMapPatchIndexs();
00045         ~MipMapPatchIndexs();
00046 
00047         MipMapPatchIndex *getIndex(int lod, int leftLod, int rightLod, int topLod, int bottomLod, int addLod = 0)
00048         {
00049                 lod = MIN(lod + addLod, getNoLevels() - 1);
00050                 leftLod = MIN(leftLod + addLod, getNoLevels() - 1);
00051                 rightLod = MIN(rightLod + addLod, getNoLevels() - 1);
00052                 topLod = MIN(topLod + addLod, getNoLevels() - 1);
00053                 bottomLod = MIN(bottomLod + addLod, getNoLevels() - 1);
00054 
00055                 unsigned int borders = 0;
00056                 if (leftLod != -1 && leftLod > lod) 
00057                 {
00058                         borders |= (leftLod - lod);
00059                 }
00060                 if (rightLod != -1 && rightLod > lod)
00061                 {
00062                         borders |= (rightLod - lod) << 3;
00063                 }
00064                 if (topLod != -1 && topLod > lod) 
00065                 {
00066                         borders |= (topLod - lod) << 9;
00067                 }
00068                 if (bottomLod != -1 && bottomLod > lod) 
00069                 {
00070                         borders |= (bottomLod - lod) << 6;
00071                 }
00072 
00073                 return getIndex(lod, borders);
00074         }
00075 
00076         MipMapPatchIndex *getIndex(int lod, int border) 
00077         { 
00078                 if (lod<0) lod=0;
00079                 else if (lod >= getNoLevels()) lod = getNoLevels()-1;
00080 
00081                 DIALOG_ASSERT(border < 4096);
00082 
00083                 IndexLevel *level = levels_[lod];
00084                 MipMapPatchIndex *index = level->borderIndexs_[border];
00085                 if (!index->getIndices()) return 0;
00086 
00087                 return index;
00088         }
00089         int getNoLevels() { return (int) levels_.size(); }
00090 
00091         void generate(int size, int totalsize, unsigned int totallods = 99);
00092 
00093         GLVertexBufferObject *getBufferObject() { return bufferObject_; }
00094 
00095 protected:
00096         std::vector<IndexLevel *> levels_;
00097         GLVertexBufferObject *bufferObject_;
00098 };
00099 
00100 #endif // __INCLUDE_MipMapPatchIndexsh_INCLUDE__

Generated on Mon Feb 16 15:14:38 2009 for Scorched3D by  doxygen 1.5.3