# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

mesh_skin_manager.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 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 #include "std3d.h"
00027 
00028 #include "3d/mesh_skin_manager.h"
00029 
00030 
00031 namespace NL3D 
00032 {
00033 
00034 
00035 // ***************************************************************************
00036 CMeshSkinManager::CMeshSkinManager()
00037 {
00038         _Enabled= false;
00039         _VertexFormat= 0;
00040         _VertexSize= 0;
00041         _MaxVertices= 0;
00042         _CurentVBHard= 0;
00043 }
00044 // ***************************************************************************
00045 CMeshSkinManager::~CMeshSkinManager()
00046 {
00047         release();
00048 }
00049 
00050 // ***************************************************************************
00051 void                    CMeshSkinManager::init(IDriver *driver, uint vertexFormat, uint maxVertices)
00052 {
00053         nlassert(driver);
00054         // clean before.
00055         release();
00056 
00057         // setup, => correct for possible release below
00058         _Driver= driver;
00059 
00060         // a dummy VB, for easy setup
00061         CVertexBuffer   vb;
00062         vb.setVertexFormat(vertexFormat);
00063 
00064         // create the VBHard, if possible
00065         for(uint i=0;i<NumVBHard;i++)
00066         {
00067                 _VBHard[i]= _Driver->createVertexBufferHard(vb.getVertexFormat(), vb.getValueTypePointer(), maxVertices, IDriver::VBHardAGP);
00068                 // if filas, release all, and quit
00069                 if(_VBHard[i]==NULL)
00070                 {
00071                         release();
00072                         return;
00073                 }
00074         }
00075 
00076         // init misc
00077         _Enabled= true;
00078         _VertexFormat= vb.getVertexFormat();
00079         _VertexSize= vb.getVertexSize();
00080         _MaxVertices= maxVertices;
00081         _CurentVBHard= 0;
00082 }
00083 // ***************************************************************************
00084 void                    CMeshSkinManager::release()
00085 {
00086         // release driver/VBHard
00087         if(_Driver)
00088         {
00089                 for(uint i=0;i<NumVBHard;i++)
00090                 {
00091                         if(_VBHard[i])
00092                                 _Driver->deleteVertexBufferHard(_VBHard[i]);
00093                         _VBHard[i]= NULL;
00094                 }
00095                 _Driver= NULL;
00096         }
00097 
00098         // misc
00099         _Enabled= false;
00100         _VertexFormat= 0;
00101         _VertexSize= 0;
00102         _MaxVertices= 0;
00103         _CurentVBHard= 0;
00104 }
00105 // ***************************************************************************
00106 uint8                   *CMeshSkinManager::lock()
00107 {
00108         return  (uint8*)_VBHard[_CurentVBHard]->lock();
00109 }
00110 // ***************************************************************************
00111 void                    CMeshSkinManager::unlock(uint numVertices)
00112 {
00113         // ATI: release only vertices used.
00114         _VBHard[_CurentVBHard]->unlock(0, numVertices);
00115 }
00116 // ***************************************************************************
00117 void                    CMeshSkinManager::activate()
00118 {
00119         _Driver->activeVertexBufferHard(_VBHard[_CurentVBHard]);
00120 }
00121 // ***************************************************************************
00122 void                    CMeshSkinManager::swapVBHard()
00123 {
00124         _CurentVBHard++;
00125         _CurentVBHard= _CurentVBHard%NumVBHard;
00126 }
00127 
00128 
00129 } // NL3D