View Full Version : Drwaing a object many times

04-16-2017, 02:31 AM

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 ??:

pGLFunc_4_3Core->glBufferData(GL_ARRAY_BUFFER,ui8_NUMBER_OF_VERTICE S*(sizeof(GLfloat)*3+sizeof(GLfloat)*4),NULL,GL_DY NAMIC_DRAW);
// Copy buffer data
pGLFunc_4_3Core->glBufferSubData(GL_ARRAY_BUFFER,0,ui8_NUMBER_OF_VE RTICES*sizeof(GLfloat)*3,positions);
pGLFunc_4_3Core->glBufferSubData(GL_ARRAY_BUFFER,ui8_NUMBER_OF_VERT ICES*sizeof(GLfloat)*3,ui8_NUMBER_OF_VERTICES*size of(GLfloat)*4,color);

or just apply a modeling transformation to the shader:

// Set modeling transformation
Qmat4_ModelingTransformation.translate(QVector3D(0 .5,0.5,0.5));

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

// Draw the buffer

Best regards

Dark Photon
04-16-2017, 11:47 AM
Since you mentioned drawing an object many times on different places... Have you taken a look at Instanced Rendering (https://www.khronos.org/opengl/wiki/Vertex_Rendering#Instancing), 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 (https://www.khronos.org/opengl/wiki/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:

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

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.