Canvas.drawVertices - Incredibly fast, incredibly low-level, incredibly fun

  Рет қаралды 19,137

Filip Hráček

Filip Hráček

Күн бұрын

One of Flutter's lowest-level APIs is the drawVertices method, which allows you to efficiently draw an astounding amount of stuff on the screen. That stuff can be lines, rectangles, polygons, particles, and whatever else you can think of. This method is how people (including Filip) can even implement specialized 3D renderers on top of Dart that run fast on mobile, web and desktop. In this talk, Filip will explain the API of Canvas.drawVertices() and the Vertices.raw() constructor - both are obscure, very low-level, and hard to explain in documentation alone. But they are worth it when you need to squeeze the last bit of performance out of Flutter.
We'll also cover Canvas.drawLines, for good measure.
This talk is part of Flutter Forward, a 2023 official Flutter conference in Nairobi, Kenya.

Пікірлер: 89
@mahmood466
@mahmood466 11 ай бұрын
This is some excellent quality content in Flutter! Please continue!!
@HezOmanjo
@HezOmanjo Жыл бұрын
Too nerdy for me ... But I'll say this - Filip has always challenged me to push beyond my boundaries of thinking in Flutter. Right from day 1. Amazing man 👍🏽
@imaNNeO
@imaNNeO Жыл бұрын
That was really great. I learned a lot. Thank you Filip
@CodeWithImem
@CodeWithImem 5 ай бұрын
the depth of the informations you provide it's amazing .
@thanhdatvo0
@thanhdatvo0 Жыл бұрын
We missed you! Welcome back!
@SmashHighlights
@SmashHighlights Жыл бұрын
Really interesting, thanks for sharing! I always enjoy your focus on performance and low level stuff in Flutter.
@Dotafreak
@Dotafreak Жыл бұрын
Fear of canvas is slowly reducing. Thanks for sharing this.
@lemomar
@lemomar Жыл бұрын
This was great! I’ve recently begun to work on the canvas after years of being scared of it and I’m enjoying it a lot
@mksln
@mksln Жыл бұрын
Wonderful video Filip! Thanks for the great intro to drawVertices, I didn't even know it was there, it looks like a great way to squeeze out lots more drawing performance when have need of it in Flutter apps.
@jjny916
@jjny916 10 ай бұрын
This is excellent and incredibly valuable content. Thank you.
@giiyms4408
@giiyms4408 Жыл бұрын
Thanks Filip. Keep it up. Learning a lot!
@yf4453
@yf4453 Жыл бұрын
Amazing talk. Thakn you!
@mivoligo
@mivoligo 10 ай бұрын
Just wanted to say Thank You! ❤
@SecondFlight
@SecondFlight Жыл бұрын
Thanks so much for this talk! I didn't realize this was hidden in the painter API and I'm excited to try it out.
@pankajkoirala6563
@pankajkoirala6563 Жыл бұрын
Really happy to watch such content :)
@Andreasonline3
@Andreasonline3 Жыл бұрын
absolutley dope keen to see more
@mohanedy
@mohanedy Жыл бұрын
I have enjoyed every second of this video. Really helpful and interesting. But I think you have drawn the Kotlin logo at 30:50 accidentally, maybe this is how the Kotlin team came up with the logo idea 😂
@reacct1002
@reacct1002 Жыл бұрын
Thanks Filip!
@Hamiiidev
@Hamiiidev Жыл бұрын
Great. waiting for Flutter Forward analysis.
@CarlosHenrique-er7zq
@CarlosHenrique-er7zq Жыл бұрын
Amazingggg video! Thanks for it
@dhruvinvainsh743
@dhruvinvainsh743 Жыл бұрын
This is superb
@Apenschi
@Apenschi Жыл бұрын
VERY good! Thanks!
@saqibshafin
@saqibshafin Жыл бұрын
I love your work. So much. Keep it up! Also, please finish the Self Improving Developer book!
@user-on3zu2fh6j
@user-on3zu2fh6j Жыл бұрын
great. love your way.
@TheDescrout
@TheDescrout Жыл бұрын
While looking at the drawVertices docs I saw that flutter also has drawAtlas(and drawRawAtlas) methods. Would these be better for drawing a lot of images ? Also in your example the image in the polygon is not rotating. I assume it could be rotated via some sort of UV coordinates binding. I see that drawAtlas method supports all sort of transformations like scale and rotation that could make our life easier but maybe at the cost of a little performance ?
@TadejKanizar
@TadejKanizar Жыл бұрын
Very cool. I'm going to start drawing all widgets using drawVertices from now on ;)
@filiphracek
@filiphracek Жыл бұрын
Lol. Yes. It also helps to render all text via Vertices.raw, inputting each vertex by hand while juggling a chainsaw.
@MohamedSalah-pi7fn
@MohamedSalah-pi7fn Жыл бұрын
This is awesome ❤️
@mkc11267
@mkc11267 Жыл бұрын
Awesome!!
@erlangparasu6339
@erlangparasu6339 Жыл бұрын
Great! Thanks 👍
@JessicaPereira-wy6ru
@JessicaPereira-wy6ru 11 ай бұрын
Thanks for this amazing talk Filip, you inspire me... Do you have the code source?
@filiphracek
@filiphracek 11 ай бұрын
Not the one I show in the talk, but have a look at github.com/zesage/flutter_cube, for example.
@SirJohn2024
@SirJohn2024 Жыл бұрын
Nerdy... But interesting... Basically you can build a 3D engine on top of that, Flutreal Engine maybe? 😏
@hyungtaecf
@hyungtaecf Жыл бұрын
Or Flame 3D
@KennyFully
@KennyFully Жыл бұрын
I’m tired of flame. I’m going to do it myself.
@R4IVI
@R4IVI Жыл бұрын
My first thought when you asked for the "bug" was : "that comes from the 16bits limits !" I'm not a low level engineer but I learned that when trying to position planets accurately in space in Blender3D, which use a 32-bits number precision, which is ok for entertainment but weak for technical viz' ! 🤓
@iy908
@iy908 Жыл бұрын
Please do more videos about high performance flutter/dart! Like how to use SIMD operations in flutter or own implementation of spatial interpolation algo and so on
@mojtabana6322
@mojtabana6322 Жыл бұрын
thanks for sharing
@yafiwala
@yafiwala Жыл бұрын
Gonna start Flutter again I did first start in 2017
@alexandergorny
@alexandergorny Жыл бұрын
Yes nerdy, but love it! feels like first days of creating assembler triangles on vc20 ;) So curious about your SciFi UIs, please share !!!
@tluanga-ruatpuii-pa
@tluanga-ruatpuii-pa Жыл бұрын
Can you please release a video about your desk setup
@rlrl5879
@rlrl5879 Жыл бұрын
Have you tried running this demo on an ios device with impeller enabled? I have an app with some very complex scenes like this that runs fine in skia, but locks up on impeller. I still need to dig into what is goin on, but Im curious if you would see the same with this demo.
@SimonNielsen-zm7mq
@SimonNielsen-zm7mq Жыл бұрын
Nice! Will it be possible for you to share the comparison app?
@AntonioBrandao
@AntonioBrandao Жыл бұрын
29:44 can these drawn shapes be tapped / made interactive with a GestureDetector or so? How would the hit area work there?
@dokinds
@dokinds Жыл бұрын
nice work @Flip :)
@aytunch
@aytunch 8 ай бұрын
Hi Filip, will you make the source code of the snowflake benchmark available? On part you did not mention int he talk was how you are changing the positions of all the vertices. SO it would be very helpful to see the code. Thanks
@mrverdant13
@mrverdant13 Жыл бұрын
I really love this video I wonder how could we add interactivity tho
Жыл бұрын
I think I have a gold rush because this is gold! This is exactly what I needed. So now what I understood is that it's the Float32List is what makes things fast not drawVertices() as much?
@filiphracek
@filiphracek Жыл бұрын
Pretty much, yes. TypedData, if you keep it around, makes things go fast. (On the other hand, if you create (and then throw away) a big chunk of typed data every frame, then it might easily be slower.)
@SecondFlight
@SecondFlight Жыл бұрын
It also seems that drawVertices() is a lot closer to the equivalent graphics API call than something like drawLine(). This means Flutter basically doesn't need to transform the data you send it before handing it to the GPU, which I imagine helps quite a bit as well.
@RioM8z
@RioM8z Жыл бұрын
You seem to prefer Android Studio as your editor ?! Isn't the little program that is an example available ?
@nonnulls
@nonnulls Жыл бұрын
Please, can you add a link to repo with source code to the description?
@becbelk
@becbelk Жыл бұрын
Good idea that the vertex eat from the buffer of the next data
@DominikRoszkowski
@DominikRoszkowski Жыл бұрын
I find it funny that it's indices that overflow, not positions or the list length. The fact that it takes 5 indices for 1 snow-flake made me a little bit puzzled at first ;)
@filiphracek
@filiphracek Жыл бұрын
Yeah, I started the experimentation with polygons (any n-gon), so it was easiest to have a vertex in the middle and draw triangles from there. It also made it easier to draw the kind of gradients I wanted. Ideally, I should have rewritten the code for the special case of a rectangle, where you need 1 less vertex and _half_ the triangles... Welp. Next time! :)
@musoftware
@musoftware Жыл бұрын
I felt the felling of OpenGL 2 era. Ah... That nostalgic glVertex3f function...
@atmega3212
@atmega3212 Жыл бұрын
It's kinda like OpenGl, I love it
@kausikmr
@kausikmr Жыл бұрын
Canvas.drawVertices is not Anti Aliased even after adding the antiAliased = true in the Paint(). Is there a solution for this @Filip Hráček ?
@zainroyan1556
@zainroyan1556 Жыл бұрын
Love your content, but iam interested as to how can u make ur vs code transparent
@theforestapp
@theforestapp Жыл бұрын
can you recommend any reading material on using the raw vertices/float lists?
@filiphracek
@filiphracek Жыл бұрын
I was going from the docs, tbh. They're terse, but they have everything you'll need.
@babydoll-li9ng
@babydoll-li9ng Жыл бұрын
What should we do to fastest the widget build ?
@gaosdatastory8884
@gaosdatastory8884 Жыл бұрын
Hi filip, Question for you. Can I use Flame in Flutter Casual Games Toolkit? I am a newbie to Flutter Casual Games Toolkit. Not sure if I can use flame in Flutter Casual Games Toolkit or not.
@odewoleabdul-jemeel8859
@odewoleabdul-jemeel8859 Жыл бұрын
This is awesome. Where can we get the source code?
@chiefolk
@chiefolk Жыл бұрын
51:00 because indices is a typed data of Uint16List which can only hold values from 0 to 65,535. so when we are trying to index from positions maybe greater than that it's breaking it??
@chiefolk
@chiefolk Жыл бұрын
so when there are more than 65,536 positions in the positions list and indices array is trying address them but it cannot be fit in 16 bits?
@chiefolk
@chiefolk Жыл бұрын
55:00 yeah i was close ✨
@cycomkid
@cycomkid Жыл бұрын
Hoping shaders deepdive
@Kiriyaki65548
@Kiriyaki65548 Жыл бұрын
🚀 🚀 🚀 🚀 🚀
@shubhamyeole2881
@shubhamyeole2881 Жыл бұрын
First comment before watching... 😀
@Pewdew
@Pewdew 10 ай бұрын
Is it possible to prepaint custom painters? I can't figure it out how to fix bad performance. I have 15 custom painter widgets and 10 fps😢
@filiphracek
@filiphracek 10 ай бұрын
Interesting. I admit I've never seen an issue like that. Are you updating them all every frame? Because if not, CustomPainter shouldRepaint() is your friend.
@Pewdew
@Pewdew 10 ай бұрын
@@filiphracek i turn phone, tilt changes and blocbuilder rebuild CustomPainters with new state. Also these custom painters are similar. Is there any way to paint it once and share to all my widget? Because each paint spent time.
@ankitverma3932
@ankitverma3932 Жыл бұрын
how do i get this code?
@LuisFernandez-cz7gb
@LuisFernandez-cz7gb Ай бұрын
code example please 😊😊
@danielduvana
@danielduvana Жыл бұрын
Is it not possible to draw circles with drawVertices? What's the most performant way to draw circles? Just Canvas.drawCircle?
@filiphracek
@filiphracek Жыл бұрын
Yes, drawCircle is really fast. You could use vertices to draw a circle-like polygon but I'm almost sure it would not give you any performance boost (possibly the opposite).
@yf4453
@yf4453 Жыл бұрын
What theme is he using?
@filiphracek
@filiphracek Жыл бұрын
The theme is called "high contrast" or something like that.
@coldwolf5050
@coldwolf5050 Жыл бұрын
Will you put this on github?
@henryriehl2058
@henryriehl2058 Жыл бұрын
One very small thing, but you could probably improve the performance a bit for the widget side of things by using valueNotifier with a listenable builder :) Currently the Stack, ColouredBox and SizedBox widgets are being rebuilt unnecessarily.
@AmazingGrace0412
@AmazingGrace0412 Жыл бұрын
Please bring Native integration with cockroachdb and interfaces like algolia 💪
@babydoll-li9ng
@babydoll-li9ng Жыл бұрын
can you please share me the code ?
@himmelkami3308
@himmelkami3308 Жыл бұрын
for one day , real game engine built by flutter.
@DmitriiGordeev
@DmitriiGordeev Жыл бұрын
This is not black magic )
@user-jr7tg5ew3r
@user-jr7tg5ew3r Жыл бұрын
How does it work by providing "this" as TickerProvider ?
@ghost_7701
@ghost_7701 Жыл бұрын
Me watching this is like monkey watching surgery 😂😂 But I really enjoyed it and I hope one day that I become on that level of understanding 🫡
@filiphracek
@filiphracek Жыл бұрын
Trust me, if I was watching this a year ago, I would feel the same. It's low-level and confusing. But once I tried (and failed) to wield this API a couple of times, it clicked.
@ghost_7701
@ghost_7701 Жыл бұрын
​@@filiphracek I will give it a try I love these challenges. Thanks for the inspiration.
Solo Gamedev: How to Build Successful Games by Yourself
23:03
Filip Hráček
Рет қаралды 25 М.
Reflecting on Hixie (Flutter Co-Founder & Tech Lead) leaving Google
24:21
GTA 5 vs GTA San Andreas Doctors🥼🚑
00:57
Xzit Thamer
Рет қаралды 28 МЛН
Bike vs Super Bike Fast Challenge
00:30
Russo
Рет қаралды 23 МЛН
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 2,8 МЛН
Or is Harriet Quinn good? #cosplay#joker #Harriet Quinn
00:20
佐助与鸣人
Рет қаралды 50 МЛН
Why is this game made with Flutter?
17:46
Filip Hráček
Рет қаралды 21 М.
Neural network in pure Dart
31:01
Filip Hráček
Рет қаралды 10 М.
Why you should bet on Flutter even after Google layoff
7:44
Kei Fujikawa
Рет қаралды 1,4 М.
Phoenix LiveView Is Making Me Reconsider React...
36:59
Theo - t3․gg
Рет қаралды 158 М.
The return of bespoke apps
17:29
Filip Hráček
Рет қаралды 3,9 М.
Observable Flutter #43: On-device LLMs with Gemma
1:33:42
Flutter
Рет қаралды 19 М.
On Google I/O as an attendee
29:17
Filip Hráček
Рет қаралды 4,3 М.
Flutter Forward - Making UI Animation Easy & Fun
16:43
gskinner
Рет қаралды 51 М.
Flutter Mad Science (conference talk)
21:41
Filip Hráček
Рет қаралды 2,3 М.
GTA 5 vs GTA San Andreas Doctors🥼🚑
00:57
Xzit Thamer
Рет қаралды 28 МЛН