Sign in to follow this  

Reusable Mesh in DX10

Recommended Posts

class Mesh : public INode
ID3D10Device* m_pD3DDevice;

ID3D10Buffer* m_pVertexBuffer;
ID3D10Buffer* m_pIndexBuffer;

D3D10_TECHNIQUE_DESC m_techDesc;

//input layout and mesh
ID3D10InputLayout* m_pVertexLayout;

//effects and techniques
ID3D10Effect* m_pBasicEffect;
ID3D10EffectTechnique* m_pBasicTechnique;

//Shader Resource View Variable
ID3D10ShaderResourceView* m_pTextureSRV;

//effect variable pointers
ID3D10EffectShaderResourceVariable* m_pTexutreEffectSRV;

//Vertex and Index Buffer
std::vector<sCustomVertex> m_Vertices;
std::vector<unsigned int> m_Indices;

//Vertex and Index Count
int m_iVertexCount;
int m_iIndexCount;

//Shader Path
WCHAR* m_pShaderPath;

//Texture Path
WCHAR* m_pTexturePath;
char* m_TechniqueName;

ThreadBufferManager* m_pThreadBufferManager;

//Object Culling
bool m_bIsCulled;

ID3D10EffectMatrixVariable* m_pWorldViewProjectionMatrixEffectVariable;
ID3D10EffectMatrixVariable* m_fxWorldVariable;
ID3D10EffectMatrixVariable* m_fxLightRotation;
ID3D10EffectVariable* m_fxEyePosVar;
ID3D10EffectVariable* m_fxLightVar;
ID3D10EffectScalarVariable* m_fxLightType;

ID3D10Device* GetMeshDevice() { return m_pD3DDevice; }
void SetMeshDevice(ID3D10Device* device) { m_pD3DDevice = device; }
void SetShaderPath(WCHAR *pFilename) { m_pShaderPath = pFilename; }
void SetTexturePath(WCHAR *pFilename) { m_pTexturePath = pFilename; }
void SetTechnique(char* technique) { m_TechniqueName = technique; }
void SetCulling(bool bCull) { m_bIsCulled = bCull; }

virtual void CreateVertexIndexBuffer();
virtual void CreatePhysxShape();
virtual bool Initialize();
virtual void Update(float dt);
virtual bool Render(int a_iExecID);
virtual bool LoadShadersAndCreateInputLayouts();
virtual bool SetTextureForShaders(unsigned int uiIndex);

This is my Mesh Class. The following classes will inherit this class

* MeshCube
* MeshGrid
* MeshCylinder
* MeshSphere

In the Create function(virtual function) i procedurally create shapes. For me, if i instance 100 cubes, 100 spheres, 100 grids, it goes into Create function 100 times and create the vertices and indices 100 times. what should i do if i want to create the Vertices and Indices only once for every object. One way which i thought is to take the variable 'm_Vertices' and 'm_Indices' to every other class and make them static, so it declares only once...

Kindly suggest me if there is any other better method. A better method could really lower my loading time.

Share this post

Link to post
Share on other sites
It would be far clever to split the mesh instance from the mesh geometry.

The mesh instance keep the world matrix, the visibility status, a reference to the geometry and things that really belong to the instance, and the geometry keep the vertices, the material and things that are common to every instance!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this