Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions impeller/scene/scene_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,24 @@ SceneContext::SceneContext(std::shared_ptr<Context> context)
return;
}

pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
auto unskinned_variant =
MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
*context_);
pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
if (!unskinned_variant) {
FML_LOG(ERROR) << "Could not create unskinned pipeline variant.";
return;
}
pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
std::move(unskinned_variant);

auto skinned_variant =
MakePipelineVariants<SkinnedVertexShader, UnlitFragmentShader>(*context_);
if (!skinned_variant) {
FML_LOG(ERROR) << "Could not create skinned pipeline variant.";
return;
}
pipelines_[{PipelineKey{GeometryType::kSkinned, MaterialType::kUnlit}}] =
std::move(skinned_variant);

{
impeller::TextureDescriptor texture_descriptor;
Expand Down
21 changes: 19 additions & 2 deletions impeller/scene/scene_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ class SceneContext {
public:
explicit PipelineVariantsT(Context& context) {
auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
if (!desc.has_value()) {
is_valid_ = false;
return;
}
// Apply default ContentContextOptions to the descriptor.
SceneContextOptions{}.ApplyToPipelineDescriptor(
*context.GetCapabilities(), *desc);
/*capabilities=*/*context.GetCapabilities(),
/*desc=*/desc.value());
variants_[{}] = std::make_unique<PipelineT>(context, desc);
};

Expand Down Expand Up @@ -99,7 +104,10 @@ class SceneContext {
return variant_pipeline;
}

bool IsValid() const { return is_valid_; }

private:
bool is_valid_ = true;
std::unordered_map<SceneContextOptions,
std::unique_ptr<PipelineT>,
SceneContextOptions::Hash,
Expand All @@ -108,10 +116,19 @@ class SceneContext {
};

template <typename VertexShader, typename FragmentShader>
/// Creates a PipelineVariantsT for the given vertex and fragment shaders.
///
/// If a pipeline could not be created, returns nullptr.
std::unique_ptr<PipelineVariants> MakePipelineVariants(Context& context) {
auto pipeline =
PipelineVariantsT<RenderPipelineT<VertexShader, FragmentShader>>(
context);
if (!pipeline.IsValid()) {
return nullptr;
}
return std::make_unique<
PipelineVariantsT<RenderPipelineT<VertexShader, FragmentShader>>>(
context);
std::move(pipeline));
}

std::unordered_map<PipelineKey,
Expand Down