Use the pipeline builder for the box primitive.
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
namespace impeller {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief A utility for creating pipelines from reflected shader
|
||||
/// information.
|
||||
/// @brief An optional (but highly recommended) utility for creating
|
||||
/// pipelines from reflected shader information.
|
||||
///
|
||||
/// @tparam VertexShader_ The reflected vertex shader information. Found
|
||||
/// in a generated header file called
|
||||
|
||||
@@ -22,6 +22,9 @@ class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
|
||||
public:
|
||||
~PipelineLibrary();
|
||||
|
||||
std::future<std::shared_ptr<Pipeline>> GetRenderPipeline(
|
||||
std::optional<PipelineDescriptor> descriptor);
|
||||
|
||||
std::future<std::shared_ptr<Pipeline>> GetRenderPipeline(
|
||||
PipelineDescriptor descriptor);
|
||||
|
||||
|
||||
@@ -14,6 +14,16 @@ PipelineLibrary::PipelineLibrary(id<MTLDevice> device) : device_(device) {}
|
||||
|
||||
PipelineLibrary::~PipelineLibrary() = default;
|
||||
|
||||
std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
std::optional<PipelineDescriptor> descriptor) {
|
||||
if (descriptor.has_value()) {
|
||||
return GetRenderPipeline(std::move(descriptor.value()));
|
||||
}
|
||||
auto promise = std::make_shared<std::promise<std::shared_ptr<Pipeline>>>();
|
||||
promise->set_value(nullptr);
|
||||
return promise->get_future();
|
||||
}
|
||||
|
||||
std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
PipelineDescriptor descriptor) {
|
||||
auto promise = std::make_shared<std::promise<std::shared_ptr<Pipeline>>>();
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "impeller/compositor/renderer.h"
|
||||
#include "impeller/compositor/vertex_buffer.h"
|
||||
#include "impeller/entity/entity.h"
|
||||
#include "impeller/primitives/box_primitive.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -20,7 +19,7 @@ class EntityRenderer final : public Renderer {
|
||||
|
||||
private:
|
||||
std::shared_ptr<Entity> root_;
|
||||
std::shared_ptr<BoxPrimitive> box_primitive_;
|
||||
std::shared_ptr<Pipeline> box_pipeline_;
|
||||
VertexBuffer vertex_buffer_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
#include "impeller/compositor/command.h"
|
||||
#include "impeller/compositor/pipeline_builder.h"
|
||||
#include "impeller/compositor/sampler_descriptor.h"
|
||||
#include "impeller/compositor/surface.h"
|
||||
#include "impeller/compositor/vertex_buffer_builder.h"
|
||||
@@ -25,8 +26,13 @@ EntityRenderer::EntityRenderer(std::string shaders_directory)
|
||||
return;
|
||||
}
|
||||
|
||||
box_primitive_ = std::make_shared<BoxPrimitive>(context);
|
||||
if (!box_primitive_) {
|
||||
using BoxPipelineBuilder =
|
||||
PipelineBuilder<BoxVertexShader, BoxFragmentShader>;
|
||||
auto desc = BoxPipelineBuilder::MakeDefaultPipelineDescriptor(*context);
|
||||
box_pipeline_ =
|
||||
context->GetPipelineLibrary()->GetRenderPipeline(std::move(desc)).get();
|
||||
|
||||
if (!box_pipeline_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,8 +73,8 @@ bool EntityRenderer::OnRender(const Surface& surface, RenderPass& pass) {
|
||||
|
||||
Command cmd;
|
||||
cmd.label = "Box";
|
||||
cmd.pipeline = box_primitive_->GetPipeline();
|
||||
cmd.vertex_bindings.buffers[box_primitive_->GetVertexBufferIndex()] =
|
||||
cmd.pipeline = box_pipeline_;
|
||||
cmd.vertex_bindings.buffers[VertexDescriptor::kReservedVertexBufferIndex] =
|
||||
vertex_buffer_.vertex_buffer;
|
||||
cmd.vertex_bindings.buffers[BoxVertexShader::kUniformUniformBuffer.binding] =
|
||||
pass.GetTransientsBuffer().EmplaceUniform(uniforms);
|
||||
|
||||
@@ -14,8 +14,6 @@ impeller_shaders("impeller_shaders") {
|
||||
|
||||
impeller_component("primitives") {
|
||||
sources = [
|
||||
"box_primitive.h",
|
||||
"box_primitive.mm",
|
||||
"primitive.h",
|
||||
"primitive.mm",
|
||||
]
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "impeller/compositor/context.h"
|
||||
#include "impeller/primitives/box.frag.h"
|
||||
#include "impeller/primitives/box.vert.h"
|
||||
#include "impeller/primitives/primitive.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class BoxPrimitive final : public Primitive {
|
||||
public:
|
||||
BoxPrimitive(std::shared_ptr<Context> context);
|
||||
|
||||
// |Primitive|
|
||||
std::shared_ptr<Pipeline> GetPipeline() const override;
|
||||
|
||||
// |Primitive|
|
||||
~BoxPrimitive() override;
|
||||
|
||||
// |Primitive|
|
||||
virtual bool IsValid() const override;
|
||||
|
||||
// |Primitive|
|
||||
virtual bool Encode(RenderPass& pass) const override;
|
||||
|
||||
size_t GetVertexBufferIndex() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Pipeline> pipeline_ = 0;
|
||||
size_t vertex_buffer_index_ = 0;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BoxPrimitive);
|
||||
};
|
||||
|
||||
bool RenderBox(std::shared_ptr<Context> context);
|
||||
|
||||
} // namespace impeller
|
||||
@@ -1,52 +0,0 @@
|
||||
// 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/primitives/box_primitive.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/base/base.h"
|
||||
#include "impeller/compositor/pipeline_builder.h"
|
||||
#include "impeller/compositor/pipeline_descriptor.h"
|
||||
#include "impeller/compositor/shader_library.h"
|
||||
#include "impeller/compositor/vertex_descriptor.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
BoxPrimitive::BoxPrimitive(std::shared_ptr<Context> context)
|
||||
: Primitive(context) {
|
||||
using Builder = PipelineBuilder<BoxVertexShader, BoxFragmentShader>;
|
||||
auto pipeline_descriptor = Builder::MakeDefaultPipelineDescriptor(*context);
|
||||
if (!pipeline_descriptor.has_value()) {
|
||||
return;
|
||||
}
|
||||
pipeline_ = context->GetPipelineLibrary()
|
||||
->GetRenderPipeline(pipeline_descriptor.value())
|
||||
.get();
|
||||
if (!pipeline_) {
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
size_t BoxPrimitive::GetVertexBufferIndex() const {
|
||||
return vertex_buffer_index_;
|
||||
}
|
||||
|
||||
BoxPrimitive::~BoxPrimitive() = default;
|
||||
|
||||
std::shared_ptr<Pipeline> BoxPrimitive::GetPipeline() const {
|
||||
return pipeline_;
|
||||
}
|
||||
|
||||
bool BoxPrimitive::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool BoxPrimitive::Encode(RenderPass& pass) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
Reference in New Issue
Block a user