SkPath to SkVertices

552 views
Skip to first unread message

Shawn Riordan

unread,
Mar 31, 2020, 12:20:32 AM3/31/20
to skia-discuss
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

Christopher Dalton

unread,
Mar 31, 2020, 11:47:15 AM3/31/20
to skia-d...@googlegroups.com
You might want to take a look at GrTriangulator.

The GPU backend does convert fills to triangles, but less for now than you might expect, due to the high up-front cost of triangulation.

On Mon, Mar 30, 2020 at 10:20 PM Shawn Riordan <craste...@gmail.com> wrote:
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/c633e2d3-81fa-46df-b1aa-1819630b1677%40googlegroups.com.

Shawn Riordan

unread,
Mar 31, 2020, 2:34:52 PM3/31/20
to skia-discuss
Thank you!  I will check that out.


On Tuesday, March 31, 2020 at 8:47:15 AM UTC-7, Christopher Dalton wrote:
You might want to take a look at GrTriangulator.

The GPU backend does convert fills to triangles, but less for now than you might expect, due to the high up-front cost of triangulation.

On Mon, Mar 30, 2020 at 10:20 PM Shawn Riordan <craste...@gmail.com> wrote:
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

Adrian Dumitru

unread,
Apr 30, 2020, 5:07:49 AM4/30/20
to skia-discuss
Hi,
I'm trying GrTriangulator::PathToVertices, I can obtain the vertices but curves are not rendered smooth.
Red drawn using drawPath, blue using drawVertices.



On Tuesday, 31 March 2020 18:47:15 UTC+3, Christopher Dalton wrote:
You might want to take a look at GrTriangulator.

The GPU backend does convert fills to triangles, but less for now than you might expect, due to the high up-front cost of triangulation.

On Mon, Mar 30, 2020 at 10:20 PM Shawn Riordan <craste...@gmail.com> wrote:
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.
IMG_1190.PNG
IMG_1189.PNG

Dirk Weltz

unread,
Apr 30, 2020, 5:37:54 AM4/30/20
to skia-discuss
Doesn't tolerance change anything?

Adrian Dumitru

unread,
Apr 30, 2020, 6:12:50 AM4/30/20
to skia-discuss
Thank you, it does.

I was using std::numeric_limits<float>::infinity(), switched to SkDoubleToScalar(0.15) and it's good now

On Thursday, 30 April 2020 12:37:54 UTC+3, Dirk Weltz wrote:
Doesn't tolerance change anything?

Dirk Weltz

unread,
Apr 30, 2020, 11:19:25 AM4/30/20
to skia-discuss
Could you say something to performance of using vertices instead of a path for drawing this polygons?

Adrian Dumitru

unread,
Apr 30, 2020, 11:35:57 AM4/30/20
to skia-discuss
I am getting better performance when drawing multiple paths batched with vertices instead of using drawPath.

Dirk Weltz

unread,
Apr 30, 2020, 11:47:38 AM4/30/20
to skia-discuss
You now create vertices from each path and draw each batch of vertices? Or do you add all vertices to one big bucket and render this bucket together? Did you tried to add all pathes to one big path?

Adrian Dumitru

unread,
Apr 30, 2020, 11:56:52 AM4/30/20
to skia-discuss
I add paths to bigger paths, but not to one big paths.
Say I have 1000 paths, I can create 10 paths, each containing 100 of the initial paths. I then draw the vertices for each one of the 10 resulting paths.

I think there is a limit of vertices per drawVertices call, that's why I don't add all of them into a single bucket.

Shawn Riordan

unread,
Apr 30, 2020, 12:03:55 PM4/30/20
to skia-discuss
It would be interesting to hear what happens if you try to put them all into as large a bucket as you can.

Adrian Dumitru

unread,
May 1, 2020, 5:49:37 PM5/1/20
to skia-discuss
drawVertices can not use a paint with bitmap shader? It's drawing using black instead of the bitmap shader.
I've created the shader like this:
sk_sp<SkShader> shader = bitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
paint.setShader(shader);

Brian Osman

unread,
May 1, 2020, 6:05:59 PM5/1/20
to skia-d...@googlegroups.com
How are you creating the vertices? You'll need to include texture coordinates in the vertex data (even if it's just a copy of the positions).

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/8725d0cf-9292-4a4c-85d8-f7a71205ab18%40googlegroups.com.

Adrian Dumitru

unread,
May 1, 2020, 6:14:24 PM5/1/20
to skia-discuss
 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, triangulated, 0, 0/*SkVertices::kHasColors_BuilderFlag*/);
    
     for (int i = 0; i < triangulated; ++i) {
         builder.positions()[i].set(vertices[i].fPos.fX, vertices[i].fPos.fY);
         if (builder.colors()) {
             builder.colors()[i] = fillColor;

         }
     }

