Start on the entity model.

This commit is contained in:
Chinmay Garde 2021-06-04 16:27:02 -07:00 committed by Dan Field
parent 7a036de8de
commit ddcc21abdc
19 changed files with 242 additions and 30 deletions

View File

@ -10,6 +10,8 @@ impeller_component("compositor") {
"allocator.mm",
"buffer.h",
"buffer.mm",
"command.h",
"command.mm",
"comparable.cc",
"comparable.h",
"context.h",
@ -30,6 +32,8 @@ impeller_component("compositor") {
"render_pass.mm",
"renderer.h",
"renderer.mm",
"sampler.h",
"sampler.mm",
"shader_function.h",
"shader_function.mm",
"shader_library.h",

View File

@ -0,0 +1,32 @@
// 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 <map>
#include <memory>
#include "flutter/fml/macros.h"
#include "impeller/compositor/buffer.h"
#include "impeller/compositor/pipeline.h"
namespace impeller {
class Texture;
class Sampler;
struct Bindings {
std::map<size_t, BufferView> buffers;
std::map<size_t, std::shared_ptr<Texture>> textures;
std::map<size_t, std::shared_ptr<Texture>> samplers;
};
struct Command {
std::shared_ptr<Pipeline> pipeline;
Bindings vertex_bindings;
Bindings fragment_bindings;
BufferView index_buffer;
};
} // namespace impeller

View File

@ -0,0 +1,7 @@
// 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/compositor/command.h"
namespace impeller {} // namespace impeller

View File

@ -15,9 +15,7 @@ namespace impeller {
class Renderer {
public:
Renderer(std::string shaders_directory);
~Renderer();
virtual ~Renderer();
bool IsValid() const;
@ -27,6 +25,13 @@ class Renderer {
std::shared_ptr<Context> GetContext() const;
protected:
Renderer(std::string shaders_directory);
virtual bool OnRender() = 0;
virtual bool OnSurfaceSizeDidChange(Size size) = 0;
private:
std::shared_ptr<Context> context_;
std::unique_ptr<Surface> surface_;

View File

@ -38,7 +38,8 @@ bool Renderer::SurfaceSizeDidChange(Size size) {
}
size_ = size;
return true;
return OnSurfaceSizeDidChange(size_);
}
bool Renderer::Render() {

View File

@ -0,0 +1,21 @@
// 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 "flutter/fml/macros.h"
namespace impeller {
class Sampler {
public:
Sampler();
~Sampler();
private:
FML_DISALLOW_COPY_AND_ASSIGN(Sampler);
};
} // namespace impeller

View File

@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/compositor/context.h"
#include "impeller/compositor/sampler.h"
namespace impeller {
bool RenderBox(std::shared_ptr<Context> context);
Sampler::Sampler() = default;
Sampler::~Sampler() = default;
} // namespace impeller

View File

@ -8,7 +8,12 @@ impeller_component("entity") {
sources = [
"entity.cc",
"entity.h",
"entity_renderer.h",
"entity_renderer.mm",
]
public_deps = [ "../image" ]
public_deps = [
"../compositor",
"../image",
]
}

View File

@ -4,7 +4,7 @@
#pragma once
#include "impeller/entity/color.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/rect.h"

View File

@ -0,0 +1,29 @@
// 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 "flutter/fml/macros.h"
#include "impeller/compositor/renderer.h"
#include "impeller/entity/entity.h"
namespace impeller {
class EntityRenderer final : public Renderer {
public:
EntityRenderer(std::string shaders_directory);
~EntityRenderer() override;
private:
std::shared_ptr<Entity> root_;
bool OnRender() override;
bool OnSurfaceSizeDidChange(Size size) override;
FML_DISALLOW_COPY_AND_ASSIGN(EntityRenderer);
};
} // namespace impeller

View File

@ -0,0 +1,23 @@
// 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/entity/entity_renderer.h"
namespace impeller {
EntityRenderer::EntityRenderer(std::string shaders_directory)
: Renderer(std::move(shaders_directory)),
root_(std::make_shared<Entity>()) {}
EntityRenderer::~EntityRenderer() = default;
bool EntityRenderer::OnRender() {
return false;
}
bool EntityRenderer::OnSurfaceSizeDidChange(Size size) {
return false;
}
} // namespace impeller

View File

@ -46,6 +46,7 @@ executable("host") {
deps = [
":impeller_host_fixtures",
":impeller_host_shaders",
"../entity",
"../primitives",
"//flutter/fml",
]

View File

@ -4,17 +4,15 @@
#import <ModelIO/ModelIO.h>
#import <simd/simd.h>
#import "assets_location.h"
#include "flutter/fml/logging.h"
#import "impeller/compositor/renderer.h"
#import "impeller/primitives/box.h"
#import "impeller_renderer.h"
#import "shaders_location.h"
// Include header shared between C code here, which executes Metal API commands,
// and .metal files
#import "ShaderTypes.h"
#include "assets_location.h"
#include "flutter/fml/logging.h"
#include "impeller/entity/entity_renderer.h"
#include "impeller/primitives/box_primitive.h"
#include "impeller_renderer.h"
#include "shaders_location.h"
static const NSUInteger kMaxBuffersInFlight = 3;
static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100;
@ -53,17 +51,13 @@ static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100;
[self _loadAssets];
}
renderer_ = std::make_unique<impeller::Renderer>(
renderer_ = std::make_unique<impeller::EntityRenderer>(
impeller::ImpellerShadersDirectory());
if (!renderer_->IsValid()) {
FML_LOG(ERROR) << "Impeller Renderer is not valid.";
}
if (!impeller::RenderBox(renderer_->GetContext())) {
FML_LOG(ERROR) << "Could not render box.";
}
return self;
}
@ -233,7 +227,9 @@ static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100;
}
- (void)drawInMTKView:(nonnull MTKView*)view {
renderer_->Render();
if (!renderer_->Render()) {
FML_LOG(ERROR) << "Could not render.";
}
/// Per frame updates here
dispatch_semaphore_wait(_inFlightSemaphore, DISPATCH_TIME_FOREVER);

View File

@ -12,5 +12,7 @@ impeller_component("image") {
"image_result.h",
]
deps = [ "../third_party/stb" ]
public_deps = [ "../geometry" ]
}

View File

@ -14,8 +14,10 @@ impeller_shaders("impeller_shaders") {
impeller_component("primitives") {
sources = [
"box.h",
"box.mm",
"box_primitive.h",
"box_primitive.mm",
"primitive.h",
"primitive.mm",
]
public_deps = [ "../compositor" ]

View File

@ -0,0 +1,26 @@
// 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/compositor/context.h"
#include "impeller/primitives/primitive.h"
namespace impeller {
class BoxPrimitive final : public Primitive {
public:
BoxPrimitive(std::shared_ptr<Context> context);
~BoxPrimitive() override;
virtual bool Encode(RenderPass& pass) const override;
private:
bool is_valid_ = false;
FML_DISALLOW_COPY_AND_ASSIGN(BoxPrimitive);
};
bool RenderBox(std::shared_ptr<Context> context);
} // namespace impeller

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/primitives/box.h"
#include "impeller/primitives/box_primitive.h"
#include <memory>
@ -15,7 +15,8 @@
namespace impeller {
bool RenderBox(std::shared_ptr<Context> context) {
BoxPrimitive::BoxPrimitive(std::shared_ptr<Context> context)
: Primitive(context) {
PipelineDescriptor desc;
desc.SetLabel(shader::BoxVertexInfo::kLabel);
@ -34,7 +35,7 @@ bool RenderBox(std::shared_ptr<Context> context) {
if (!vertex_descriptor->SetStageInputs(
shader::BoxVertexInfo::kAllShaderStageInputs)) {
FML_LOG(ERROR) << "Could not configure vertex descriptor.";
return false;
return;
}
desc.SetVertexDescriptor(std::move(vertex_descriptor));
}
@ -43,10 +44,16 @@ bool RenderBox(std::shared_ptr<Context> context) {
context->GetPipelineLibrary()->GetRenderPipeline(std::move(desc)).get();
if (!pipeline) {
FML_LOG(ERROR) << "Could not create the render pipeline.";
return false;
return;
}
return true;
is_valid_ = true;
}
BoxPrimitive::~BoxPrimitive() = default;
bool BoxPrimitive::Encode(RenderPass& pass) const {
return false;
}
} // namespace impeller

View File

@ -0,0 +1,31 @@
// 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 <memory>
#include "flutter/fml/macros.h"
#include "impeller/compositor/context.h"
#include "impeller/compositor/render_pass.h"
namespace impeller {
class Primitive {
public:
Primitive(std::shared_ptr<Context>);
virtual ~Primitive();
std::shared_ptr<Context> GetContext() const;
virtual bool Encode(RenderPass& pass) const = 0;
private:
std::shared_ptr<Context> context_;
FML_DISALLOW_COPY_AND_ASSIGN(Primitive);
};
} // namespace impeller

View File

@ -0,0 +1,18 @@
// 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/primitive.h"
namespace impeller {
Primitive::Primitive(std::shared_ptr<Context> context)
: context_(std::move(context)) {}
Primitive::~Primitive() = default;
std::shared_ptr<Context> Primitive::GetContext() const {
return context_;
}
} // namespace impeller