Recommended Posts

These might seem like pretty stupid questions so forgive me but i've been searching the web and i cant find any information regarding this, all the tutorials i've found seem to be rehashes of wendy jone's "beginning dx10 programming" which itself is just a rehash of the sdk examples.
first question is regarding effects:
since the removal of the fixed function pipeline, you have to define each stage yourself. thats fine i get this, what I'm wondering, must each object (model) in my scene have its own effect (loaded from a file) which it uses in its draw method or should i have an effect pool i load once at the start and then just re-assign the matrix pointers to the effect variables for each object before drawing?
ie. call something like:
localObjectMatrix = pGlobalEffect->getVariableByName("NAME")->AsMatrix();
every time i draw an object.
Second question is a bit general:
should i create a base object class with a draw technique and its own world matrix and then create each other object class (tree, wall, ball, etc) as a child class. This will allow me to have a long list of object to draw in the render loop.
Any problem with this approach, any better methods?
Sorry for these stupid questions, i've ordered several books regarding 3d engine structure but it'll be several days before they arrive.
thanks in advance!

0

Share this post

Link to post

Share on other sites

Original post by ColdonI'm wondering, must each object (model) in my scene have its own effect (loaded from a file) which it uses in its draw method or should i have an effect pool i load once at the start and then just re-assign the matrix pointers to the effect variables for each object before drawing?

Have one effect used by multiple objects in the way you describe. There is no need to have a copy of an effect for each and every object - for exactly the same reasons you wouldn't want a duplicate of the same texture for each object using it.

Typically you'll have code that sets up the current effect/technique and then just updates the appropriate constants prior to each draw call.

Quote:

should i create a base object class with a draw technique and its own world matrix and then create each other object class (tree, wall, ball, etc) as a child class. This will allow me to have a long list of object to draw in the render loop.

You've stumbled upon one of the fundamental design programs for a graphics engine, and unfortunately there is no single correct answer.

In a nutshell you can either have objects that know how to draw themselves or objects that can describe how someone else can draw them. By analogy you'd have the former being given a canvas and some coloured pens and drawing a picture all on its own, and the latter would tell an artist what to draw but wouldn't ever actually pick up the pens itself.

Having objects draw themselves initially seems like a good idea, but it quickly falls down in my opinion. You end up dispersing Direct3D code all over the place (a bit of a maintenance and extensibility nightmare) and you have to rely on each object being well behaved with the device. If you have 10 objects rendering in sequence you want to ensure that one of those objects doesn't mess things up so as to affect how later objects are drawn (e.g. leaking state).

Having the classic 'manager' class works nicely in that it encapsulates all your D3D code in one place (great for maintenance and if you want to later upgrade your API or add new features) and can ensure that a client object can't mangle the device state for other objects - it maintains correctness. All that said, it has the distinct problem that your objects need to describe themselves in a way that the manager understands, which immediately limits them to whatever capabilities or techniques the manager object exposes.

That aside, a good clean inheritance heirarchy is a good thing provided it helps you represent and solve your problem in an appropriate way. Don't shy away from it for technical reasons.

hthJack

0

Share this post

Link to post

Share on other sites

the manager approach seems the best solution, but once again i dont really have any idea where i can start looking for example structure. I'm not worried about the technical complexity but rather for the best approach.

I don't feel like trying to re-invent the wheel nor do i have the time available to mess around with different approaches.