Pangolin icon indicating copy to clipboard operation
Pangolin copied to clipboard

RenderVboIbo: fix number of vertex indices for glDrawElements

Open christian-rauch opened this issue 8 years ago • 4 comments

This commit fixes an issue in RenderVboIbo where the incorrect number of indices (ibo.num_elements) is used for glDrawElements. The correct number of indices to use is ibo.num_elements*ibo.count_per_element.

christian-rauch avatar Oct 06 '16 18:10 christian-rauch

I am using this fix for quite some time to correctly render meshes. Can I have some feedback if this is the desired solution and what is needed to get the fix merged upstream?

christian-rauch avatar Nov 15 '16 11:11 christian-rauch

Sorry, I haven't had a chance to look properly at it. The GL_TRIANGLE_STRIP parameter should probably be an option, not hard-coded. GL_TRIANGLE_STRIP is more efficient generally than GL_TRIANGLES if you have managed to set up your indices in a way to use them. Regarding the element count, it seems like a usage issue - I need to take a look at it carefully because your change would appear to break the semantics for existing code.

stevenlovegrove avatar Nov 15 '16 18:11 stevenlovegrove

If you look at the documentation for glDrawElements (https://www.opengl.org/sdk/docs/man4/html/glDrawElements.xhtml), the second parameter is the "number of elements to be rendered". If you take MakeTriangleStripIboForVbo as an example, you would typically have only 1 'count per element' for an IBO. What would multiple counts mean, in an index buffer?

stevenlovegrove avatar Nov 18 '16 10:11 stevenlovegrove

The problem is probably my mesh, it has holes. E.g. MakeTriangleStripIboForVbo cannot generate a triangle strip with missing triangles.

Here is example code (with corrupted mesh): triangle_strip_example.tar.gz that compares both approaches (with and without MakeTriangleStripIboForVbo preprocessing).

Running: ./triangle_strip_example nostrip ../bottle_holes.ply will render the mesh (GL_TRIANGLES) with holes as it is e.g. rendered by MeshLab: mesh_holes

./triangle_strip_example strip ../bottle_holes.ply will generate the triangle-strip and render (GL_TRIANGLE_STRIP) wrongly: mesh_strip

There should be an optional flag to render meshes that have not been converted to a triangle strip. Alternative this could be determined by the count_per_element, which will be 1 for a triangle strip and e.g. 3 for triangular faces.

christian-rauch avatar Dec 07 '16 19:12 christian-rauch