HWMesh.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 *<
00003 FILE: HWMesh.h
00004 
00005 DESCRIPTION: Hardware Mesh Interface Implementation
00006 
00007 CREATED BY: Peter Watje
00008 
00009 HISTORY: Created June 13, 2008
00010 
00011 Copyright 2008 Autodesk, Inc.  All rights reserved.
00012 
00013 Use of this software is subject to the terms of the Autodesk license agreement 
00014 provided at the time of installation or download, or which otherwise accompanies 
00015 this software in either electronic or hard copy form.   
00016 
00017 
00018 These classes are designed to allow the creation of a retained hardware mesh that the display system 
00019 can quickly display.  With the old code you had an mesh/mnmesh which had a hardwaremesh interface.  
00020 The mesh then made a copy of itself but a tuple version and that was stored in the hardwaremesh interface.
00021 That interface was then passed the gfx layer which would then split the mesh based on size and material
00022 id's into index and vertex buffers that the gfx layer could consume.
00023 
00024 The new hwmesh pushes more of the work on the mesh end. This is to prevent the massive amount of
00025 copying we had with the old scheme.  Instead of copy the entire mesh into the hardware mesh and then 
00026 turning it into a tuple mesh.  The mesh passes a chunk to the hardware mesh.  This chunk is based on
00027 MatID and vertex buffer count (typically less then a dword).  The hardware mesh then turns this chunk 
00028 into a tuple mesh which is then passed to the gfx layer to have the hw vertex and index buffer created.
00029 Once that is done the tuple mesh is deleted and the next chunk is passed in.
00030 
00031 Mesh : HardwareMesh
00032             HWTupleMeshContainer - which is container that holds all our sub meshes.  Each entry is 1 matID and
00033                                 is typically has less than 65,500 vertex indices so we can use WORD indices to
00034                                 reduce memory foot print
00035                 Tab<GFX_MESH::HWTupleMesh *> this is the list of sub meshes.  Each sub mesh contains
00036                                     1 vertex buffer 
00037                                     2 index buffer 1 for shaded faces and 1 for wireframe(lineLis)
00038                                     IHWDrawMesh which is a pointer back to the raw hardware buffers that the device created.
00039 
00040 So to create a HWTupleMesh
00041     1.  The mesh first gets a list a faces that all have the same MatID and have less than the MaxVerts
00042     2.  That chunk is then converted into a tuple mesh and stored GFX_MESH::HWMesh
00043     3.  The GFX_MESH::HWMesh is then passed to the graphics window which tries a graphics window specific
00044         buffers.  If this is successfull the HWMesh tuple data is deleted.  If it fails the data is kept
00045         and when the data will be used to draw the mesh in immediate mode.  This can happen is we run out 
00046         of memory.
00047     4.  Repeat step one till you have no more faces to process
00048 
00049 When the mesh is drawn it just calls draw on each GFX_MESH::HWMesh entry.  If the entry contains graphic
00050 window specific buffers.  That is just immediately blasted out, if the hardware specific data is not there
00051 the tuple data is still there and can be drawn in immediate mode.
00052                     
00053 
00054 **********************************************************************/
00055 #pragma once
00056 
00057 #include "maxheap.h" 
00058 #include "tab.h" 
00059 #include "HWVertex.h"
00060 #include "HWIndex.h"
00061 // forward declarations
00062 class BitArray;
00063 class GraphicsWindow;
00064 class Point3; 
00065 
00066 namespace GFX_MESH
00067 {
00068 
00069 
00071 
00078     class IHWDrawMesh : public  MaxHeapOperators
00079     {
00080         
00081     public:
00083         DllExport IHWDrawMesh();
00084         virtual ~IHWDrawMesh() { ; }
00086 
00090         virtual void Draw(GraphicsWindow *gw, DWORD attribute) = 0;
00091 
00093 
00104         virtual void UpdateVertexBuffer(Point3 *vertexList,Point3 *gfxNormalList, Point3 *faceNormalList, BitArray &changedVerts, int count,
00105                                         unsigned int *vertMapList,  int *normalsMapList) = 0;
00106 
00108         virtual void Release() = 0;
00109         
00112         DllExport void MakeRef();
00113 
00114 
00115     protected:      
00116 
00117         
00120         DllExport void DecRefCount();
00121 
00122         
00125         DllExport bool CanDelete();
00126 
00127         int mRefCount;  //this is just a simple ref counter, when it is zero we can safely delete this class
00128 
00129     };
00130 
00132 
00134     class IHWSubMesh : public  MaxHeapOperators
00135     {
00136 
00137     public:
00138         virtual ~IHWSubMesh()   {   }
00139         
00141 
00145         virtual void Draw(GraphicsWindow *gw, DWORD attribute) = 0;
00146 
00148 
00159         virtual void UpdateVertexBuffer(Point3 *vertexList,Point3 *gfxNormalList, Point3 *faceNormalList, BitArray &changedVerts, int count,
00160             unsigned int *vertMapList,  int *normalsMapList) = 0;
00161 
00162     
00163 
00164     };
00165 
00166 
00167 
00169 
00173     class HWTupleMesh : public  MaxHeapOperators
00174     {
00175     public:
00177 
00180         DllExport HWTupleMesh(DWORD vertexType);
00181 
00183         DllExport ~HWTupleMesh();
00184 
00186         DllExport unsigned int Size();
00187 
00189 
00191         DllExport HWVertexBuffer*   GetHWVertexBuffer();
00192 
00194 
00201         DllExport unsigned int AddHWIndexBuffer(unsigned int numberPrimitives, PrimitiveType primitive, bool use16Bit);
00202 
00204         DllExport HWIndexBuffer*    GetHWIndexBuffer(unsigned int id);  
00205 
00207         DllExport bool              ReleaseHWIndexBuffer(unsigned int id);  
00208 
00210         DllExport unsigned int      GetHWIndexCount();  
00211 
00213 
00214         DllExport DWORD GetMatID(); 
00216 
00217         DllExport void  SetMatID(DWORD matID);  
00218 
00220 
00221         DllExport void  SetGFXMesh(IHWSubMesh *msh);
00223 
00224         DllExport IHWSubMesh* GetGFXMesh();
00225 
00227 
00234         DllExport void UpdateVertexBuffer(Point3 *vertexList,Point3 *gfxNormalList, Point3 *faceNormalList, BitArray &changedVerts, int count);
00235 
00236 
00237         
00238 
00239     private:
00240         DWORD                   mMatID;             //the matid associated with this chunk.  We only allow one material per chunk
00241         HWVertexBuffer          *mHWVertexBuffer;   // our vertex buffer
00242         Tab<HWIndexBuffer*>     mPrimitives;    // our array of index buffers
00243 
00244 
00245         IHWSubMesh              *mHWDrawMesh;       //pointer to the class that contains our graphics hardware specific buffers
00246 
00247     };
00248 
00249 
00250 
00252 
00254     class HWTupleMeshContainer : public IHWDrawMesh
00255     {
00256     public:
00258         DllExport HWTupleMeshContainer();
00260         DllExport ~HWTupleMeshContainer();  
00261 
00263         DllExport void FreeMeshes();    
00264 
00266         DllExport unsigned int Count();
00268         DllExport GFX_MESH::HWTupleMesh *Get(unsigned int id);
00270 
00273         DllExport void Append(GFX_MESH::HWTupleMesh *hwMesh);
00274 
00275 
00276 
00278 
00282         DllExport void Draw(GraphicsWindow *gw, DWORD attribute);
00283 
00285 
00296         DllExport void UpdateVertexBuffer(Point3 *vertexList,Point3 *gfxNormalList, Point3 *faceNormalList, BitArray &changedVerts, int count,
00297             unsigned int *vertMapList, int *normalsMapList);
00298 
00300          DllExport void Release();
00301 
00302     private:
00303         //new hw mesh representation
00304         Tab<GFX_MESH::HWTupleMesh *> mHWTupleMesh; //this is an array of all our sub mesh. a sub mesh are faces thathave the same mat ID
00305     };
00306 
00307 
00308 
00309 
00310 
00311 };