Files
mtgodot-poc/src/platform/EterLib/CpuBuffer.h
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

73 lines
2.2 KiB
C++

#pragma once
// CPU-memory vertex/index buffers behind the D3D8 buffer handles. 40250 fills its buffers through
// Lock/Unlock (CGrannyModel::__LoadVertices, CGrannyModelInstance deform) and the renderer later reads
// them back, so the platform keeps the bytes in memory instead of creating device objects.
#include "EterLib/StdAfx.h"
#include <cstdint>
#include <atomic>
#include <vector>
inline std::atomic<std::uint64_t> mt_next_cpu_buffer_id{1};
struct MtCpuVertexBuffer : IDirect3DVertexBuffer8
{
const std::uint64_t id = mt_next_cpu_buffer_id.fetch_add(1, std::memory_order_relaxed);
std::uint64_t revision = 0;
std::vector<uint8_t> bytes;
DWORD fvf = 0;
HRESULT Lock(UINT offset, UINT size, BYTE** data, DWORD) override
{
if (size_t(offset) + size > bytes.size())
return E_FAIL;
*data = bytes.data() + offset;
return S_OK;
}
HRESULT Unlock() override { ++revision; return S_OK; }
};
struct MtCpuIndexBuffer : IDirect3DIndexBuffer8
{
const std::uint64_t id = mt_next_cpu_buffer_id.fetch_add(1, std::memory_order_relaxed);
std::uint64_t revision = 0;
std::vector<uint8_t> bytes;
D3DFORMAT format = D3DFMT_INDEX16;
HRESULT Lock(UINT offset, UINT size, BYTE** data, DWORD) override
{
if (size_t(offset) + size > bytes.size())
return E_FAIL;
*data = bytes.data() + offset;
return S_OK;
}
HRESULT Unlock() override { ++revision; return S_OK; }
};
// D3DXGetFVFVertexSize.
inline unsigned mt_fvf_vertex_size(DWORD fvf)
{
unsigned size = 0;
switch (fvf & D3DFVF_POSITION_MASK)
{
case D3DFVF_XYZ: size += 12; break;
case D3DFVF_XYZRHW: size += 16; break;
case D3DFVF_XYZB1: size += 16; break;
case D3DFVF_XYZB2: size += 20; break;
case D3DFVF_XYZB3: size += 24; break;
case D3DFVF_XYZB4: size += 28; break;
case D3DFVF_XYZB5: size += 32; break;
}
if (fvf & D3DFVF_NORMAL) size += 12;
if (fvf & D3DFVF_PSIZE) size += 4;
if (fvf & D3DFVF_DIFFUSE) size += 4;
if (fvf & D3DFVF_SPECULAR) size += 4;
const unsigned texCount = (fvf & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
for (unsigned i = 0; i < texCount; ++i)
{
static const unsigned coordSize[4] = { 8, 12, 16, 4 };
size += coordSize[(fvf >> (16 + i * 2)) & 3];
}
return size;
}