metaforce/hecl/lib/Runtime/HMDL.cpp

104 lines
3.1 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");
2015-11-21 01:13:06 +00:00
m_vbo = factory->newStaticBuffer(boo::BufferUse::Vertex, vbo, meta.vertStride, meta.vertCount);
m_ibo = factory->newStaticBuffer(boo::BufferUse::Index, ibo, 4, meta.indexCount);
if (factory->bindingNeedsVertexFormat())
m_vtxFmt = NewVertexFormat(factory, meta, m_vbo, m_ibo);
}
/* For binding constructors that require vertex format up front (GLSL) */
boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory* factory, const HMDLMeta& meta,
boo::IGraphicsBuffer* vbo, boo::IGraphicsBuffer* ibo)
{
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 = vbo;
vdescs[i].indexBuffer = ibo;
}
2015-11-21 01:13:06 +00:00
vdescs[0].semantic = boo::VertexSemantic::Position;
vdescs[1].semantic = boo::VertexSemantic::Normal;
size_t e = 2;
for (size_t i=0 ; i<meta.colorCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::Color;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<meta.uvCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::UV;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<meta.weightCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::Weight;
vdescs[e].semanticIdx = i;
}
return factory->newVertexFormat(elemCount, vdescs.get());
}
/* For shader constructors that require vertex format up-front (HLSL) */
boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory *factory) const
{
size_t elemCount = 2 + m_colorCount + m_uvCount + m_weightCount;
std::unique_ptr<boo::VertexElementDescriptor[]> vdescs(new boo::VertexElementDescriptor[elemCount]);
for (size_t i=0 ; i<elemCount ; ++i)
{
vdescs[i].vertBuffer = nullptr;
vdescs[i].indexBuffer = nullptr;
}
2015-11-21 01:13:06 +00:00
vdescs[0].semantic = boo::VertexSemantic::Position;
vdescs[1].semantic = boo::VertexSemantic::Normal;
size_t e = 2;
for (size_t i=0 ; i<m_colorCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::Color;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<m_uvCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::UV;
vdescs[e].semanticIdx = i;
}
for (size_t i=0 ; i<m_weightCount ; ++i, ++e)
{
2015-11-21 01:13:06 +00:00
vdescs[e].semantic = boo::VertexSemantic::Weight;
vdescs[e].semanticIdx = i;
}
return factory->newVertexFormat(elemCount, vdescs.get());
2015-11-13 02:12:09 +00:00
}
}
}