Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Short answer is that hardware instancing is where one set of render data is prepared (like you have) and then a list of positions is uploaded and then they're all drawn at once (not like you have) without further intervention. You may or may not get any speedup from this depending on how many objects you're drawing, be sure to profile. –  Patrick Hughes Dec 3 '11 at 11:45
    
@PatrickHughes OOOOHHH!! so you UPLOAD the transforms. I thought you just cycled through them in a loop. This is making much more sense now. –  Asher Einhorn Jan 4 '12 at 15:12
add comment

1 Answer

up vote 9 down vote accepted

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.

share|improve this answer
    
What is the minimum DX and OGL requirement for this feature? –  iamcreasy Dec 3 '11 at 12:52
1  
OpenGl supports instancing from 3.0 (en.wikipedia.org/wiki/OpenGL). DirectX I think from version 9. –  thomasD Dec 3 '11 at 13:28
    
The minimum for DirectX 9 is shader model 2.0, specifically vs_2_0 for vertex shaders where instancing takes place. –  ChrisC Dec 3 '11 at 18:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.