Close the feature gap for OpenGL mappers between Desktop and WebAssembly environment
A VTK C++ application can be compiled with empscripten into a WASM binary. These instructions Examples/Emscripten/Cxx/README.md, though a little outdated, are known to work after tweaking the cmake configure flags.
Related discourse discussion
- building-vtk-9-with-emscripten-gles-for-rendering
- vtkScalarBarActor-in-webassembly
- texture-buffers-dont-work-in-webgl
With a WASM-ified VTK, OpenGL rendering is very limited because of the constrained WebGL2 (OpenGL ES3.0) feature set. WebGL2 maps to GLES3.0. When this issue referes to GLES3.0, it addresses WebGL2 as well.
As most of the OpenGL VTK mappers were written with desktop OpenGL 3.2+ or OpenGL ES3.2 in mind, their shader programs simply refuse to compile in the browser. A simple C++ example that renders polydata with cell colors and a scalar bar will show lots of errors in the browser's developer console. It would be great to have the performance and feature set of VTK accessible on the web platform through WebAssembly. Here are the identified issues with using VTK C++ through WASM.
-
Color by cell data doesn't work. -
Hardware selector cannot pick cells. -
Cannot render a polydata with the "surface with edges" representation. -
Line width adjustments have no effect. (triangles and strips represented as surface with edges) -
Point size adjustments have no effect. -
The vertex visibility setting has no effect (#18703 (closed)) -
vtkTextureObject::CreateTextureBuffer
doesn't work. Resolved in !9866 (merged) -
2D mappers do not render any geometry. -
Line width adjustments have no effect (VTK_WIREFRAME and lines rendered as VTK_SURFACE) (!10589 (merged)) -
Glyph mapper 3D -
Dual depth peeling
A good number of features rely on texture buffers and gl_PrimitiveID
. Unfortunately, GLES3.0 does not support any of those. A workaround is to have alternate overrides of the classes in Rendering/Core.
Example: A vtkOpenGLES30PolyDataMapper
subclasses vtkOpenGLPolyDataMapper
, implements ReplaceShader<Feature>()
and other important methods such that they are compliant with GLES3.0 spec. When VTK is built with VTK_OPENGL_USE_GLES=ON
, the classes with GLES30 prefix are configured to override Rendering/Core classes instead. This approach can be done for vtkOpenGLGlyph3DMapper
, vtkOpenGLPolyDataMapper2D
and others. A benefit of this approach is that code duplication can be minimized, there is a clear distinction between the GLES30
, GL
mapper code and finally, the GLES30
classes are still capable of implementing completely different rendering algorithms.
Once resolved, VTK will be more pleasant to use in WebAssembly - especially for rendering.