Skip to content

Commit bf6cdc1

Browse files
authored
Update simple_sdf sample to use uniform-by-name accessor (#2843)
The newer, more convenient method `getUniformVec2` is now available on stable, so let's use that in the `simple_sdf` sample ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [ ] I have added sample code updates to the [changelog]. - [x] I updated/added relevant documentation (doc comments with `///`). <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md [changelog]: ../CHANGELOG.md
1 parent 8fbf213 commit bf6cdc1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

simple_sdf/lib/main.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ class MyHomePage extends StatelessWidget {
4444
}
4545

4646
class ShaderPainter extends CustomPainter {
47-
ShaderPainter({required this.shader});
48-
ui.FragmentShader shader;
47+
ShaderPainter({required this.shader})
48+
: _resolution = shader.getUniformVec2('resolution');
49+
50+
final ui.FragmentShader shader;
51+
final ui.UniformVec2Slot _resolution;
4952

5053
@override
5154
void paint(Canvas canvas, Size size) {
52-
shader.setFloat(0, size.width);
53-
shader.setFloat(1, size.height);
55+
_resolution.set(size.width, size.height);
5456

5557
final paint = Paint()..shader = shader;
5658
canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), paint);

0 commit comments

Comments
 (0)