What is instancing, and how can I update my graphics code to do it?

  • What is instancing, and how can I update my graphics code to do it? SirYakalot

    This question directly follows on from this one:

    How can I implement a renderer that can draw many kinds of primitives?

    I have a small amount of drawing code structured in the following way:

    A mesh object can be instantiated with different configurations of vertices and indices in order to form any desired shape. A reference to this mesh is then passed to every gameObject class, this class holds spacial information and a draw method that combines this data with that of the mesh to draw that object with the proper transforms.

    The mesh is simply responsible for holding pointers to the appropriate buffers.

    I was under the impression (wrongly I think) that because I actually only have one object of each type that I'm drawing multiple times, that this WAS instancing. I know this isn't the case.

    What EXACTLY is the difference between what I'm doing and hardware instancing and what changes do I need to make to achieve it?

  • Anything I can say on the subject is said better here: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter03.html, but I'll give you my best shot anyway.

    The idea behind hardware instancing is that you reduce the amount of GPU draw calls by sending each mesh only once, together with a list of transforms. This offloads some of the work done by the CPU to the GPU and reduces amount the communication between CPU and the GPU.

    So the difference between hardware instancing and your approach is that you apply the per-instance transforms on the CPU and that use a draw call for each instance. Vs a draw call per mesh for hardware instancing.

    To implement hardware instancing you would have write a shader to apply the per-instance transforms and pass the relevant data to this shader. Also you need to use a different OpenGl or DirectX function to do the drawing (for OpenGl you would need to use glDrawInstanced instead of glDraw).

    For more details on how to do this exactly, please read the Gpu Gems chapter in the link.

c++ directx graphics-programming directx10
Related questions and answers
  • a transformation matrix to the shader that makes it appear in different places. This worked beautifully. I now have a new problem though: how would I draw many different types of primitives? Here is my code...This is somewhat linked to a question I previously asked concerning the drawing of indexed primitives. My problem was that I was only drawing one cube when I wanted to draw many. I was told... would overwrite the vertex buffer, wouldn't it? Do I use multiple vertex buffers? Do I append the new vertex buffer to the old one and use the appropriate indices to draw them? Can I do either? Both?

  • with different types of objects in the same scene. I was also thinking about making a MeshNode class and then make a Mesh object that contains them, but then I have some conflict on where to store some data... constructing a node object it's done referencing a pool of structure instances to prevent allocation for 2 equal frames. Also the lights are something that I'm not sure on how to handle as I need them to be attached to the node in most cases, even if I allow setting global lights to the scene. @Nicol: Yes that's what I'm trying to figure out. You can see the code doesn't rely on any hardware

  • I'm trying to implement a basic scene graph in DirectX using C++. I am using a left child-right sibling binary tree to do this. I'm having trouble updating each node's world transformation relative to its parent (and its parent's parent etc.). I'm struggling to get it to work recursively, though I can get it to work like this: for(int i = 0; i < NUM_OBJECTS; i++) { // Initialize...; } } toWorldXForm is the object's world transform and toParentXForm is the object's transform relative to the parent. I want to do this using a method within my object class (the code above

  • do this in C++, and I have a hierarchical set-up when it comes to classes. There's a base class and some other classes derive from that. So now I'm onto the part where I want to load up some textures..., and OpenGL renders the whole thing. I think that's the best I can do at explaining. Know that the SceneManager itself contains no OpenGL code, just paths and information that OpenGL needs to know to render the scene. What I'm interested in, what is the best practice to handle this, and how to handle OpenGL texture storage. I understand OpenGL keeps the textures in it's texture memory, and that I

  • I first created a game on the iPhone and I'm now porting it to Android. I wrote most of the code in C++, but when it came to porting it wasn't so easy. The Android's way is to have two threads, one for rendering and one for updating - this due to some devices blocking when updating the hardware - while the iPhone's way is to have one thread to do it all. My problem is that I am coming from... thing on Android, but I have noticed on game ports like Quake, don't do this - as far as I can tell. What I want is someone to explain how a game like Quake can transition from the menu to the game

  • Collision Resolution ultifinitus

    ," on the stack. What's I think is happening is the object's collision system checks and resolves for collisions based on creation time, so If I check one axis, then the other, the object will "sink... with a working algorithm, but I'd rather not =). So what in the heck do you think I should do? How could I change my collision resolution system to fix this? Here's the program (temporary link, not sure how...Hey all, I'm making a simple side-scrolling game, and I would appreciate some input! My collision detection system is a simple bounding box detection, so it's really easy to implement. However my

  • I'm trying to map a brick texture on the edge of a fountain and I'm using gluDisk for that. How can I make the right coordinates for the disk? My code looks like this and I have only found a function that takes the texture along with the camera. I want the cubic texture to be alongside of the fountain, but gluDisk does a linear mapping. How do I get a circular mapping? void Fountain::Draw...(); // push 3 glTranslatef(0,0,height); // spherical texture generation // this piece of code doesn't work as I intended glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T

  • Like many beginner graphics programmers I followed a tutorial which showed me how to set up buffer descriptions and fill out the vertex buffer etc... - the steps involved in drawing a simple indexed cube on the screen. There is a leap however when it comes to drawing more than one of these cubes. My code below is the original cube drawing code, if called more than once, each call overwrites the vertex buffer and only one object is drawn - the last one. So what are the options for drawing many of these cubes? Cube::Cube(D3DXCOLOR colour, D3DXVECTOR3 min, D3DXVECTOR3 max) { // create eight

  • I'm making a GUI API (in C++) for games which uses Allegro 5 as a backend. I looked at how GuiChan works and noticed that they intend for the user to override the paint event and do all the drawing yourself. Since I felt that in general, there's a decent standard to how widgets behave, I have a static theme class in each widget class (static ButtonTheme buttonTheme; etc) and the parameters set... has corresponding bitmaps. I also have bitmaps for focused and disabled. The user can always choose to override the paint event and do it from scratch. Is this a good idea or a terrible one to use

Data information