Files
mtgodot-poc/src/platform/EterLib/GrpIndexBuffer.cpp
T
shenleiandClaude Opus 5.5 a46093104c layout: restructure into src/ tests/ android/ scripts/ tools/
- extension/src/{port,platform,codepage} -> src/; native_render -> src/host
  (+ dxt, shaders/); libgr2 -> src/gr2; extension/third_party -> third_party
- extension/tests -> tests/port, libgr2/tests -> tests/gr2
- android-native -> android (build.sh, push-client.sh moved in)
- script -> scripts; tools/40250 -> tools/server; oracle -> tools/granny-oracle;
  perf tools -> tools/perf
- all build trees under build/ (native, release, android, port-gate)
- xrender:: CMake aliases -> mt::; port-map ledger impl paths rewritten

No code changes. ctest 15/15, port_gate macos+android PASS, port_map check 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 19:08:19 +09:00

131 lines
2.7 KiB
C++

// 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<MtCpuIndexBuffer*>(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<MtCpuIndexBuffer*>(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<MtCpuIndexBuffer*>(m_lpd3dIdxBuf)->revision++;
}
bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices)
{
assert(m_lpd3dIdxBuf!=NULL);
memcpy(index_bytes(m_lpd3dIdxBuf), srcIndices, bufSize);
static_cast<MtCpuIndexBuffer*>(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<WORD*>(index_bytes(m_lpd3dIdxBuf));
for (int i = 0; i<faceCount; ++i, dstIndices+=3)
{
TFace * curFace=faces+i;
dstIndices[0]=curFace->indices[0];
dstIndices[1]=curFace->indices[1];
dstIndices[2]=curFace->indices[2];
}
static_cast<MtCpuIndexBuffer*>(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<MtCpuIndexBuffer*>(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();
}