Looking for advice to construct class structure for efficiency

Started by
2 comments, last by #Include Graphics 9 years, 8 months ago

So I have a base class of "actors" that will be drawn to the screen,which includes basic stuff like vertex,index buffers,some data types,information about geometry(index vertex count etc.). So here's my question:

Should I pass ID3D11Device* and ID3D11DeviceContext* to classes derived from base class and simply let this classes handle all rendering by themselves in a method such as virtual void Render( ID3D11DeviceContext* ),

or

Should I create a renderer class which takes this derived classes and their data and implement their rendering logic?

or better suggestions? I am building a huge project and I have never been worried about efficiency so I need your help.

Advertisement

This isn’t a matter of efficiency, it’s about modular design.

A renderer doesn’t know what a model/actor is, so your second idea simply doesn’t make sense.

Among your proposals, the first is the correct choice.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I don't like either of those options -- a model is too high level to know about a ID3D11DeviceContext, and the Device is too low-level to know about complex things like models.

I would choose option #2, but instead of the Device knowing how to draw "models", break that down into it's simplest parts -- vertex streams, a stream layout, a shader program, lists of texture bindings, lists of cbuffer bindings, and a "DrawPrimitives" operation. I'd have the device know how to draw something use all of those objects internally, and then I'd have the "Model" class have these as members (i.e. be composed out of these simpler objects).

I am with L. Spiro here, the renderer should not have to know anything about how a model will be rendered, instead he will know about how are all the stuff in the world rendered:

1. Order of the models and the type being rendered ( fe: First the non alpha. then alpha models )

2. which effects are being applied and in which order.

3. Post effects applied

It is like a mix of multiplexor, manager and organizer system.

Hope it helps.

This topic is closed to new replies.

Advertisement