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

const vertex handle

parent c526e295
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include "VertexLayout.h" #include "Vertex.h"
namespace dx = DirectX; namespace dx = DirectX;
...@@ -42,6 +42,8 @@ void f() ...@@ -42,6 +42,8 @@ void f()
auto tex = vb[1].Attr<VertexLayout::Texture2D>(); auto tex = vb[1].Attr<VertexLayout::Texture2D>();
vb.Back().Attr<VertexLayout::Position3D>().z = 420.0f; vb.Back().Attr<VertexLayout::Position3D>().z = 420.0f;
pos = vb.Back().Attr<VertexLayout::Position3D>(); pos = vb.Back().Attr<VertexLayout::Position3D>();
const auto& cvb = vb;
pos = cvb[1].Attr<VertexLayout::Position3D>();
} }
App::App() App::App()
......
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
case Float4Color: case Float4Color:
return sizeof( XMFLOAT3 ); return sizeof( XMFLOAT3 );
case BGRAColor: case BGRAColor:
return sizeof( unsigned int ); return sizeof( ::BGRAColor );
} }
assert( "Invalid element type" && false ); assert( "Invalid element type" && false );
return 0u; return 0u;
...@@ -188,7 +188,7 @@ public: ...@@ -188,7 +188,7 @@ public:
assert( "Bad element type" && false ); assert( "Bad element type" && false );
} }
} }
private: protected:
Vertex( char* pData,const VertexLayout& layout ) noexcept(!IS_DEBUG) Vertex( char* pData,const VertexLayout& layout ) noexcept(!IS_DEBUG)
: :
pData( pData ), pData( pData ),
...@@ -196,6 +196,7 @@ private: ...@@ -196,6 +196,7 @@ private:
{ {
assert( pData != nullptr ); assert( pData != nullptr );
} }
private:
template<typename First,typename ...Rest> template<typename First,typename ...Rest>
// enables parameter pack setting of multiple parameters by element index // enables parameter pack setting of multiple parameters by element index
void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noexcept(!IS_DEBUG) void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noexcept(!IS_DEBUG)
...@@ -221,6 +222,22 @@ private: ...@@ -221,6 +222,22 @@ private:
const VertexLayout& layout; 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 class VertexBuffer
{ {
public: public:
...@@ -258,6 +275,18 @@ public: ...@@ -258,6 +275,18 @@ public:
assert( i < Size() ); assert( i < Size() );
return Vertex{ buffer.data() + layout.Size() * i,layout }; 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: private:
std::vector<char> buffer; std::vector<char> buffer;
VertexLayout layout; 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