// 40250 EterLib/GrpIndexBuffer.cpp over CPU memory (CpuBuffer.h). #include "EterLib/StdAfx.h" #include "EterLib/GrpIndexBuffer.h" #include "EterLib/StateManager.h" #include "CpuBuffer.h" namespace { BYTE* index_bytes(LPDIRECT3DINDEXBUFFER8 buffer) { return static_cast(buffer)->bytes.data(); } } LPDIRECT3DINDEXBUFFER8 CGraphicIndexBuffer::GetD3DIndexBuffer() const { assert(m_lpd3dIdxBuf!=NULL); return m_lpd3dIdxBuf; } void CGraphicIndexBuffer::SetIndices(int startIndex) const { STATEMANAGER.SetIndices(m_lpd3dIdxBuf, startIndex); } bool CGraphicIndexBuffer::Lock(void** pretIndices) const { assert(m_lpd3dIdxBuf!=NULL); *pretIndices = index_bytes(m_lpd3dIdxBuf); return true; } void CGraphicIndexBuffer::Unlock() const { assert(m_lpd3dIdxBuf!=NULL); static_cast(m_lpd3dIdxBuf)->revision++; } bool CGraphicIndexBuffer::Lock(void** pretIndices) { assert(m_lpd3dIdxBuf!=NULL); *pretIndices = index_bytes(m_lpd3dIdxBuf); return true; } void CGraphicIndexBuffer::Unlock() { assert(m_lpd3dIdxBuf!=NULL); static_cast(m_lpd3dIdxBuf)->revision++; } bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices) { assert(m_lpd3dIdxBuf!=NULL); memcpy(index_bytes(m_lpd3dIdxBuf), srcIndices, bufSize); static_cast(m_lpd3dIdxBuf)->revision++; return true; } bool CGraphicIndexBuffer::Create(int faceCount, TFace* faces) { int idxCount = faceCount * 3; m_iidxCount = idxCount; if (!Create(idxCount, D3DFMT_INDEX16)) return false; WORD* dstIndices = reinterpret_cast(index_bytes(m_lpd3dIdxBuf)); for (int i = 0; iindices[0]; dstIndices[1]=curFace->indices[1]; dstIndices[2]=curFace->indices[2]; } static_cast(m_lpd3dIdxBuf)->revision++; return true; } bool CGraphicIndexBuffer::CreateDeviceObjects() { MtCpuIndexBuffer* buffer = new MtCpuIndexBuffer; buffer->bytes.assign(m_dwBufferSize, 0); buffer->format = m_d3dFmt; m_lpd3dIdxBuf = buffer; return true; } void CGraphicIndexBuffer::DestroyDeviceObjects() { delete static_cast(m_lpd3dIdxBuf); m_lpd3dIdxBuf = NULL; } bool CGraphicIndexBuffer::Create(int idxCount, D3DFORMAT d3dFmt) { Destroy(); m_iidxCount = idxCount; m_dwBufferSize = sizeof(WORD) * idxCount; m_d3dFmt = d3dFmt; return CreateDeviceObjects(); } void CGraphicIndexBuffer::Destroy() { DestroyDeviceObjects(); } void CGraphicIndexBuffer::Initialize() { m_lpd3dIdxBuf=NULL; m_iidxCount=0; m_dwBufferSize=0; } CGraphicIndexBuffer::CGraphicIndexBuffer() { Initialize(); } CGraphicIndexBuffer::~CGraphicIndexBuffer() { Destroy(); }