Page 1 of 1

Graphics engine architecture

Posted: Tue Mar 24, 2009 11:04 am
by fantastico
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:

Code: Select all

for all active particles:
     renderer.drawQuad(position, color, etc)
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?

Re: Graphics engine architecture

Posted: Tue Mar 24, 2009 1:58 pm
by MarauderIIC
Welcome to the forum.
The "OO" solution would be to call like a renderer.initBlock and renderer.endBlock but all these would do is call glBegin and glEnd. So you could shove glBegin and glEnd straight into your particle fn, but then you're back to your initial problem.
Optimally, what I think I would do is that if your active particles is a list of some sort, you could pass the entire list, either by passing a pointer or by begin/end iterators or whatnot. We do something like this, IIRC.

Re: Graphics engine architecture

Posted: Tue Mar 24, 2009 5:17 pm
by fantastico
Thanks for the ideas and the welcome.

For now I will go with the approach that the renderer knows how a particle system is built. Hopefully there won't be too many of those special cases, in the end I just need the engine for the game I plan to make anyway and not super generic :) I guess in the long run I should give the renderer some methods that take lists of quads, triangles or whatever and make the particle system pass it such a list as you suggested.