5

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.

user7860670
  • 35,849
  • 4
  • 58
  • 84
  • 1
    Are you looking for GrTessellator: https://github.com/google/skia/blob/81abc43e6f0b1a789e1bf116820c8ede68d778ab/src/gpu/GrTessellator.h#L42 – Simon Mourier Feb 14 '20 at 08:17
  • @SimonMourier Yes, but it seems like these methods aren't a part of [public API](https://api.skia.org/) and there is no obvious way to somehow utilize them indirectly. – user7860670 Feb 15 '20 at 07:30

2 Answers2

1

As I've checked into Skia source tesselation from path into triangles goes on automatically in the rendering step, before pushing video buffer into GPU pipeline. So you don't need to worry about that, library takes care itself. Unless you want explicitly get the output of tessellation step, but I doubt that this API is exported for the user. Probably it is hidden from the library user.

Agnius Vasiliauskas
  • 10,935
  • 5
  • 50
  • 70
  • 2
    *"Unless you want explicitly get the output of tessellation step"* - well, that precisely what i want. And i'm almost certain that there should be a proper way to do it because extracting mesh seems to be a common scenario when one needs to repeatedly render a ton of paths separately and regenerating vector graphics is expensive while prerendering them to texture is out of question. – user7860670 Feb 13 '20 at 10:02
  • Then by all means, look at the link cited above. The Tesselator described there in turn calls PathToTriangles() here: https://github.com/google/skia/blob/master/src/gpu/GrTessellator.cpp#L2461 – bjorke Feb 18 '20 at 06:34
1

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

吕鹏伟
  • 79
  • 6