Graphics engine architecture

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
fantastico
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Fri Mar 20, 2009 4:37 am
Location: Germany

Graphics engine architecture

Post 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?
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Graphics engine architecture

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
fantastico
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Fri Mar 20, 2009 4:37 am
Location: Germany

Re: Graphics engine architecture

Post 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.
Post Reply