I am looking for a nice way to render mesh objects with different vertex layouts wihtout large effort (e.g. defining a renderer class for each vertex layout). You can see some examples of different vertex formats below.
enum EVertexFormat
{
VERTEX_FORMAT_UNDEFINED = -1,
VERTEX_FORMAT_P1 = 0,
VERTEX_FORMAT_P1N1,
VERTEX_FORMAT_P1N1UV,
VERTEX_FORMAT_P1N1C1,
VERTEX_FORMAT_P1N1UVC1,
};
// the simplest possible vertex -- position only
struct SVertexP1
{
math::Vector3D m_position; // position of the vertex
};
struct SVertexP1N1
{
math::Vector3D m_position; // position of the vertex
math::Vector3D m_normal; // normal of the vertex
};
// a typical vertex format with position, vertex normal
// and one set of texture coordinates
struct SVertexP1N1UV
{
math::Vector3D m_position; // position of the vertex
math::Vector3D m_normal; // normal of the vertex
math::Vector2D m_uv; // (u,v) texture coordinate
};
struct SVertexP1N1C1
{
math::Vector3D m_position; // position of the vertex
math::Vector3D m_normal; // normal of the vertex
uint32_t m_color_u32; // color of the vertex
};
struct SVertexP1N1UVC1
{
math::Vector3D m_position; // position of the vertex
math::Vector3D m_normal; // normal of the vertex
math::Vector2D m_uv; // (u,v) texture coordinate
uint32_t m_color_u32; // color of the vertex
};
The background is, that I want to render different objects. Some of them are primitives (e.g. planes, spheres) which do not own texture coordinates or normals. On the other hand I want to render more complex objects which have normals, texture coordinates etc. Is there a smart way or design to avoid programming multiple renderer classes and instead using a single renderer class? I am aware, that this will also affect shaders.