2016-03-04 23:02:44 +00:00
|
|
|
#include "hecl/HMDLMeta.hpp"
|
|
|
|
#include "hecl/Runtime.hpp"
|
|
|
|
#include <athena/MemoryReader.hpp>
|
2015-11-13 02:12:09 +00:00
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
namespace hecl
|
2015-11-13 02:12:09 +00:00
|
|
|
{
|
|
|
|
namespace Runtime
|
|
|
|
{
|
2016-03-04 23:02:44 +00:00
|
|
|
static logvisor::Module Log("HMDL");
|
2015-11-13 02:12:09 +00:00
|
|
|
|
2016-03-30 19:15:08 +00:00
|
|
|
HMDLData::HMDLData(boo::IGraphicsDataFactory::Context& ctx,
|
2015-11-14 02:26:06 +00:00
|
|
|
const void* metaData, const void* vbo, const void* ibo)
|
2015-11-13 02:12:09 +00:00
|
|
|
{
|
2015-11-14 02:26:06 +00:00
|
|
|
HMDLMeta meta;
|
|
|
|
{
|
2016-03-04 23:02:44 +00:00
|
|
|
athena::io::MemoryReader r((atUint8*)metaData, HECL_HMDL_META_SZ);
|
2015-11-14 02:26:06 +00:00
|
|
|
meta.read(r);
|
|
|
|
}
|
2015-11-14 23:40:32 +00:00
|
|
|
if (meta.magic != 'TACO')
|
2016-03-04 23:02:44 +00:00
|
|
|
Log.report(logvisor::Fatal, "invalid HMDL magic");
|
2015-11-14 02:26:06 +00:00
|
|
|
|
2016-03-30 19:15:08 +00:00
|
|
|
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vbo, meta.vertStride, meta.vertCount);
|
|
|
|
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, ibo, 4, meta.indexCount);
|
2015-11-14 02:26:06 +00:00
|
|
|
|
2016-03-30 19:15:08 +00:00
|
|
|
if (ctx.bindingNeedsVertexFormat())
|
|
|
|
m_vtxFmt = NewVertexFormat(ctx, meta, m_vbo, m_ibo);
|
2015-11-18 06:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For binding constructors that require vertex format up front (GLSL) */
|
2016-03-30 19:15:08 +00:00
|
|
|
boo::IVertexFormat* HMDLData::NewVertexFormat(boo::IGraphicsDataFactory::Context& ctx, const HMDLMeta& meta,
|
2015-11-18 06:16:08 +00:00
|
|
|
boo::IGraphicsBuffer* vbo, boo::IGraphicsBuffer* ibo)
|
|
|
|
{
|
2015-11-14 02:26:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-11-18 06:16:08 +00:00
|
|
|
vdescs[i].vertBuffer = vbo;
|
|
|
|
vdescs[i].indexBuffer = ibo;
|
2015-11-14 02:26:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 00:22:55 +00:00
|
|
|
vdescs[0].semantic = boo::VertexSemantic::Position3;
|
|
|
|
vdescs[1].semantic = boo::VertexSemantic::Normal3;
|
2015-11-14 02:26:06 +00:00
|
|
|
size_t e = 2;
|
|
|
|
|
|
|
|
for (size_t i=0 ; i<meta.colorCount ; ++i, ++e)
|
|
|
|
{
|
2015-11-26 00:22:55 +00:00
|
|
|
vdescs[e].semantic = boo::VertexSemantic::ColorUNorm;
|
2015-11-14 02:26:06 +00:00
|
|
|
vdescs[e].semanticIdx = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i=0 ; i<meta.uvCount ; ++i, ++e)
|
|
|
|
{
|
2015-11-26 00:22:55 +00:00
|
|
|
vdescs[e].semantic = boo::VertexSemantic::UV2;
|
2015-11-14 02:26:06 +00:00
|
|
|
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;
|
2015-11-14 02:26:06 +00:00
|
|
|
vdescs[e].semanticIdx = i;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:15:08 +00:00
|
|
|
return ctx.newVertexFormat(elemCount, vdescs.get());
|
2015-11-18 06:16:08 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 02:33:29 +00:00
|
|
|
/* For shader constructors that require vertex format up-front (HLSL/Metal/Vulkan) */
|
2016-03-30 19:15:08 +00:00
|
|
|
boo::IVertexFormat* ShaderTag::newVertexFormat(boo::IGraphicsDataFactory::Context& ctx) const
|
2015-11-18 06:16:08 +00:00
|
|
|
{
|
|
|
|
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-26 00:22:55 +00:00
|
|
|
vdescs[0].semantic = boo::VertexSemantic::Position3;
|
|
|
|
vdescs[1].semantic = boo::VertexSemantic::Normal3;
|
2015-11-18 06:16:08 +00:00
|
|
|
size_t e = 2;
|
|
|
|
|
|
|
|
for (size_t i=0 ; i<m_colorCount ; ++i, ++e)
|
|
|
|
{
|
2015-11-26 00:22:55 +00:00
|
|
|
vdescs[e].semantic = boo::VertexSemantic::ColorUNorm;
|
2015-11-18 06:16:08 +00:00
|
|
|
vdescs[e].semanticIdx = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i=0 ; i<m_uvCount ; ++i, ++e)
|
|
|
|
{
|
2015-11-26 00:22:55 +00:00
|
|
|
vdescs[e].semantic = boo::VertexSemantic::UV2;
|
2015-11-18 06:16:08 +00:00
|
|
|
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;
|
2015-11-18 06:16:08 +00:00
|
|
|
vdescs[e].semanticIdx = i;
|
|
|
|
}
|
|
|
|
|
2016-03-30 19:15:08 +00:00
|
|
|
return ctx.newVertexFormat(elemCount, vdescs.get());
|
2015-11-13 02:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|