I read about creating graphics abstraction layers to make it convenient to switch between graphics platforms. Unfortunately, I could not find many details on this. Is this abstraction functionally achievable with something like this?
void pushMatrix(){ if (directx){ // do directx function }else if (opengl){ // do opengl function } }
How it works? Is there a better way? Can someone point me to some examples of things that this or more example code does?
It is usually done in such a way as to have an interface with a “universal” visualization tool:
class RendererInterface{ virtual DrawMesh() = 0; virtual SwapBuffers() = 0; /// etc }
with one implementation for each lib:
class OpenGLRenderer : public RendererInterface{ virtual DrawMesh(){... } .... }
But the concept is the same as Alexander’s answer.
, . API, , . , GDI , , .
, , HDC. .
, API, . API (DirectX OpenGL) , , .
, . .
, OpenGL , A, B, - , DX , func B, func A. , - :
void functionA(...) { if (OpenGL) { glFuncA(); } else { //store parameters } } void functionB(...) { if (OpenGL) { glFuncB(); } else { dxFuncB(); dxFuncA( saved params ); } }
, . API , .
. , "" . "renderer", OpenGL Direct3D.
- , Ogre3d.
mhutch 100%. , , , , , .
API , , if (this_platform) { do_this(); } else { do_that(); }, .
if (this_platform) { do_this(); } else { do_that(); }
- , , HOW. , , , (IMHO) API, , , , .
, , , . , , - ( , ..) . , instancing, , API- ", " " " .