Graphics engine architecture
Posted: Tue Mar 24, 2009 11:04 am
Hey
I'm currently working on a basic graphics engine and stumbled upon a design problem regarding rendering. I have an interface class called Renderer which can be implemented in OpenGL, DirectX etc. It has some basic methods like renderQuad and renderSphere. So now I wanted to implement a particle system, which I gave a method called draw(Renderer& renderer) that does more or less this:
Now I have the problem that in OpenGL I would have to change the blending type to something else before rendering those quads and it would be a lot more efficient to draw all the quads in a single glBegin/glEnd block without having to translate/rotate etc. for every single quad. This is obviously OpenGL business and has no place in the ParticleSystem method.
Alternatively I could implement a method in the Renderer that takes a ParticleSystem and renders it. In the OpenGL implementation of the Renderer I would simply do it the more efficient way then. But that would mean that the Renderer needs to know about the structure of a particle system and other objects if I wanted to have for example some 3D model.
I'm interested how other programmers solved this kind of issue. Do you have models/objects that know how to draw themself using basic methods of the renderer or API or do you have Renderers that know how to draw models?
I'm currently working on a basic graphics engine and stumbled upon a design problem regarding rendering. I have an interface class called Renderer which can be implemented in OpenGL, DirectX etc. It has some basic methods like renderQuad and renderSphere. So now I wanted to implement a particle system, which I gave a method called draw(Renderer& renderer) that does more or less this:
Code: Select all
for all active particles:
renderer.drawQuad(position, color, etc)
Alternatively I could implement a method in the Renderer that takes a ParticleSystem and renders it. In the OpenGL implementation of the Renderer I would simply do it the more efficient way then. But that would mean that the Renderer needs to know about the structure of a particle system and other objects if I wanted to have for example some 3D model.
I'm interested how other programmers solved this kind of issue. Do you have models/objects that know how to draw themself using basic methods of the renderer or API or do you have Renderers that know how to draw models?