Jump to content
  • Advertisement
Sign in to follow this  
rumble

OpenGL Integrating different renderers to one app

This topic is 3501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Recently I have had to start integrating two entirely unrelated renderers as selectable plugins to a windows application. Though both of them share similarities, having their respective Matrix, Camera, and Material classes, I am very undecided on how to go about it. For example, RendererA and B each has their Matrix classes. Since the functionalities are similar, ideally I would use say, RendererA's Matrix for rendererB. Or, have both Matrix classes inherit from a common interface. But this is often not practical because so many classes reference the Matrix class. Even if I were to have the drive to refactor them all, the closed source nature of one renderer prevents me. Thus whenever the main app wants to manipulate Matrices, I may have to write separate versions for each renderer ( though called through a polymorphic fashion, hiding the different implementations) Another example. RendererA may have a CameraManipulator class that accepts key/mouse events that drive the underlying Camera class. RendererB would just have a Camera class; I would have to implement an equivalent CameraManipulator class. Now, if I adopt the existing header/interface of RendererA's CameraManipulator in its implementation for RendererB, I would have to deal with the deep inheritance hiearachy inherent to the class, among others. If I don't adopt this header, I would have to invent an independent CameraManipulatorForRendererB, and make a wrapper that hides the different implementations for both manipulators for the main application, just like before. Other problems include: -One renderer prefers to use call backs -One is multi-threaded -One is not open source. -Both have deep inheritance for most classes. -One is a ray tracer; the other a standard rasterizer. I cannot re-use effect files for the ray tracer. -etc. Wonder if others have had to do something similar. Many engines seem to have OpenGL/DirectX/software/Null renderers. But mine seems more high level.

Share this post


Link to post
Share on other sites
Advertisement
Write an interface that receives your own application's copy of matrix implementation and converts it to whatever matrix implementation the renderer uses.

If your renderers are precompiled, then you have to interface with them anyway so it still comes down to writing an interface that handles the many functions of a renderer. So you do not adopt the interface of A or B but write a common one for them, in my opinion this is the best way to go.

Share this post


Link to post
Share on other sites
As Dynx said, you will have to adapt the pre-existing renderers to use a new interface that supports all of the needed functionality; in the literature, this is a design pattern called Adapter.

So, you can do as follows:
-create your interface, IRenderer
-create a class for Renderer A, which implements the IRenderer interface: RendererAAdapter : public IRenderer
  -this class will internally have a reference or pointer to a RendererA object
  -implement all of the interface methods such that they use the internal RendererA object to do the work
-create a class for Renderer A, which implements the IRenderer interface: RendererBAdapter : public IRenderer
  -this class will internally have a reference or pointer to a RendererB object
  -implement all of the interface methods such that they use the internal RendererB object to do the work

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!