#pragma once namespace graphics { template struct PosField { T * m_x; unsigned short m_xStride; T * m_y; unsigned short m_yStride; T * m_z; unsigned short m_zStride; T * m_w; unsigned short m_wStride; PosField() : m_x(0), m_xStride(0), m_y(0), m_yStride(0), m_z(0), m_zStride(0), m_w(0), m_wStride(0) {} template void copyFrom(PosField const & u) { if (m_x && u.m_x) *m_x = static_cast(*u.m_x); if (m_y && u.m_y) *m_y = static_cast(*u.m_y); if (m_z && u.m_z) *m_z = static_cast(*u.m_z); if (m_w && u.m_w) *m_w = static_cast(*u.m_w); } void advance(unsigned cnt) { if (m_x) m_x = reinterpret_cast(reinterpret_cast(m_x) + m_xStride * cnt); if (m_y) m_y = reinterpret_cast(reinterpret_cast(m_y) + m_yStride * cnt); if (m_z) m_z = reinterpret_cast(reinterpret_cast(m_z) + m_zStride * cnt); if (m_w) m_w = reinterpret_cast(reinterpret_cast(m_w) + m_wStride * cnt); } }; template struct TexField { T * m_u; unsigned short m_uStride; T * m_v; unsigned short m_vStride; TexField() : m_u(0), m_uStride(0), m_v(0), m_vStride(0) {} template void copyFrom(TexField const & u) { if (m_u && u.m_u) *m_u = static_cast(*u.m_u); if (m_v && u.m_v) *m_v = static_cast(*u.m_v); } void advance(unsigned cnt) { if (m_u) m_u = reinterpret_cast(reinterpret_cast(m_u) + m_uStride * cnt); if (m_v) m_v = reinterpret_cast(reinterpret_cast(m_v) + m_vStride * cnt); } }; struct VertexStream { PosField m_fPos; PosField m_dPos; PosField m_fNormal; PosField m_dNormal; TexField m_fTex; TexField m_dTex; /// should be inline for max performance inline void copyVertex(VertexStream * dstVS) { m_fPos.copyFrom(dstVS->m_fPos); m_fPos.copyFrom(dstVS->m_dPos); m_dPos.copyFrom(dstVS->m_fPos); m_dPos.copyFrom(dstVS->m_dPos); m_fNormal.copyFrom(dstVS->m_fNormal); m_fNormal.copyFrom(dstVS->m_dNormal); m_dNormal.copyFrom(dstVS->m_fNormal); m_dNormal.copyFrom(dstVS->m_dNormal); m_fTex.copyFrom(dstVS->m_fTex); m_fTex.copyFrom(dstVS->m_dTex); m_dTex.copyFrom(dstVS->m_fTex); m_dTex.copyFrom(dstVS->m_dTex); } /// should be inline for max performance inline void advanceVertex(unsigned cnt) { m_fPos.advance(cnt); m_dPos.advance(cnt); m_fNormal.advance(cnt); m_dNormal.advance(cnt); m_fTex.advance(cnt); m_dTex.advance(cnt); } }; }