/* KResourceDXDynamic.h Software processing용 vertex buffer Note: Resource는 아니지만 인터페이스 통일을 위해 상속함 Created 2006/04, by JiYoung */ #ifndef __KRESOURCEDXDYNAMIC_H__ #define __KRESOURCEDXDYNAMIC_H__ #include "KResourceDX.h" // // VTXDECLARATION_ALPHATEX용 vertex format // Dynamic vertex buffer에서 주로 사용 // /* struct DynamicVertex_old { // old-style, no mesh-blending vertex K3DVector pos; K3DVector normal; DWORD color0, color1; float u0, v0; float u1, v1, u2, v2, u3, v3; // Vertex declaration for CreateVertexDeclaration() const static D3DVERTEXELEMENT9 vertexDeclaration[]; const static DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX4 // TEX4 : use 4 vertex UVs | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) | D3DFVF_TEXCOORDSIZE2(2) | D3DFVF_TEXCOORDSIZE2(3) ; // 4 tex coords, [uv, uv, uv, uv] void clear() { pos.x = pos.y = pos.z = 0.f; normal.x = normal.y = 0.f; normal.z=1.0f; color0=0xffffffff; // white color1=0x00000000; u0 = 0.f; v0 = 0.f; u1 = 0.f; v1 = 0.f; u2 = 0.f; v2 = 0.f; u3 = 0.f; v3 = 0.f; } }; */ struct DynamicVertex { K3DVector pos; K3DVector normal; DWORD color0, color1; float u0, v0; float u1, v1; DWORD blendIndices; float blendWeight0, blendWeight1, blendWeight2; // aligned to 64-byte boundary const static D3DVERTEXELEMENT9 vertexDeclaration[]; ///< Vertex declaration for CreateVertexDeclaration() const static DWORD FVF = D3DFVF_XYZB4 | D3DFVF_LASTBETA_UBYTE4 ///< XYZ + 4 blend params (last one is DWORD blend indices) | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR ///< Normal and 2 colors | D3DFVF_TEX2 ///< TEX2 : use 2 vertex UVs | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) ///< 2 tex coords, [uv, uv] ; void clear() { pos.x = pos.y = pos.z = 0.f; blendWeight0=1.0f; blendWeight1=0.0f; blendWeight2=0.0f; blendIndices=0; normal.x = normal.y = 0.f; normal.z=1.0f; color0=0xffffffff; ///< white color1=0x00000000; u0 = 0.f; v0 = 0.f; u1 = 0.f; v1 = 0.f; } }; class KVertexBufferDX_dynamic : public K3DVertexBufferDX { public: KVertexBufferDX_dynamic(); virtual ~KVertexBufferDX_dynamic(); /// Inherited virtual void Lock( void** ppBuf, int& size, DWORD flags = 0 ); virtual void Unlock(); virtual bool Reload(); virtual bool PreReload(); virtual IDirect3DVertexBuffer9* GetD3DVertexBuffer() const { return vertexBuffer; } /// original bool create(UINT length, DWORD usage, DWORD FVF, D3DPOOL pool, bool autoPreserve=true); ///< See IDirect3DDevice9::CreateVertexBuffer() for parameters bool clear(); ///< Release(); /// Device Lost되어서 reload()되었을 때, autoPreserve가 false이면 ON됨. i.e. 버퍼에 데이터 다시 채워넣어야 한다. bool isReloaded() { return m_bHaveToReloadBuffer; } /// 버퍼에 데이터 다시 채워넣은 다음에 이거 불러서 flag reset할 것 void clearReloadedFlag() { m_bHaveToReloadBuffer=false; } void setVertexFormat(DWORD format) { m_format=format; } void setVertexStride(DWORD strideCount) { m_vtxStride=strideCount; } void setVertexCount(DWORD count) { m_vtxCount=count; } void setUsage(DWORD usage) { m_usage=usage; } protected: UINT m_bufferSize; ///< alloc된 버텍스 버퍼 크기 LPDIRECT3DVERTEXBUFFER9 vertexBuffer; bool m_autoDataPreserve; ///< Device lost시 reload()되는 경우, 버퍼의 데이터를 자동으로 refresh한다 void *m_pDataPreserveBuffer; ///< m_autoDataPreserver==true인 경우 Lock()/Unlock()시에 여기다 데이터를 dump한다 void *m_pLockedPosition; ///< Lock()시 ppBuf에 return한 pointer. i.e. !=NULL이면 Lock()된 상태이다. Unlock()에서 NULL로 reset한다 bool m_bHaveToReloadBuffer; ///< Reload()되었으나 m_autoDataPreserve가 false여서 수동으로 buffer를 채워야 한다 }; class KIndexBufferDX_dynamic : public K3DIndexBufferDX { public: KIndexBufferDX_dynamic(); virtual ~KIndexBufferDX_dynamic(); /// Inherited virtual void Lock( void** ppBuf, int& size, DWORD flags = 0 ); virtual void Unlock(); virtual bool Reload(); virtual bool PreReload(); virtual IDirect3DIndexBuffer9* GetD3DIndexBuffer() const { return indexBuffer; } /// original bool create(UINT length, DWORD usage, D3DFORMAT format, D3DPOOL pool, bool autoPreserve=true); ///< See IDirect3DDevice9::CreateIndexBuffer() for parameters bool clear(); ///< Release(); /// Device Lost되어서 reload()되었을 때, autoPreserve가 false이면 ON됨. i.e. 버퍼에 데이터 다시 채워넣어야 한다. bool isReloaded() { return m_bHaveToReloadBuffer; } /// 버퍼에 데이터 다시 채워넣은 다음에 이거 불러서 flag reset할 것 void clearReloadedFlag() { m_bHaveToReloadBuffer=false; } void setFormat(K3DFORMAT format) { m_format=format; } void setIndexCount(DWORD count) { m_idxCount=count; } protected: UINT m_bufferSize; ///< alloc된 인덱스 버퍼 크기 LPDIRECT3DINDEXBUFFER9 indexBuffer; bool m_autoDataPreserve; ///< Device lost시 reload()되는 경우, 버퍼의 데이터를 자동으로 refresh한다 void *m_pDataPreserveBuffer; ///< m_autoDataPreserver==true인 경우 Lock()/Unlock()시에 여기다 데이터를 dump한다 void *m_pLockedPosition; ///< Lock()시 ppBuf에 return한 pointer. i.e. !=NULL이면 Lock()된 상태이다. Unlock()에서 NULL로 reset한다 bool m_bHaveToReloadBuffer; ///< Reload()되었으나 m_autoDataPreserve가 false여서 수동으로 buffer를 채워야 한다 }; #endif // __KRESOURCEDXDYNAMIC_H__