Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain mesh from Skia path geometry?

Tags:

c++

skia

I'm trying to figure out how to make Skia produce mesh from path geometry. I've checked SkPath::dump, SkPath::writeToMemory, SkPath::serialize, however all of them seem to output path content rather than mesh.

Note: by mesh i mean triangle mesh produced by tessellation of path shape that can be later used to be rendered with non-vector graphical APIs, such as OpenGL / Vulkan. Something similar to output of ID2D1Geometry::Tessellate.

like image 793
user7860670 Avatar asked Nov 06 '22 10:11

user7860670


1 Answers

I have extracted this part of the code, exposed the triangulation interface, and then used OpenGL rendering in libpag.

// 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/5bf0bc2acf8dbd74efb5713627de144a8f1ef2b1/include/core/SkPath.h#L898 https://github.com/libpag/pathkit/blob/5bf0bc2acf8dbd74efb5713627de144a8f1ef2b1/src/core/SkPath.cpp#L2453

like image 87
吕鹏伟 Avatar answered Nov 22 '22 12:11

吕鹏伟