I am writing graphics engine for educational pursoses and have some problems.
I need to have ability to use different vertex formats (for example position+normal+uv or position+normal+uv+bones+weights). I have different structs for these formats and have a class HardwareBuffer that stores OpenGL vertex and index buffers. The problem is to give this class the ability to work with different types of vertices. There are a way to make this class template and use like this:
HardwareBuffer<VertexPosNormUV> buffer; buffer.addVertex(VertexPosNormUV(vector3(1, 1, 1), vector3(1, 0, 0), vector2(1, 0)));
But in my engine there is an interface IRenderer that have virtual method
drawDataFromHardwaveBuffer. Also there is a class OpenGLRenderer that is inherited from it. And now I can't pass my hardware buffer object to this method because there isn't a way to use template virtual methods.
Renderer renderer = createRenderer(GraphicsDriver::OpenGL3); renderer->drawDataFromHardwaveBuffer(buffer); // can't make this method template
I can write functions for every type of vertex but this is not a solution.
How can I solve the problem?