# 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  

coarse_mesh_manager.h

Go 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_COARSE_MESH_MANAGER_H
00027 #define NL_COARSE_MESH_MANAGER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/rgba.h"
00031 
00032 #include "3d/transform.h"
00033 #include "3d/material.h"
00034 #include "3d/primitive_block.h"
00035 #include "3d/vertex_buffer.h"
00036 
00037 namespace NL3D 
00038 {
00039 
00040 // ***************************************************************************
00041 
00042 #define NL3D_COARSEMESH_VERTEXBUFFER_GRANULARITY_SHIFT  3
00043 #define NL3D_COARSEMESH_VERTEXBUFFER_GRANULARITY_MASK   (NL3D_COARSEMESH_VERTEXBUFFER_GRANULARITY-1)
00044 #define NL3D_COARSEMESH_VERTEXBUFFER_GRANULARITY                (1<<NL3D_COARSEMESH_VERTEXBUFFER_GRANULARITY_SHIFT)
00045 #define NL3D_COARSEMESH_VERTEXBUFFER_RESERVE                    10
00046 // The vertex Format used by the coarseMesh manager
00047 #define NL3D_COARSEMESH_VERTEX_FORMAT_MGR                               (CVertexBuffer::PositionFlag|CVertexBuffer::TexCoord0Flag|CVertexBuffer::PrimaryColorFlag)
00048 // The Vertex Format used for export CoarseMesh. MUST NOT HAVE color (important for material coloring/alphaTrans)
00049 #define NL3D_COARSEMESH_VERTEX_FORMAT_EXPORT                    (CVertexBuffer::PositionFlag|CVertexBuffer::TexCoord0Flag)
00050 #define NL3D_COARSEMESH_PRIMITIVE_BLOCK_SIZE                    100
00051 
00052 // ***************************************************************************
00053 
00054 class CMeshGeom;
00055 class CTransformShape;
00056 class CTextureFile;
00057 
00058 // ***************************************************************************
00059 
00060 const NLMISC::CClassId          CoarseMeshManagerId=NLMISC::CClassId(0x77554f87, 0x5bb373d8);
00061 
00062 // ***************************************************************************
00063 
00103 class CCoarseMeshManager : public CTransform
00104 {
00105 public:
00106 
00107         enum
00108         {
00109                 CantAddCoarseMesh = 0xffffffff
00110         };
00111 
00113         CCoarseMeshManager ();
00114 
00116         void setTextureFile (const char* file);
00117 
00122         uint64 addMesh (const CMeshGeom& geom);
00123 
00127         void removeMesh (uint64 id);
00128 
00132         void setMatrixMesh (uint64 id, const CMeshGeom& geom, const CMatrix& matrix);
00133 
00137         void setColorMesh (uint64 id, const CMeshGeom& geom, NLMISC::CRGBA color);
00138 
00142         void render (IDriver *drv);
00143 
00147         static void             registerBasic();
00148 
00152         CMaterial               &getMaterial() {return _Material;}
00153 
00154 private:
00155 
00159         static uint64 buildId (uint32 renderPassId, uint32 renderPassMeshId)
00160         {
00161                 return ((uint64)renderPassId|(((uint64)renderPassMeshId)<<32));
00162         }
00163 
00167         static uint32 getRenderPassId (uint64 id)
00168         {
00169                 return (uint32)(id&0xFFFFFFFF);
00170         }
00171 
00175         static uint32 getRenderPassMeshId (uint64 id)
00176         {
00177                 return (uint32)(id>>32);
00178         }
00179 
00180         class CRenderPass
00181         {
00182         public:
00183                 enum
00184                 {
00185                         CantAddMesh = 0xffffffff
00186                 };
00187 
00191                 void init (uint blockSize);
00192 
00196                 uint32 addMesh (const CMeshGeom& geom);
00197 
00201                 uint    getTriCount (const CMeshGeom& geom);
00202 
00206                 void removeMesh (uint32 id);
00207 
00211                 void setMatrixMesh (uint32 id, const CMeshGeom& geom, const CMatrix& matrix);
00212 
00216                 void setColorMesh (uint32 id, uint nVertices, NLMISC::CRGBA color);
00217 
00221                 void render (IDriver *drv, CMaterial& mat);
00222         private:
00223 
00227                 static uint32 buildId (uint16 primitiveBlockId, uint16 vertexBufferId)
00228                 {
00229                         return ((uint32)primitiveBlockId|(((uint32)vertexBufferId)<<16));
00230                 }
00231 
00235                 static uint16 getPrimitiveblockId (uint32 id)
00236                 {
00237                         return (uint16)(id & 0xFFFF);
00238                 }
00239 
00243                 static uint16 getVertexBufferId (uint32 id)
00244                 {
00245                         return (uint16)(id>>16);
00246                 }
00247 
00251                 class CPrimitiveBlockInfo
00252                 {
00253                 public:
00254                         enum
00255                         {
00256                                 Failed = 0,
00257                                 Success = 1,
00258                         };
00259 
00263                         uint    addMesh (uint16 vertexBufferId, const CMeshGeom& geom, uint32 firstVertexIndex, uint triCount);
00264 
00268                         void removeMesh (uint16 vertexBufferId);
00269 
00271                         class CMeshInfo
00272                         {
00273                         public:
00275                                 CMeshInfo (uint offset, uint length, uint16 vertexBufferId)
00276                                 {
00277                                         Offset=offset;
00278                                         Length=length;
00279                                         VertexBufferId=vertexBufferId;
00280                                 }
00281 
00283                                 uint    Offset;
00284 
00286                                 uint    Length;
00287 
00289                                 uint16  VertexBufferId;
00290                         };
00291 
00293                         void init (uint size);
00294 
00296                         CPrimitiveBlock                                 PrimitiveBlock;
00297 
00299                         std::list< CMeshInfo >                  MeshIdList;
00300                 };
00301 
00302                 uint                                                            VBlockSize;
00303                 CVertexBuffer                                           VBuffer;
00304                 std::list< uint16 >                                     FreeVBlock;
00305                 std::list< CPrimitiveBlockInfo >        PrimitiveBlockInfoList;
00306         };
00307 
00308         // Indexes allocation
00309         typedef std::map< uint, CRenderPass >   TRenderingPassMap;
00310         TRenderingPassMap                                               _RenderPass;
00311 
00312         // The unique texture used by all the coarse object inserted in the container.
00313         CSmartPtr<CTextureFile>                                 _Texture;
00314 
00315         // The unique material used by all the coarse object inserted in the container.
00316         CMaterial                                                               _Material;
00317 
00318         static IModel   *creator() {return new CCoarseMeshManager;}
00319 };
00320 
00321 // ***************************************************************************
00322 
00328 class   CCoarseMeshClipObs : public CTransformClipObs
00329 {
00330 public:
00331 
00333         // @{
00334         virtual bool    clip(IBaseClipObs *caller);
00335         // @}
00336 
00337         // The creator.
00338         static IObs     *creator() {return new CCoarseMeshClipObs;}
00339 };
00340 
00341 } // NL3D
00342 
00343 
00344 #endif // NL_COARSE_MESH_MANAGER_H
00345 
00346 /* End of coarse_mesh_manager.h */