如何从 Skia 路径几何中获取网格?

How to obtain mesh from Skia path geometry?

我正在尝试弄清楚如何让 Skia 从路径几何体生成网格。我检查了 SkPath::dumpSkPath::writeToMemorySkPath::serialize,但是它们似乎都输出路径内容而不是网格。

注意:我所说的网格是指由路径形状的细分生成的三角形网格,稍后可以使用非矢量图形 API(例如 OpenGL / Vulkan)进行渲染。类似于 ID2D1Geometry::Tessellate.

的输出

正如我所检查的那样 Skia source 在将视频缓冲区推入 GPU 管道之前,从路径到三角形的细分在渲染步骤中自动进行。所以你不必担心,图书馆会照顾好自己。除非你想明确地获得镶嵌步骤的输出,但我怀疑这个 API 是为用户导出的。可能它对图书馆用户是隐藏的。

我把这部分代码提取出来,暴露了三角剖分界面,然后在libpag中使用了OpenGL渲染。

// SkPath.h
int toAATriangles(float tolerance, const SkRect& clipBounds, std::vector<float>* vertex) const;

// SkPath.cpp
int SkPath::toAATriangles(float tolerance,
                          const SkRect& clipBounds,
                          std::vector<float>* vertex) const {
  return GrAATriangulator::PathToAATriangles(*this, tolerance, clipBounds, vertex);
}

https://github.com/libpag/pathkit/blob/main/include/core/SkPath.h#L898 https://github.com/libpag/pathkit/blob/main/src/core/SkPath.cpp#L2453