blob: f3db163cb19945addafc57bdfba645a357e176fa [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/render_pass.h"
namespace impeller {
RenderPass::RenderPass(RenderTarget target)
: render_target_(std::move(target)),
transients_buffer_(HostBuffer::Create()) {}
RenderPass::~RenderPass() = default;
const RenderTarget& RenderPass::GetRenderTarget() const {
return render_target_;
}
ISize RenderPass::GetRenderTargetSize() const {
return render_target_.GetRenderTargetSize();
}
HostBuffer& RenderPass::GetTransientsBuffer() {
return *transients_buffer_;
}
void RenderPass::SetLabel(std::string label) {
if (label.empty()) {
return;
}
transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str()));
OnSetLabel(std::move(label));
}
bool RenderPass::AddCommand(Command command) {
if (!command) {
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
return false;
}
if (command.scissor.has_value()) {
auto target_rect = IRect({}, render_target_.GetRenderTargetSize());
if (!target_rect.Contains(command.scissor.value())) {
VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
"of the render target.";
return false;
}
}
if (command.index_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
}
if (command.instance_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
}
commands_.emplace_back(std::move(command));
return true;
}
} // namespace impeller