Skip to content

RenderVboIbo: fix number of vertex indices for glDrawElements#152

Open
christian-rauch wants to merge 3 commits intostevenlovegrove:masterfrom
christian-rauch:RenderVboIbo_fix
Open

RenderVboIbo: fix number of vertex indices for glDrawElements#152
christian-rauch wants to merge 3 commits intostevenlovegrove:masterfrom
christian-rauch:RenderVboIbo_fix

Conversation

@christian-rauch
Copy link
Collaborator

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.

@stevenlovegrove stevenlovegrove changed the base branch from devel to master October 10, 2016 22:25
@christian-rauch
Copy link
Collaborator Author

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?

@stevenlovegrove
Copy link
Owner

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
Copy link
Owner

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?

@christian-rauch
Copy link
Collaborator Author

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.

The amount of indices to use from the element buffer is number-of-elements
times the number-of-indices.
By using GL_TRIANGLES, the index order does not need to be pre-processed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants