What's the point of having a single render device?,
Members - Reputation: 124
Posted 25 May 2011 - 07:00 AM
What's the point of having a single render device, when so many things need different ways of handling?
I'm trying to implement my own rendering system, really basic, Dx9 and all that, and from overhauling some of my old code, I've found out that out that the more I keep responsibilities of objects/functions separate, the easier I can maintain and extend stuff, pretty much what people recommend anyways.
Avoid monolithic do-it-all god classes, right? Yes.
Isn't a render device pretty much monolithic, that way if one wants it to be actually substantial, and not just some sort of delegate thing that shoves data between specialized components?
Or is that the point of one, after all?
So, isn't it better to have things like "GuiWindowRenderer", "FontRenderer", "3dRenderer" that could maybe act as plugins, or well, components for a big class?
Or would it be better to completely split those things and use them on their own, when one wants to render a GuiWindow instead of an actual ingame object?
The only need for a RenderDevice I can see that way would be a common framework like thing, that access backbuffers, and flips them and all that, but in that case the renderdevice is not the main hero, but the shadow sidekick.
So, what are the "rendering system" blocks one can see in engine design diagrams really?
I'm aware that that question is kind of a bad one, since a monolithic, rigid spaghetti-like monster class could do it all, and still pass as a rendering system, but let's say we don't want it that way...
Instead...would you make the components the stars, and have the device be some sort of low level widget?
Or have the components act more like scripts, or plug ins something that wants to be rendered can use?
Like with 2D GUI rendering, if it were a script, it could set the device to use an orthogonal view, and then feed it a stream of vertices, and material data.
Then, when it's time to render some scene object, a different view would be used, and so on.
So in short, I'm having trouble designing a sort of layout plan for responsibilities, what should depend on what, etc.
Any resources that focus on that particular topic?
(Again I apologize for vagueness, please act as if this topic never happened if it's too vague for you. Don't want people to feel like they put effort into a reply in vain)
Moderators - Reputation: 48699
Posted 25 May 2011 - 07:15 AM
StateGroups => set of RenderStates.
States => sub-classed into RenderStates (blend mode, shader constants, shader programs, stream sources, etc) and DrawCalls.
CommandList => sequence of States.
RenderInstance => a DrawCall paired with a stack of StateGroups, and a sort-key.
RenderGroup => a set of RenderInstances.
High-level rendering modules are then built on top of these classes (e.g. GuiRenderer, LevelRenderer, etc).
High-level 'Drawables' can exist in many different formats, as long as they can be converted into a RenderInstance (i.e. are composed of DrawCalls and StateGroups).
These high-level modules then collect a list of 'Drawables' (each of which has a DrawCall and stack of StateGroups), and gives them to a function along with a default/global StateGroup (the default/global group is for states like the viewport/render-target that apply to every drawable in the list), which produces a RenderGroup. This RenderGroup can then be handed to the low-level renderer.
The low-level module can sort the submitted RenderGroups and then convert them into CommandLists, which are then executed by the device.
N.B. there's no global states in this design. One thing can't "set a ortho matrix" by itself -- that "set" command has to be part of a state-group, which is attached to a 'Drawable' somehow.
Members - Reputation: 124
Posted 25 May 2011 - 07:54 AM
Thank you for your reply, I might adapt my system to it as well, since it has some vague similarities already.
My very small and humble system so far uses commands as well, but it's the meshes that have them, and the meshes are being filled by the two simple components so far, window rendering, and static mesh rendering.
It goes like this:
My render device can only do one thing when it comes to rendering: clear, accept a list of meshes, flip.
Each mesh has vertex and index data, and a material.
A material has resources (or handles to them, the actual things are in a libary that get filled at load time) like vertex and pixelshaders, a vertex declaration, a constant table that is linked to variable emitters, info about which datastreams of the mesh are in use, and so on.
To actually produce data, a system like the window renderer takes a mesh, fills it with mesh data according to the states of the windows using it, then sets commands like "Clear the Zbuffer", "Change View to Orthogonal" for the material script, and sends the mesh on it's merry way.
It's a bit awkward when it comes to configuring it all, but it works.
I'm not sure if this 'passthrough' way of doing it is a good idea.
In essence, that window rendering system is just a mutator, it doesn't have much state info itself...does that fall under that gypsy wagon/poltergeist thing?
But again, thanks for the input, that looks a lot more structured than mine...
Hm, so no global state like that?
Interesting. Makes sense though, smaller lego blocks that can form many things, including a duplo block, like the OrthoMatrix thing are better than using duplos only.