00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00047 #define NL3D_COARSEMESH_VERTEX_FORMAT_MGR (CVertexBuffer::PositionFlag|CVertexBuffer::TexCoord0Flag|CVertexBuffer::PrimaryColorFlag)
00048
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
00309 typedef std::map< uint, CRenderPass > TRenderingPassMap;
00310 TRenderingPassMap _RenderPass;
00311
00312
00313 CSmartPtr<CTextureFile> _Texture;
00314
00315
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
00338 static IObs *creator() {return new CCoarseMeshClipObs;}
00339 };
00340
00341 }
00342
00343
00344 #endif // NL_COARSE_MESH_MANAGER_H
00345
00346