D3DGeometryItem.h
#ifndef D3DGeometryItem_h_
#define D3DGeometryItem_h_
#if defined(D3D9_SUPPORTED)
#include <maya/MDagPath.h>
#include <maya/MObjectHandle.h>
#include <maya/MMessage.h>
#include <list>
#define WIN32_LEAN_AND_MEAN
#include <d3d9.h>
#include <d3dx9.h>
class D3DGeometry
{
public:
D3DGeometry()
: VertexBuffer( NULL), IndexBuffer( NULL), FVF( 0), Stride( 0), NumVertices( 0), NumIndices( 0)
{
}
~D3DGeometry()
{
Release();
}
bool Populate( const MDagPath& dagPath, LPDIRECT3DDEVICE9 D3D);
bool Render( LPDIRECT3DDEVICE9 D3D)
{
D3D->SetStreamSource( 0, VertexBuffer, 0, Stride );
D3D->SetFVF( FVF);
D3D->SetIndices( IndexBuffer);
D3D->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, NumVertices, 0, NumIndices / 3);
return true;
}
void Release()
{
if( VertexBuffer)
VertexBuffer->Release();
if( IndexBuffer)
IndexBuffer->Release();
VertexBuffer = NULL;
IndexBuffer = NULL;
}
private:
LPDIRECT3DVERTEXBUFFER9 VertexBuffer;
LPDIRECT3DINDEXBUFFER9 IndexBuffer;
unsigned int NumVertices;
unsigned int NumIndices;
DWORD FVF;
int Stride;
};
struct GeometryItem {
MDagPath m_objectPath;
D3DGeometry* m_objectGeometry;
MCallbackId m_objectDeleteMonitor;
MCallbackId m_objectDirtyMonitor;
MCallbackId m_objectChangeMonitor;
};
typedef std::list<GeometryItem*> GeometryItemList;
#endif
#endif