mirror of
https://github.com/flutter/samples.git
synced 2026-05-19 21:46:29 +00:00
Updated fragment shader sample to use uniform-by-name accessor (#2736)
Do not land until the following are on stable: - https://github.com/flutter/flutter/pull/176728 - https://github.com/flutter/flutter/pull/176980 If you need help, consider asking for advice on the #hackers-devrel channel on [Discord].
This commit is contained in:
@@ -44,13 +44,15 @@ class MyHomePage extends StatelessWidget {
|
||||
}
|
||||
|
||||
class ShaderPainter extends CustomPainter {
|
||||
ShaderPainter({required this.shader});
|
||||
ui.FragmentShader shader;
|
||||
ShaderPainter({required this.shader})
|
||||
: _resolution = shader.getUniformVec2('resolution');
|
||||
|
||||
final ui.FragmentShader shader;
|
||||
final ui.UniformVec2Slot _resolution;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
shader.setFloat(0, size.width);
|
||||
shader.setFloat(1, size.height);
|
||||
_resolution.set(size.width, size.height);
|
||||
|
||||
final paint = Paint()..shader = shader;
|
||||
canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), paint);
|
||||
|
||||
Reference in New Issue
Block a user