metaforce/hecl/lib/Runtime/HMDL.cpp

60 lines
1.6 KiB
C++
Raw Normal View History

#include "HECL/HMDLMeta.hpp"
2015-11-13 02:12:09 +00:00
#include "HECL/Runtime.hpp"
#include <Athena/MemoryReader.hpp>
2015-11-13 02:12:09 +00:00
namespace HECL
{
namespace Runtime
{
static LogVisor::LogModule Log("HMDL");
2015-11-13 02:12:09 +00:00
HMDLData::HMDLData(boo::IGraphicsDataFactory* factory,
const void* metaData, const void* vbo, const void* ibo)
2015-11-13 02:12:09 +00:00
{
HMDLMeta meta;
{
Athena::io::MemoryReader r((atUint8*)metaData, HECL_HMDL_META_SZ);
meta.read(r);
}
2015-11-14 23:40:32 +00:00
if (meta.magic != 'TACO')
Log.report(LogVisor::FatalError, "invalid HMDL magic");
m_vbo = factory->newStaticBuffer(boo::BufferUseVertex, vbo, meta.vertStride, meta.vertCount);
m_ibo = factory->newStaticBuffer(boo::BufferUseIndex, ibo, 4, meta.indexCount);
size_t elemCount = 2 + meta.colorCount + meta.uvCount + meta.weightCount;
std::unique_ptr<boo::VertexElementDescriptor[]> vdescs(new boo::VertexElementDescriptor[elemCount]);
for (size_t i=0 ; i<elemCount ; ++i)
{
vdescs[i].vertBuffer = m_vbo;
vdescs[i].indexBuffer = m_ibo;
}
vdescs[0].semantic = boo::VertexSemanticPosition;
vdescs[1].semantic = boo::VertexSemanticNormal;
size_t e = 2;
for (size_t i=0 ; i<meta.colorCount ; ++i, ++e)
{
vdescs[e].semantic = boo::VertexSemanticColor;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<meta.uvCount ; ++i, ++e)
{
vdescs[e].semantic = boo::VertexSemanticUV;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<meta.weightCount ; ++i, ++e)
{
vdescs[e].semantic = boo::VertexSemanticWeight;
vdescs[e].semanticIdx = i;
}
m_vtxFmt = factory->newVertexFormat(elemCount, vdescs.get());
2015-11-13 02:12:09 +00:00
}
}
}