On Saturday, 2 May 2020 01:05:59 UTC+3, Brian Osman wrote:
How are you creating the vertices? You'll need to include texture coordinates in the vertex data (even if it's just a copy of the positions).

On Fri, May 1, 2020 at 5:49 PM Adrian Dumitru <orto...@gmail.com> wrote:
drawVertices can not use a paint with bitmap shader? It's drawing using black instead of the bitmap shader.
I've created the shader like this:
sk_sp<SkShader> shader = bitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
paint.setShader(shader);


On Tuesday, 31 March 2020 07:20:32 UTC+3, Shawn Riordan wrote:
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

Brian Osman

unread,
May 1, 2020, 6:17:33 PM5/1/20
to skia-d...@googlegroups.com
Yeah, you're going to want to pass kHasTexCoords_BuilderFlag, and set builder.texCoords()[i] to the same point as positions()[i]. It's arguable that we should support the positions being implicit coords, but for now we ignore the shader unless they're explicitly present.

To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/4f8074bc-6e7f-4e3d-abb5-b5f50445ecf9%40googlegroups.com.

Adrian Dumitru

unread,
May 1, 2020, 6:19:06 PM5/1/20
to skia-discuss
Thanks a lot, I've included texcoords and it works perfectly now.

By the way, I noticed that skia batches drawVertices calls automatically but not drawPath calls, it's indended?

 SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, triangulated, 0, SkVertices::kHasTexCoords_BuilderFlag);

    
     for (int i = 0; i < triangulated; ++i) {
         builder.positions()[i].set(vertices[i].fPos.fX, vertices[i].fPos.fY);
         if (builder.colors()) {
             builder.colors()[i] = fillColor;
         }
         if(builder.texCoords())
             builder.texCoords()[i].set(vertices[i].fPos.fX, vertices[i].fPos.fY);
     }

Matthew Leibowitz

unread,
May 3, 2020, 11:47:28 AM5/3/20
to skia-discuss
I see that file/function is in the "src" directory. What are the rules for using this? I recall that this directory is more "internal implementation" than public API.


On Tuesday, March 31, 2020 at 5:47:15 PM UTC+2, Christopher Dalton wrote:
You might want to take a look at GrTriangulator.

The GPU backend does convert fills to triangles, but less for now than you might expect, due to the high up-front cost of triangulation.

On Mon, Mar 30, 2020 at 10:20 PM Shawn Riordan <craste...@gmail.com> wrote:
Is there any way to convert a filled SkPath to SkVerticies triangles?
I imagine that the OpenGL backend implementation has to do that sometimes.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

Mike Reed

unread,
May 3, 2020, 12:04:15 PM5/3/20
to skia-d...@googlegroups.com
Files in src/... are *entirely* internal implementation, and may change/go-away at any time. The same is true for include/private/...

This thread has pointed to the src/ tessellation code as a courtesy/experiment, so they can see what goes on under the hood. If that code is useful, ambitious users can copy the code for their own use, but they can't rely on it to always be around.

This is not to say we aren't considering options to make something public in the future, but we do want to be clear that accessing private classes is "fine" since all the source is open, but not "reliable" between releases. (we also don't make any explicit attempt to document how the private classes work).


To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/30d54fe4-c2ec-49d7-9219-84b4ce3aad58%40googlegroups.com.

Matthew Leibowitz

unread,
May 3, 2020, 12:06:03 PM5/3/20
to skia-discuss
Awesome, thanks for the confirmation. Just wanted to make sure.

Brian Osman

unread,
May 4, 2020, 7:26:50 AM5/4/20
to skia-d...@googlegroups.com
Re: Batching - It varies. Some path renderers do perform batching, others don't. It depends on how easy it is to apply batching to the particular algorithm, how much it would help, and - in some cases, if the path renderer is so old that it predates the effort to apply batching, and never got updated. For vertices, batching is straightforward.

To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/16a5bd21-8d91-4f46-af7e-a7df92cec10d%40googlegroups.com.

Dirk Weltz

unread,
May 5, 2020, 3:19:47 AM5/5/20
to skia-discuss
@Brian could you explain batching a little bit more or could you point to any documentation on this? For me it sounds like you convert some paths to vertices once and store the result for the next rendering. Is this correct? And which paths are batched? Questions over questions ;-)

Brian Osman

unread,
May 18, 2020, 10:54:06 AM5/18/20
to skia-d...@googlegroups.com
Update: I've just landed  https://skia.googlesource.com/skia/+/8219e91468d35af9df8321705fd10752b6edd8e1, which removes the need for kHasTexCoords. You can now draw a triangulated path that just has positions, and get the same results as drawing the path itself (when there's a shader on the paint).
Reply all
Reply to author
Forward
0 new messages