Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions packages/flame/lib/src/camera/camera_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,6 @@ class CameraComponent extends Component {
canvas.save();
try {
currentCameras.add(this);
void renderWorld(Canvas canvas) {
canvas.transform2D(viewfinder.transform);
world!.renderFromCamera(canvas);

// Render the viewfinder elements, which will be in front of
// the world,
// but with the same transforms applied to them.
viewfinder.renderTree(canvas);
}

final postProcessors = children.query<PostProcessComponent>();
if (postProcessors.isNotEmpty) {
assert(
Expand All @@ -223,13 +213,11 @@ class CameraComponent extends Component {
postProcessor.render(
canvas,
viewport.virtualSize,
renderWorld,
(context) {
renderContext.currentPostProcess = context;
},
_renderWorld,
_updatePostProcessContext,
);
} else {
renderWorld(canvas);
_renderWorld(canvas);
}
} finally {
currentCameras.removeLast();
Expand All @@ -242,6 +230,24 @@ class CameraComponent extends Component {
canvas.restore();
}

/// Renders the world and the viewfinder elements through the camera
/// transform. An instance method rather than a local function, so that the
/// render pass does not allocate a closure per camera per frame.
void _renderWorld(Canvas canvas) {
canvas.transform2D(viewfinder.transform);
world!.renderFromCamera(canvas);
// Render the viewfinder elements, which will be in front of the world,
// but with the same transforms applied to them.
viewfinder.renderTree(canvas);
}

// Not a setter: this is passed as a `ValueSetter` tear-off to
// `PostProcess.render`.
// ignore: use_setters_to_change_properties
void _updatePostProcessContext(PostProcess? context) {
renderContext.currentPostProcess = context;
}

/// Converts from the global (canvas) coordinate space to
/// local (camera = viewport + viewfinder).
///
Expand Down
Loading