Drwaing a object many times


i want to draw a object many times on different places.

Is it better to do the movement and Transformation with GL_DYNAMIC_DRAW and changing the positins Array any time ??:

        // Copy buffer data

or just apply a modeling transformation to the shader:

// Set modeling transformation

    // Set modeling transformation to shader
    pGLFunc_4_3Core->glUniformMatrix4fv(gli_ModelingTransformation_NameId,1,GL_FALSE,(GLfloat *)Qmat4_ModelingTransformation.data());

    // Draw the buffer

Best regards

Since you mentioned drawing an object many times on different places… Have you taken a look at Instanced Rendering, either by using an Instanced draw call, or by using vertex attribute divisors? For best performance, that’s going to be your best bet. This will likely to be much, much faster than updating and drawing each instance one at a time separately using the techniques you’re asking about – particularly if your number of instances is large (i.e. you’re drawing it many times).

That aside, as far as the specific techniques you suggested…

In my experience, normal uniform sets tend to be a fast and efficient way to set small amounts of dynamic uniform data. As for submitting dynamic vertex attribute data, client arrays are pretty fast for data that’s generated on the CPU, or VBOs for vertex attributes that are generated on the GPU.

If you want to exceed the performance of client arrays for dynamic vertex attribute data generated on the CPU, read up on Buffer Object Streaming methods – in particular streaming into PERSISTENT/COHERENT buffers, or as a fallback streaming into buffer objects with UNSYCHRONIZED writes.

What you don’t want to do is find yourself doing something like this:

[li] update buffer object A (with implicit synchronization; i.e. without Map UNSYNCHRONIZED, PERSISTENT/COHERENT, or buffer respecification), [/li][li] draw from buffer object A, [/li][li] update buffer object A again (with implicit sync), [/li][li] draw from buffer object A, [/li][li] … [/li][/ul]

Rinse/repeat. If you were writing the underlying GL driver, just think about what you’d have to do in this case to pipeline these buffer updates to the GPU for later execution, and you can see pretty easily that this is unlikely to perform well. It’s bad on desktop and it’s positively horrible on mobile GPUs.