OpenGL (and all other hardware rasterizers) only guarantees gapless rendering of the edge between two triangles if the edges exactly match. And that means you can't just have one triangle next to the edge of another. The two triangles must have identical vertices on the shared edge between them.
So if you have a long triangle next to a short triangle, what you have to do is split the long triangle into several triangles, so that the shared portion of the edge is properly shared between two triangles.
Since you seem to be building a world made of cubes, this should be fairly easy for you.
The other thing you have to do is make certain that the two shared vertices between the two triangles are binary identical. The gl_Position
output from the vertex shader needs to be the exact same value. So if you're computing the position of the cube's vertices in the VS, you need to do that in a way that will guarantee binary identical results.
But in my case I want to keep the greedy meshing due to performance aspects.
Then you need to decide which is more important: performance, or correctness. Because there's no way to force the rasterizer allow such edges to be gapless. It's a matter of floating-point precision and such, which will always be different on different hardware.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…