Browse Source

vertex buffer: added some accessors to inspect a VertexDeclaration/Stream/Buffer

legacy
Benlitz benlitz 11 years ago
parent
commit
9a38b27bd8
2 changed files with 84 additions and 1 deletions
  1. +45
    -0
      src/gpu/vertexbuffer.cpp
  2. +39
    -1
      src/lol/gpu/vertexbuffer.h

+ 45
- 0
src/gpu/vertexbuffer.cpp View File

@@ -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<T>(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<void>(i, VertexStreamBase::Typevoid);

return stream;
}

// //
// The VertexBuffer class // The VertexBuffer class
// ---------------------- // ----------------------
@@ -634,6 +674,11 @@ VertexBuffer::~VertexBuffer()
delete m_data; delete m_data;
} }


size_t VertexBuffer::GetSize()
{
return m_data->m_size;
}

void *VertexBuffer::Lock(size_t offset, size_t size) void *VertexBuffer::Lock(size_t offset, size_t size)
{ {
if (!m_data->m_size) if (!m_data->m_size)


+ 39
- 1
src/lol/gpu/vertexbuffer.h View File

@@ -29,6 +29,8 @@ public:
VertexBuffer(size_t size); VertexBuffer(size_t size);
~VertexBuffer(); ~VertexBuffer();


size_t GetSize();

void *Lock(size_t offset, size_t size); void *Lock(size_t offset, size_t size);
void Unlock(); void Unlock();


@@ -142,7 +144,7 @@ class VertexStreamBase
{ {
friend class VertexDeclaration; friend class VertexDeclaration;


protected:
public:
enum enum
{ {
Typevoid = 0, Typevoid = 0,
@@ -157,6 +159,38 @@ protected:
Typeuint32_t, Typeuvec2, Typeuvec3, Typeuvec4, 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) \ #define LOL_TYPE(T) \
static uint8_t GetType(T *x) { UNUSED(x); return Type##T; } static uint8_t GetType(T *x) { UNUSED(x); return Type##T; }


@@ -266,6 +300,10 @@ public:
ShaderAttrib attr11 = ShaderAttrib(), ShaderAttrib attr11 = ShaderAttrib(),
ShaderAttrib attr12 = ShaderAttrib()); ShaderAttrib attr12 = ShaderAttrib());


int GetStreamCount() const;

VertexStreamBase GetStream(int index) const;

private: private:
void Initialize(); void Initialize();
void AddStream(VertexStreamBase const &); void AddStream(VertexStreamBase const &);


Loading…
Cancel
Save