• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
betawarz

Should game objects render themselves, or should an object manager render them?

9 posts in this topic

I'm learning how to program games using C++ and D3D11. I've got a basic 3D application that I re-factored from one of the simple tutorials; the one with a single spinning cube. I'm about to write a basic object manager, and pull the code for the cube out into an object class.

 

Now, I've been reading about object managers and game objects, etc. I've read two different takes on it.

 

  1. Each game object is responsible for updating and drawing itself. So each object has its own draw method that the object manager would call.
  2. Game objects only contain the information needed to draw itself; the object manager actually handles the drawing logic using that information.

I'm familiar with the first method, because it's pretty simple to wrap my head around. I've seen it used in quite a few examples and stuff. I'm trying to grok the 2nd way, though. Wouldn't the draw function of the object manager need to iterate over each object, and depending on the type do specific stuff? This would result in a pretty massive draw function with a bunch of if-else branches based on the object type. Is that good? I know it consolidates all the drawing logic into one area, so it's not spread out over many different object classes, so I could see that being a bonus.

 

Just looking for some advice on which method to go with, I guess. Thanks!

0

Share this post


Link to post
Share on other sites

I've been looking to cross this bridge as well. Previously all my projects have had the "object draws itself" method implemented and ive been trying to get my head wrapped around a way to get out of that into something more flexible.

 

I get the basic concepts but when you throw in shaders (which i have little/no experience with) I'm at a loss as how to structure things.

0

Share this post


Link to post
Share on other sites

Create a manager with various rendering buckets, base on materials, shaders etc...  Then whichever bucket the object belong to, add it to that bucket (probably some sort of reference, id or something, as you might have another manager that manage all the objects).  When it time to render, you can render all the objects from different buckets.

1

Share this post


Link to post
Share on other sites
Either method works fine on their own. It depends on how your program NEEDS to do it. My current project absolutely needs a controlled render section where all the objects are rendered in a specific order. I have various distances that have different projection matrix's applied to them and clearing the z-buffer each time to keep objects from overlapping...... I will eventually render other scenes that I imagine will require the "object draw" method like skinned meshes. Use a method that works for your application.
0

Share this post


Link to post
Share on other sites

my "engine" uses different object representations: object are added to the world using a scene graph but that is not used for rendering as it would not be the most efficient way. Rather, after the scene is complete, a "SceneManager" examines the graph and computes the most efficient way to render it. As it has been said, objects are grouped according to materials, geometry used, rendering order and other properties. This scene manager returns a list of "commands" that the rendering loop executs. Commands can be of various types, i.e.: generate a shadow map, activate blending, render objects and so on. 

 

Another thing that I've been doing is separating the object class from the geometry class. In my engine, the object represents the high-level properties of a mesh such as its local position, rotation, etc. (local because the absolute values are obtained according to the scene graph). Whereas the geometry class contains the actual vertex/index buffers. There is only one geometry instance for each unique 3D object in the world.

 

This helps further improve the rendering efficiency. After each object has been grouped into materials then I further group each one of these objects according to the geometry used. Then for each Material/Geometry couple I issuse a "Render Command" to render all the objects that use the same materials and reference geometry. This way there will be only one setVB/IB command per group. This also helps with hardware instancing: if a material supports it, then I just use the list of object instances to compute an instance buffer.

Edited by AvengerDr
1

Share this post


Link to post
Share on other sites

That depends on what "render themselves" means.

If you mean putting OGL/D3D calls right into an object::render method then no, that's a terrible idea.

That makes it too easy to break the graphics when you add a new object into the game.

I do it this way for simple things where performance is a non-issue and I'm in a hurry.

e.g. prototype a replacement for Simulink. (It's 2D drawing the most complex call in the graphics is to turn on anti-aliasing line drawing.)

 

If you mean putting abstracted graphics routines into the object then that's sub-optimal for performance but might be easy to code with.

 

To maximize performance, I believe you need to submitted the graphics to the GPU in batches so that you keep the GPU & CPU both working simultaneously and to maximize performance of the GPU you want to minimize rendering state-changes.

 

Suppose you were making an RTS and 50 of the things on the screen were the same base tank model. You want to change all the states for every tank over and over again. It'd probably be better to draw all the faces & same textures on all the tanks at same time. Then switch to the next texture. Given the small number of pixels the tanks would actually use up, it'd probably be just as fast to draw 50 tanks this way as 2 or 3 the previous way.

 

Some things, like mirror effects, have to be drawn last so you can't even draw then correctly if you attempt to draw them "in line" as you transverse your spatial sorting. You have to queue it for later. Before 'custom shaders' were the norm, we'd write 'shader' based rendering engines. We'd have graphics code that we called a "shader". Different part of the various models would pick which shader drew that part of the model.

I would cull objects with a sphere tree, submit their shaders to the renderer which hash sorted them based on their priority (a constant that is unique and part of the shader). The priorities were carefully picked to minimize renderer state changes and-also guarantee the correct execution order for things like mirrors. With constant custom shaders this would let you draw everything that used the same shader all together, then switch to the next shader. This presumes it is unlikely that you would use the same textures with different shaders; if you're changing the shader I think you're probably going to be changing textures as well. So I sorted by shader first, texture second.

 

When I say "sort" I do no mean an O(n²) sort. I mean something like hash or a priority-heap.

2

Share this post


Link to post
Share on other sites

I second to move rendering outside the objects itself. But an object manager (although a term with interpretation possibilities) is not the correct place either. Following the name "manager", it stands for being responsible for the lifetime of objects and perhaps attributed queries, but not also for rendering; this would violate the one-responsibility principle. However, the main reason is that "drawing" doesn't describe very well what's really going on when it comes to shading.

 

When looking at the problem without having a specific result in mind, one finds that there are various rendering methods that can be used. The keywords are forward shading, deferred shading, NPR, ..., with or without attributes like tiled, clustered, ... and so on. Additionally, special handling of transparency, mirroring, portals, overlays ... is needed. According to the rendering method one or more passes are needed, and image composition may be needed to compose several passes to the end result. Transparency and friends usually introduce a force on the order of processing, perhaps giving more passes to run as well.

 

Optimization like ordering RenderItems along their material (as an example) meant to have knowledge of the rendering method. E.g. a depth-only pass is totally independent on material (letting transparency aside). Instead, an ordering front to back would be an optimization, because of fill rate reduction.

 

Whether one implements an engine with switchable rendering method, or else a game with a single method, is IMHO irrelevant at this point. The task of rendering is a stand-alone thing due to its inherent complexity as well as its self-evident meaning.

 

That said, my advice is to attach the information bits what to render to the objects, and let the graphics sub-system do the rendering in the way (i.e. how) defined by the installed rendering pipeline (meaning the implementation of a rendering method).

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0