RazrFalcon / tiny-skia

A tiny Skia subset ported to Rust
BSD 3-Clause "New" or "Revised" License
1.12k stars 69 forks source link

is there a fast way to draw vertex colored triangles? #53

Closed tinaun closed 2 years ago

tinaun commented 2 years ago

or would I have to fill each triangle 3 times for each vertex's color with a gradient pattern to get the blending correct?

RazrFalcon commented 2 years ago

Can you illustrate what you want?

tinaun commented 2 years ago

my shape data has a color associated with each point in the shape, like this classic OpenGL example: https://learnopengl.com/img/getting-started/shaders3.png

RazrFalcon commented 2 years ago

This is a 2D CPU library. It doesn't operate on vertexes. To draw multiple triangles like this you would need to render one to a bitmap first and then use it as a pattern.

tinaun commented 2 years ago

I know that, I was just wondering if there was a way I could render one without a gpu and without writing my own equivalent of SkCanvas::drawVertices - I guess someone has to.

RazrFalcon commented 2 years ago

I guess this is what you're looking for:

https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/src/core/SkDraw_vertices.cpp#L266

It seems like Skia uses a custom code path specifically for this function. Meaning there is no code for such a path in tiny-skia. It looks like a 500-1000 LOC patch. I can't imagine why anyone would want anything like this and I do not plan implementing it either.