diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index af243f9a..57ba31b6 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -598,6 +598,46 @@ void VertexDeclaration::AddStream(VertexStreamBase const &s) } } +int VertexDeclaration::GetStreamCount() const +{ + return m_count ? m_streams[m_count - 1].index + 1 : 0; +} + +VertexStreamBase VertexDeclaration::GetStream(int index) const +{ + VertexStreamBase stream; + int n = 0; + + for (int i = 0; i < m_count; ++i) + { + if (m_streams[i].index != index) + continue; + + switch (m_streams[i].stream_type) + { +#define LOL_TYPE(T) \ + case VertexStreamBase::Type##T: stream.AddStream(n++, m_streams[i].usage); break; + + LOL_TYPE(void) + LOL_TYPE(half) LOL_TYPE(f16vec2) LOL_TYPE(f16vec3) LOL_TYPE(f16vec4) + LOL_TYPE(float) LOL_TYPE(vec2) LOL_TYPE(vec3) LOL_TYPE(vec4) + LOL_TYPE(double) LOL_TYPE(dvec2) LOL_TYPE(dvec3) LOL_TYPE(dvec4) + LOL_TYPE(int8_t) LOL_TYPE(i8vec2) LOL_TYPE(i8vec3) LOL_TYPE(i8vec4) + LOL_TYPE(uint8_t) LOL_TYPE(u8vec2) LOL_TYPE(u8vec3) LOL_TYPE(u8vec4) + LOL_TYPE(int16_t) LOL_TYPE(i16vec2) LOL_TYPE(i16vec3) LOL_TYPE(i16vec4) + LOL_TYPE(uint16_t) LOL_TYPE(u16vec2) LOL_TYPE(u16vec3) LOL_TYPE(u16vec4) + LOL_TYPE(int32_t) LOL_TYPE(ivec2) LOL_TYPE(ivec3) LOL_TYPE(ivec4) + LOL_TYPE(uint32_t) LOL_TYPE(uvec2) LOL_TYPE(uvec3) LOL_TYPE(uvec4) +#undef LOL_TYPE + } + } + + for (int i = m_count; i < 12; ++i) + stream.AddStream(i, VertexStreamBase::Typevoid); + + return stream; +} + // // The VertexBuffer class // ---------------------- @@ -634,6 +674,11 @@ VertexBuffer::~VertexBuffer() delete m_data; } +size_t VertexBuffer::GetSize() +{ + return m_data->m_size; +} + void *VertexBuffer::Lock(size_t offset, size_t size) { if (!m_data->m_size) diff --git a/src/lol/gpu/vertexbuffer.h b/src/lol/gpu/vertexbuffer.h index 0e8dd26e..7d73f391 100644 --- a/src/lol/gpu/vertexbuffer.h +++ b/src/lol/gpu/vertexbuffer.h @@ -29,6 +29,8 @@ public: VertexBuffer(size_t size); ~VertexBuffer(); + size_t GetSize(); + void *Lock(size_t offset, size_t size); void Unlock(); @@ -142,7 +144,7 @@ class VertexStreamBase { friend class VertexDeclaration; -protected: +public: enum { Typevoid = 0, @@ -157,6 +159,38 @@ protected: Typeuint32_t, Typeuvec2, Typeuvec3, Typeuvec4, }; + int GetSize() const + { + int size = 0, i = 0; + while (m_streams[i].size) + size += m_streams[i++].size; + return size; + } + + int GetStreamCount() const + { + int i = 0; + while (m_streams[i].size) ++i; + return i; + } + + VertexUsage GetUsage(int index) const + { + return m_streams[index].usage; + } + + uint8_t GetType(int index) const + { + return m_streams[index].stream_type; + } + + uint8_t GetSize(int index) const + { + return m_streams[index].size; + } + +protected: + #define LOL_TYPE(T) \ static uint8_t GetType(T *x) { UNUSED(x); return Type##T; } @@ -266,6 +300,10 @@ public: ShaderAttrib attr11 = ShaderAttrib(), ShaderAttrib attr12 = ShaderAttrib()); + int GetStreamCount() const; + + VertexStreamBase GetStream(int index) const; + private: void Initialize(); void AddStream(VertexStreamBase const &);