drawVertices with colors problem

106 views
Skip to first unread message

Mike Clifton

unread,
May 2, 2024, 8:14:51 PM5/2/24
to skia-discuss
I used to use the drawVertices function of the canvas with colored vertices, and with a recent Skia update I started getting just solid black.

I've been digging around for something I changed, but maybe something changed in Skia? See this fiddle - I think the triangle on the left should be a smaooth blend of red, green, and blue, should it not?


Has something changed in how colored triangles are drawn? Does the fiddle need to be updated?

Greg Daniel

unread,
May 2, 2024, 8:48:59 PM5/2/24
to skia-d...@googlegroups.com
I may be misremembering how it works off the top of my head so someone can correct me. But with drawVertices we combine the color of the vertices with the color of the SkPaint. These are combined together using the passed in SkBlendMode. When doing this, I believe the SkPaints color is treated as the src and the vertices as the dst (i.e. the vertices are drawn/colored independently first and then the paint/shader is applied on top using the blend mode). So in your example you are using kSrcOver and since everything is opaque all you will see is the paint's color which is black.

--
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/00c52e9c-9bc3-4c37-b3ee-9da4e5ad9dafn%40googlegroups.com.

Brian Salomon

unread,
May 2, 2024, 9:13:22 PM5/2/24
to skia-d...@googlegroups.com
Yes, if you change the blend mode to kDst you get what you expected. A while back, the blend mode was only respected if the paint had a shader, but that is no longer the case.

Mike Clifton

unread,
May 3, 2024, 12:37:30 AM5/3/24
to skia-discuss
Aha - thank you both! kDst does the trick.

As far as that example I linked to, that's not my example, that came straight from skia.org. So it may be working correctly, but I don't think it's a good example of how to use drawVertices. There are a couple examples linked to from here that just draw blackened triangles. But if you change these examples to kDst, they also work visually the way I believe they are meant to. I don't know who might maintain those examples, but having them show colors by default would be good.

Mike Reed

unread,
May 3, 2024, 10:31:04 AM5/3/24
to skia-d...@googlegroups.com
Agreed -- those examples should be updated to pass kDst for the mode.



--
"I think I can safely say that nobody understands quantum mechanics." -- Richard Feynman
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so." -- Mark Twain
"I am pleased to see that we have differences" -- Surak

John Stiles

unread,
May 3, 2024, 10:42:45 AM5/3/24
to skia-discuss
I've sent out a CL to update the examples: http://review.skia.org/849416

Mike Clifton

unread,
May 3, 2024, 12:09:47 PM5/3/24
to skia-discuss
Awesome - thanks!
Reply all
Reply to author
Forward
0 new messages