Saturday 15 February 2014

c++ - OpenGL render multiple objects using single VBO and updata object's matrices using another VBO -


Therefore, I do not need a way to submit multiple objects using a drop call (for example not) actually , I know how to do this, just enter data in one vbo / ibo and render using glDrawElements.

The question is: What is the method of updating uniformly using gluinform ... without setting uniform form data for each single object?

Do I include MVP matrix in data of a single dozen objects, bind it and render using a single call call? I tried to use UBO, but this is not necessary for me.

In order to present the examples, we move the only data including the matrix, in another VBO, and using the glVertexAttribDivisor to set up a specialty separator, but it only works example.

Is there a way to do that I want in OpenGL? If not, what can I do to overcome overheads to set up uniform data for dozens of objects?

For example:

  {// VBO glenbuffers (1, & Amp; vbo); GlBindBuffer (vbo); GlBufferData (..., data_size); // Setup buffer for (int i = 0; i & lt; object_num; i ++) glubber data (... offset, size, and (object [ii])); // There is only one for IBO ......... // While setting up some buffer, which will store all the items for every object ......... glDrawElements (...) ; }  

Thank you in advance for helping.

OpenLL is ok with the requirement of 4.3 or more, I believe that you get it < Using a code> glMultiDrawElementsInirect () , you can render with a single drawing call. This allows you to call multiple draws with essentially a single API call. Each sub-call is defined by values ​​in a straight line of the form:

  type -fiff structure {glument count; Glumean Example Count; Glut first index; Gluent bassettes; Glumean Base Instance; } DrawElementsIndirectCommand;  

Since you do not want to attract many examples of the same creed, you use 1 for instanceCount in each draw call. The important idea is that you can still use instancing by specifying a different baseInstance value for each one, so each object will have a different gl_InstanceID value, and you can Use an extensible attribute for values ​​(matrix, etc.), which you want to convert to per object.

So if you currently have a rendering loop:

 for  (int k = 0; k & lt; object count; ++ k) {// set object Uniform k GlDrawElements (GL_TRIANGLES, Object [K]. Indoxount, GL_ UNSIGNED_INT, Object [A]. Index Offset * Sizes (Glutton)); }  

You must fill an array of structures defined with the argument instead:

  Drawing indexes cmds [objectCount]; For (int k = 0; k & lt; object count; ++ k) {cmds [k]. Count = object [k] .indexcount; Cmds [k] .instanceCount = 1; Cmds [k] First index = item [k] .indexoffset; Cmds [k] .baseVertex = 0; Cmds [k] .baseInstance = k; } // Set Up Setup GlMultiDrawElementsInirect (GL_TRIANGLES, GL_UNSIGNED_INT, 0, ObjectCount, 0);  

I have not provided the code for the complete setup above. The major steps include:

  • Drop cmds into a buffer, and tie it as GL_DRAW_INDIRECT_BUFFER .
  • Store the counter-object value in VBO
  • Set up the per-vertical property as usual.
  • Set up an index buffer normally.

To work for this, the index will be in the same index buffer for all the objects, and the value of each attribute must be on all objects in the same VBO.


No comments:

Post a Comment