HWVertex.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 *<
00003 FILE: HWVertex.h
00004 
00005 DESCRIPTION: Hardware Vertex 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 
00019 
00020 #pragma once
00021 #include "export.h"
00022 #include "maxheap.h" 
00023 #include "tab.h" 
00024 
00025 class Point3;
00026 
00027 namespace GFX_MESH
00028 {
00030     static const unsigned int kMAX_COLORS = 2;
00032     static const unsigned int kMAX_TEXTURES = 8;
00033 
00035 enum VertexType { 
00036     kPos = 1,                                               
00037     kNormal = 2 ,                                           
00038     kVC0  = 4 ,kVC1 = 8 ,                                   
00039     kUVW0 = 16 ,kUVW1 = 32 ,kUVW2 = 64, kUVW3 = 128,        
00040     kUVW4 = 256, kUVW5 = 512, kUVW6 = 1024, kUVW7 = 2048,
00041     kBinormal = 4096, kTangent = 8192                       
00042 };
00043 
00045 
00047 class HWVertex : public  MaxHeapOperators
00048 {
00049 public:
00050 
00052 
00055     DllExport HWVertex(DWORD vType);
00056     DllExport HWVertex();
00057     DllExport ~HWVertex();
00058 
00059 
00061 
00062     DllExport void SetVertexType(DWORD vType);
00064     DllExport DWORD GetVertexType();
00065 
00066 
00068 
00073     DllExport void  SetUVWSize(unsigned int id, unsigned int size);
00074 
00076 
00079     DllExport unsigned int  GetUVWSize(unsigned int id);
00080 
00082 
00085     DllExport void  SetBuffer(BYTE *vertexBuffer);
00086     
00088     DllExport unsigned int GetStride();
00089 
00091     DllExport  Point3 GetPos();
00094     DllExport  void SetPos(Point3 p);
00096     DllExport  Point3* GetPosPtr();
00097 
00099     DllExport  Point3 GetNormal();
00102     DllExport  void SetNormal(Point3 p);
00104     DllExport  Point3* GetNormalPtr();
00105 
00107     DllExport unsigned int GetMaxVC();
00108 
00111     DllExport DWORD GetVC(unsigned int id);
00115     DllExport void SetVC(unsigned int id, DWORD c);
00117     DllExport DWORD* GetVCPtr(unsigned int id);
00118 
00120     DllExport unsigned int GetMaxUVW();
00121 
00124     DllExport  float* GetUVW(unsigned int id);
00128     DllExport  void   SetUVW(unsigned int id, float *uv);
00129 
00131     DllExport  Point3 GetTangent();
00133     DllExport  Point3* GetTangentPtr();
00136     DllExport  void SetTangent(Point3 p);
00137 
00139     DllExport  Point3 GetBinormal();
00141     DllExport  Point3* GetBinormalPtr();
00144     DllExport  void SetBinormal(Point3 p);
00145 
00148     DllExport  void CopyDataFrom(HWVertex &hwVertSource);
00150     DllExport BYTE* GetRawBufferPointer();
00151 
00152 private:
00153     //This initializes all our data
00154     void Init();
00155     //this computes the stride of the vertex in bytes
00156     void    ComputeStride();
00157     //this computes our pointers offsets into vertex to allow quick look ups.
00158     //needs to be called after the stride has been computed
00159     void    ComputePointers();
00160 
00161     DWORD   mVertexType;    //Description of the HW Vertx
00162     BYTE*   mVertex;        //the pointer into the raw hw vertex buffer
00163     unsigned int mStride;   //the stride in byes of the hw vertex
00164 
00165     Point3      *mP;                    //Pointer to our Position component
00166     Point3      *mN;                    //Pointer to our Normal component
00167     DWORD       *mVC[kMAX_COLORS];  //Array of Pointers to our vertex color component
00168 
00169     unsigned int mUVWSizes[kMAX_TEXTURES];  //Array of sizes of each UVW channel
00170     float       *mUVW[kMAX_TEXTURES];       //Array of Pointers to our vertex UVW/texture component
00171     Point3      *mTangent;                  //Pointer to our Tangent component
00172     Point3      *mBinormal;                 //Pointer to our Binormal component
00173 
00174 };
00175 
00178 class HWVertexBuffer : public  MaxHeapOperators
00179 {
00180 public:
00183     DllExport HWVertexBuffer(DWORD vType);
00185     DllExport ~HWVertexBuffer();
00186 
00188     DllExport void FreeBuffer();
00189 
00191 
00196     DllExport void SetUVWSize(unsigned int id, unsigned int size);
00197 
00201     DllExport void SetMaxMapChannel(unsigned int hwChannel, int maxMapChannel);
00204     DllExport int GetMaxMapChannel(unsigned int hwChannel);
00205 
00207 
00211     DllExport bool CreateBuffer(unsigned int numVertice);
00212 
00214     DllExport unsigned int GetStride();
00216     DllExport inline unsigned int Size();
00217 
00219     DllExport inline unsigned int NumberVertices();
00220 
00222 
00225     DllExport bool SetNumberVertices(unsigned int ct);
00226 
00227 
00230     DllExport inline HWVertex GetHWVert(int id);
00231 
00232 
00234     DllExport BYTE *GetRawBufferPointer();
00235 
00236 
00237 
00240     DllExport void SetHasConnectionData(bool hasConnectionData);
00242     DllExport bool GetHasConnectionData();
00244 
00248     DllExport void SetConnectionData(unsigned int i,unsigned int oldPosID, int oldNormalID);
00249 
00251     DllExport unsigned int *GetPositionConnectionList();
00253     DllExport int *GetNormalConnectionList();
00254 
00255 private:
00256 
00257     bool                mHasConnectionData;     //whethe the connection data is allocated also
00258     Tab<unsigned int>   mOriginalVertID;        // this is an index list back into the original Max mesh so you 
00259     Tab<int>    mOriginalGFXNormalID; // this is an index list back into the original Max mesh so you 
00260                                         //this is special cased to handle vertices attached to a face with no smoothing group
00261                                         // in this case the value of the normal will be negative.  If that is the case you lookup the 
00262                                         // the normal in face normal list
00263 
00264     DWORD           mVertexType;        //Description of the HW Vertx
00265     HWVertex        mHWVertex;          //our HW vertex overlay so we can easily look up components in the hw vertex buffer
00266 
00267     unsigned int    mNumberVertices;    //number of vertices in the hw vertex buffer
00268     unsigned int    mStride;            //stride of each vertex in bytes
00269     Tab<BYTE>       mVertexBuffer;      //raw hw vertex data
00270     int             mMaxMapChannel[kMAX_TEXTURES];      //this maps the HW UVW channel to a Max UVW channel
00271 };
00272 
00275 class MeshVertex : public  MaxHeapOperators
00276 {
00277 public:
00279     DllExport MeshVertex();
00280 
00281 
00283     DllExport inline void InitHWVert();
00284 
00286     DllExport inline void SetSize(unsigned int s);
00287 
00289 
00296     DllExport inline bool IsInList(BYTE *hwVert, BYTE *vertexBuffer, unsigned int stride, DWORD &id);
00297     
00299 
00302     DllExport inline void  AddHWVert(DWORD id);
00303 
00304 
00305 private:
00306     //this is a list of indices into the HW vertex buffer that are needed to represent this mesh vertex
00307     Tab<DWORD>  mHWVertex;
00308 
00309 };
00310 }