title: Draw a bunch of elements generated by CUDA/OpenCL?
body: <p>I'm new to graphics programming, and need to add on a rendering backend for a demo we're creating. I'm hoping you guys can point me in the right direction.</p>
  
  <p><strong>Short version</strong>: Is there any way to send OpenGL an array of data for distinct elements, without having to issue a draw command for each element distinctly?</p>
  
  <p><strong>Long version</strong>: We have a CUDA program (will eventually be OpenCL) which calculates a bunch of data for a bunch of objects for us. We then need to render these objects using, e.g., OpenGL.</p>
  
  <p>The CUDA kernel can generate our vertices, and using OpenGL interop, it can shove these in an OpenGL VBO and not have to transfer the data back to host device memory. But the problem is we have a bunch (upwards of a million is our goal) distinct objects. It seems like our best bet here is allocating one VBO and putting every object's vertices into it. Then we can call glDrawArrays with offsets and lengths of each element inside that VBO.</p>
  
  <p><em>However,</em> each object may have a variable number of vertices (though the total vertices in the scene can be bounded.) I'd like to avoid having to transfer a list of start indices and lengths from CUDA -> CPU every frame, especially given that these draw commands are going right back to the GPU. </p>
  
  <p>Is there any way to pack a buffer with data such that we can issue only one call to OpenGL to render the buffer, and it can render a number of distinct elements from that buffer?</p>
  
  <p>(Hopefully I've also given enough info to avoid a XY problem here.)</p>