mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Start on the entity model.
This commit is contained in:
parent
7a036de8de
commit
ddcc21abdc
@ -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",
|
||||
|
||||
32
engine/src/flutter/impeller/compositor/command.h
Normal file
32
engine/src/flutter/impeller/compositor/command.h
Normal 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
|
||||
7
engine/src/flutter/impeller/compositor/command.mm
Normal file
7
engine/src/flutter/impeller/compositor/command.mm
Normal 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
|
||||
@ -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_;
|
||||
|
||||
@ -38,7 +38,8 @@ bool Renderer::SurfaceSizeDidChange(Size size) {
|
||||
}
|
||||
|
||||
size_ = size;
|
||||
return true;
|
||||
|
||||
return OnSurfaceSizeDidChange(size_);
|
||||
}
|
||||
|
||||
bool Renderer::Render() {
|
||||
|
||||
21
engine/src/flutter/impeller/compositor/sampler.h
Normal file
21
engine/src/flutter/impeller/compositor/sampler.h
Normal 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
|
||||
@ -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
|
||||
@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@ -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"
|
||||
|
||||
29
engine/src/flutter/impeller/entity/entity_renderer.h
Normal file
29
engine/src/flutter/impeller/entity/entity_renderer.h
Normal 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
|
||||
23
engine/src/flutter/impeller/entity/entity_renderer.mm
Normal file
23
engine/src/flutter/impeller/entity/entity_renderer.mm
Normal 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
|
||||
@ -46,6 +46,7 @@ executable("host") {
|
||||
deps = [
|
||||
":impeller_host_fixtures",
|
||||
":impeller_host_shaders",
|
||||
"../entity",
|
||||
"../primitives",
|
||||
"//flutter/fml",
|
||||
]
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -12,5 +12,7 @@ impeller_component("image") {
|
||||
"image_result.h",
|
||||
]
|
||||
|
||||
deps = [ "../third_party/stb" ]
|
||||
|
||||
public_deps = [ "../geometry" ]
|
||||
}
|
||||
|
||||
@ -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" ]
|
||||
|
||||
26
engine/src/flutter/impeller/primitives/box_primitive.h
Normal file
26
engine/src/flutter/impeller/primitives/box_primitive.h
Normal 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
|
||||
@ -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
|
||||
31
engine/src/flutter/impeller/primitives/primitive.h
Normal file
31
engine/src/flutter/impeller/primitives/primitive.h
Normal 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
|
||||
18
engine/src/flutter/impeller/primitives/primitive.mm
Normal file
18
engine/src/flutter/impeller/primitives/primitive.mm
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user