Home | nevrax.com |
|
landscapevb_allocator.hGo to the documentation of this file.00001 00007 /* Copyright, 2001 Nevrax Ltd. 00008 * 00009 * This file is part of NEVRAX NEL. 00010 * NEVRAX NEL is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2, or (at your option) 00013 * any later version. 00014 00015 * NEVRAX NEL is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * General Public License for more details. 00019 00020 * You should have received a copy of the GNU General Public License 00021 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00022 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00023 * MA 02111-1307, USA. 00024 */ 00025 00026 #ifndef NL_LANDSCAPEVB_ALLOCATOR_H 00027 #define NL_LANDSCAPEVB_ALLOCATOR_H 00028 00029 #include "nel/misc/types_nl.h" 00030 #include "nel/misc/smart_ptr.h" 00031 #include "3d/tessellation.h" 00032 #include "3d/vertex_buffer.h" 00033 00034 00035 namespace NL3D 00036 { 00037 00038 00039 class IDriver; 00040 00041 00042 // *************************************************************************** 00043 // Landscape VertexProgram: Position of vertices in VertexBuffer. 00044 #define NL3D_LANDSCAPE_VPPOS_STARTPOS (CVertexBuffer::Position) 00045 #define NL3D_LANDSCAPE_VPPOS_TEX0 (CVertexBuffer::TexCoord0) 00046 #define NL3D_LANDSCAPE_VPPOS_TEX1 (CVertexBuffer::TexCoord1) 00047 #define NL3D_LANDSCAPE_VPPOS_TEX2 (CVertexBuffer::TexCoord5) 00048 #define NL3D_LANDSCAPE_VPPOS_GEOMINFO (CVertexBuffer::TexCoord2) 00049 #define NL3D_LANDSCAPE_VPPOS_DELTAPOS (CVertexBuffer::TexCoord3) 00050 #define NL3D_LANDSCAPE_VPPOS_ALPHAINFO (CVertexBuffer::TexCoord4) 00051 00052 00053 // *************************************************************************** 00060 class CLandscapeVBAllocator 00061 { 00062 public: 00063 00064 enum TType {Far0, Far1, Tile}; 00065 00067 CLandscapeVBAllocator(TType type); 00068 ~CLandscapeVBAllocator(); 00069 00079 void updateDriver(IDriver *driver); 00080 00081 00082 // delete all VB, and free driver ressources (if RefPtr driver not deleted). clear list too. 00083 void clear(); 00084 00085 00087 // @{ 00088 00089 // true if reallocationOccurs during a allocateVertex() or a setDriver(). 00090 // a buildVBInfo() should be done and ALL data are lost, so all VB must be rewrited. 00091 bool reallocationOccurs() const {return _ReallocationOccur;} 00092 void resetReallocation(); 00093 00094 // Allocate free vertices in VB. (AGP or RAM). work with locked or unlocked buffer. 00095 // NB: if reallocationOccurs(), then ALL data are lost. 00096 uint allocateVertex(); 00097 // Delete free vertices in VB. (AGP or RAM). 00098 void deleteVertex(uint vid); 00099 // @} 00100 00101 00103 // @{ 00107 void lockBuffer(CFarVertexBufferInfo &farVB); 00108 void lockBuffer(CNearVertexBufferInfo &tileVB); 00109 void unlockBuffer(); 00110 bool bufferLocked() const {return _BufferLocked;} 00111 00116 void activate(uint vpId); 00117 // @} 00118 00119 00120 // ****************** 00121 private: 00122 00123 // For Debug. 00124 struct CVertexInfo 00125 { 00126 bool Free; 00127 }; 00128 00129 private: 00130 TType _Type; 00131 00132 bool _ReallocationOccur; 00133 // List of vertices free. 00134 std::vector<uint> _VertexFreeMemory; 00135 std::vector<CVertexInfo> _VertexInfos; 00136 uint _NumVerticesAllocated; 00137 00138 00140 // @{ 00141 00142 // a refPtr on the driver, to delete VBuffer Hard at clear(). 00143 NLMISC::CRefPtr<IDriver> _Driver; 00144 // tell if VBHard is possible. 00145 bool _VBHardOk; 00146 CVertexBuffer _VB; 00147 NLMISC::CRefPtr<IVertexBufferHard> _VBHard; 00148 bool _BufferLocked; 00149 00150 /* try to create a vertexBufferHard or a vbSoft if not possible. 00151 After this call, the vertexBufferHard may be NULL. 00152 */ 00153 void deleteVertexBuffer(); 00154 void allocateVertexBuffer(uint32 numVertices); 00155 // @} 00156 00157 00159 // @{ 00160 enum {MaxVertexProgram= 2,}; 00161 // Vertex Program , NULL if not enabled. 00162 CVertexProgram *_VertexProgram[MaxVertexProgram]; 00163 void deleteVertexProgram(); 00164 void setupVBFormatAndVertexProgram(bool withVertexProgram); 00165 // @} 00166 00167 }; 00168 00169 00170 } // NL3D 00171 00172 00173 #endif // NL_LANDSCAPEVB_ALLOCATOR_H 00174 00175 /* End of landscapevb_allocator.h */ |