Let's say I want to have an OpenGL program that runs on a platform that supports the latest OpenGL version (4.6), but also on a platform that supports a very low OpenGL version (1.5, which does not have shaders).
To create such a program, I would need at least two code paths - one that uses functions from the OpenGL 4.6, and one that uses functions from the 1.5.
What I would like to end up with is one program (one binary), which based on the system requirements ends up using the first or the second code path. By code paths, I actually mean different classes that would do the rendering using a certain set of OpenGL functions, so something like this:
// Rendering interface.
class Renderer{
...
void init(){
// Load OpenGL functions
glewInit();
}
virtual void renderSphere() = 0;
...
};
// Rendering implementation that uses opengl 4.6
class RendererProgrammablePipeline: Renderer{
...
void renderSphere(){ /* use shaders to render a sphere */ }
...
};
// Rendering implementation that uses opengl 1.5
class RendererFixedFunctionPipeline: Renderer{
...
void renderSphere(){ /* use display lists to render a sphere */ }
...
};
Then during runtime, after an OpenGL context is created, I would ask what's the current OpenGL version and pick the Renderer implementation.
My question is, I am missing something (big) here with the approach described?
According to this question, it seems that loading OpenGL functions at runtime might not be as simple as calling glewInit(), but it's also posted 10 years ago.
Thanks in advance for any comments and suggestions.