Commit 2b41752b authored by chili's avatar chili
Browse files

const vertex handle

parent c526e295
......@@ -13,7 +13,7 @@
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "VertexLayout.h"
#include "Vertex.h"
namespace dx = DirectX;
......@@ -42,6 +42,8 @@ void f()
auto tex = vb[1].Attr<VertexLayout::Texture2D>();
vb.Back().Attr<VertexLayout::Position3D>().z = 420.0f;
pos = vb.Back().Attr<VertexLayout::Position3D>();
const auto& cvb = vb;
pos = cvb[1].Attr<VertexLayout::Position3D>();
}
App::App()
......
......@@ -62,7 +62,7 @@ public:
case Float4Color:
return sizeof( XMFLOAT3 );
case BGRAColor:
return sizeof( unsigned int );
return sizeof( ::BGRAColor );
}
assert( "Invalid element type" && false );
return 0u;
......@@ -188,7 +188,7 @@ public:
assert( "Bad element type" && false );
}
}
private:
protected:
Vertex( char* pData,const VertexLayout& layout ) noexcept(!IS_DEBUG)
:
pData( pData ),
......@@ -196,6 +196,7 @@ private:
{
assert( pData != nullptr );
}
private:
template<typename First,typename ...Rest>
// enables parameter pack setting of multiple parameters by element index
void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noexcept(!IS_DEBUG)
......@@ -221,6 +222,22 @@ private:
const VertexLayout& layout;
};
class ConstVertex
{
public:
ConstVertex( const Vertex& v ) noexcept(!IS_DEBUG)
:
vertex( v )
{}
template<VertexLayout::ElementType Type>
const auto& Attr() const noexcept(!IS_DEBUG)
{
return const_cast<Vertex&>(vertex).Attr<Type>();
}
private:
Vertex vertex;
};
class VertexBuffer
{
public:
......@@ -258,6 +275,18 @@ public:
assert( i < Size() );
return Vertex{ buffer.data() + layout.Size() * i,layout };
}
ConstVertex Back() const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer*>(this)->Back();
}
ConstVertex Front() const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer*>(this)->Front();
}
ConstVertex operator[]( size_t i ) const noexcept(!IS_DEBUG)
{
return const_cast<VertexBuffer&>(*this)[i];
}
private:
std::vector<char> buffer;
VertexLayout layout;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment