Imagine I have a cube which consists of six surfaces. My goal I want to reach is to be able to export this cube in STL format. Tessellating a cube is quite easy but this is just an example here.
Now I want to use the OpenGL tessellation shader to perform the tessellation and grab the created triangles and use them as STL triangles. As far as I understand when I pass each surface as a patch to the shader, they get tessellated independently from each other. This can result in non matching nodes/points of the triangles at the cube's surface edges. Thus this would not be a valid STL file.
Is there a way to force the tessellation shader to create matching nodes/poins on patch edges when patches are in contact? Should I define a patch which consists of all six surfaces of the cube when this is even possible?

- 233
- 1
- 10
-
This is going to be much simpler to perform on the CPU. Unless you need to generate STL files real-time... what's the goal? – 3Dave Nov 16 '20 at 15:07
-
The goal is to export an STL file of an arbitrary geometry. This is most likely to be a concave polygon with holes. May idea was to use the tessellation shader as tessellation concave polygons with holes by hand can be very complex. – vydesaster Nov 16 '20 at 15:11
-
1@vydesaster Um, the tesselation shader isn't really made for that purpose. It's mostly meant for subdivision of primitives, not tesselation of arbitrary geometry. One hint at that is the lower bound for patch size is 32, which would already significantly limit your ability to use it to tesselate arbitrary geometry – Bartek Banachewicz Nov 16 '20 at 15:12
1 Answers
That sounds like a use case for Transform Feedback. Long story short, this mechanism exists just for what you want to do - to grab the result of a vertex pipeline and store it in a buffer.
If you're not dead set on using the tesselation pipeline, you might want to consider Compute Shaders instead as well. They're in general very well suited for offline jobs, and are much more flexible in terms of input and output.
As for the actual vertex generation, there's nothing that will prevent you from generating "invalid" geometry. This is something you need to guarantee yourself, but it's possible to ensure if done correctly:
Tessellating patches so that there are no gaps between primitives generated by adjacent patches is very important. It also is not something that simply happens. Because OpenGL is blind to how the actual tessellation works (the primitive generator only deals with the abstract patch), there are specific things that you must do to ensure gap-less tessellation between patches.

- 38,596
- 7
- 91
- 135