floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.63k stars 472 forks source link

What is the best way to add tessellation shader support for OpenGL backend? #891

Closed Lerg closed 10 months ago

Lerg commented 10 months ago

I found myself in need of terrain rendering optimization and want to use a tessellation shader to reduce the number of rendered triangles.

What would be the best way for me to add support for it?

floooh commented 10 months ago

TBH, after quickly skimming over the GL wiki (https://www.khronos.org/opengl/wiki/Tessellation), you're probably better off not using sokol-gfx at all, since it's not just a new shader stage, but also a new primitive type (GL_PATCHES) and this requires pretty deep cuts into the shader, pipeline and draw code (so almost everything).

Normally one can get pretty far with custom requirements by mixing OpenGL calls with sokol-gfx calls, but in this case that might not be worth it because you'd need to re-implement too big parts of the sokol-gfx GL backend.

Also, don't count on tesselation support ever making it into sokol-gfx, at least not until WebGPU has figured out a way to abstract this over the various backend APIs (and then it's still an open question whether this programming model can be wrapped over D3D11 and desktop GL too): https://github.com/gpuweb/gpuweb/issues/445

Lerg commented 10 months ago

@floooh thank you for your insight! Other time then.