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
6 changes: 4 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1626,14 +1626,15 @@ ORIGIN: ../../../flutter/impeller/scene/mesh.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/mesh.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/node.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/node.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/pipeline_key.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene_context.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene_context.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene_encoder.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/scene_encoder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/shaders/geometry.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/shaders/unlit.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/scene/shaders/unskinned.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4075,14 +4076,15 @@ FILE: ../../../flutter/impeller/scene/mesh.cc
FILE: ../../../flutter/impeller/scene/mesh.h
FILE: ../../../flutter/impeller/scene/node.cc
FILE: ../../../flutter/impeller/scene/node.h
FILE: ../../../flutter/impeller/scene/pipeline_key.h
FILE: ../../../flutter/impeller/scene/scene.cc
FILE: ../../../flutter/impeller/scene/scene.h
FILE: ../../../flutter/impeller/scene/scene_context.cc
FILE: ../../../flutter/impeller/scene/scene_context.h
FILE: ../../../flutter/impeller/scene/scene_encoder.cc
FILE: ../../../flutter/impeller/scene/scene_encoder.h
FILE: ../../../flutter/impeller/scene/shaders/geometry.vert
FILE: ../../../flutter/impeller/scene/shaders/unlit.frag
FILE: ../../../flutter/impeller/scene/shaders/unskinned.vert
FILE: ../../../flutter/impeller/tessellator/c/tessellator.cc
FILE: ../../../flutter/impeller/tessellator/c/tessellator.h
FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart
Expand Down
1 change: 1 addition & 0 deletions impeller/scene/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impeller_component("scene") {
"mesh.h",
"node.cc",
"node.h",
"pipeline_key.h",
"scene.cc",
"scene.h",
"scene_context.cc",
Expand Down
43 changes: 40 additions & 3 deletions impeller/scene/geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include "impeller/renderer/vertex_buffer.h"
#include "impeller/renderer/vertex_buffer_builder.h"
#include "impeller/scene/importer/scene_flatbuffers.h"
#include "impeller/scene/shaders/geometry.vert.h"
#include "third_party/flatbuffers/include/flatbuffers/vector.h"
#include "impeller/scene/shaders/unskinned.vert.h"

namespace impeller {
namespace scene {
Expand Down Expand Up @@ -111,8 +110,14 @@ void CuboidGeometry::SetSize(Vector3 size) {
size_ = size;
}

// |Geometry|
GeometryType CuboidGeometry::GetGeometryType() const {
return GeometryType::kUnskinned;
}

// |Geometry|
VertexBuffer CuboidGeometry::GetVertexBuffer(Allocator& allocator) const {
VertexBufferBuilder<GeometryVertexShader::PerVertexData, uint16_t> builder;
VertexBufferBuilder<UnskinnedVertexShader::PerVertexData, uint16_t> builder;
// Layout: position, normal, tangent, uv
builder.AddVertices({
// Front.
Expand All @@ -132,6 +137,19 @@ VertexBuffer CuboidGeometry::GetVertexBuffer(Allocator& allocator) const {
return builder.CreateVertexBuffer(allocator);
}

// |Geometry|
void CuboidGeometry::BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
const Matrix& transform,
Command& command) const {
command.BindVertices(
GetVertexBuffer(*scene_context.GetContext()->GetResourceAllocator()));

UnskinnedVertexShader::VertInfo info;
info.mvp = transform;
UnskinnedVertexShader::BindVertInfo(command, buffer.EmplaceUniform(info));
}

//------------------------------------------------------------------------------
/// VertexBufferGeometry
///
Expand All @@ -144,9 +162,28 @@ void VertexBufferGeometry::SetVertexBuffer(VertexBuffer vertex_buffer) {
vertex_buffer_ = std::move(vertex_buffer);
}

// |Geometry|
GeometryType VertexBufferGeometry::GetGeometryType() const {
return GeometryType::kUnskinned;
}

// |Geometry|
VertexBuffer VertexBufferGeometry::GetVertexBuffer(Allocator& allocator) const {
return vertex_buffer_;
}

// |Geometry|
void VertexBufferGeometry::BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
const Matrix& transform,
Command& command) const {
command.BindVertices(
GetVertexBuffer(*scene_context.GetContext()->GetResourceAllocator()));

UnskinnedVertexShader::VertInfo info;
info.mvp = transform;
UnskinnedVertexShader::BindVertInfo(command, buffer.EmplaceUniform(info));
}

} // namespace scene
} // namespace impeller
30 changes: 30 additions & 0 deletions impeller/scene/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
#include <memory>

#include "flutter/fml/macros.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/vector.h"
#include "impeller/renderer/allocator.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/device_buffer.h"
#include "impeller/renderer/host_buffer.h"
#include "impeller/renderer/vertex_buffer.h"
#include "impeller/scene/importer/scene_flatbuffers.h"
#include "impeller/scene/pipeline_key.h"
#include "impeller/scene/scene_context.h"

namespace impeller {
namespace scene {
Expand All @@ -32,7 +37,14 @@ class Geometry {
const fb::MeshPrimitive& mesh,
Allocator& allocator);

virtual GeometryType GetGeometryType() const = 0;

virtual VertexBuffer GetVertexBuffer(Allocator& allocator) const = 0;

virtual void BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
const Matrix& transform,
Command& command) const = 0;
};

class CuboidGeometry final : public Geometry {
Expand All @@ -43,9 +55,18 @@ class CuboidGeometry final : public Geometry {

void SetSize(Vector3 size);

// |Geometry|
GeometryType GetGeometryType() const override;

// |Geometry|
VertexBuffer GetVertexBuffer(Allocator& allocator) const override;

// |Geometry|
void BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
const Matrix& transform,
Command& command) const override;

private:
Vector3 size_;

Expand All @@ -60,9 +81,18 @@ class VertexBufferGeometry final : public Geometry {

void SetVertexBuffer(VertexBuffer vertex_buffer);

// |Geometry|
GeometryType GetGeometryType() const override;

// |Geometry|
VertexBuffer GetVertexBuffer(Allocator& allocator) const override;

// |Geometry|
void BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
const Matrix& transform,
Command& command) const override;

private:
VertexBuffer vertex_buffer_;

Expand Down
21 changes: 9 additions & 12 deletions impeller/scene/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "impeller/renderer/formats.h"
#include "impeller/renderer/sampler_descriptor.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/scene/pipeline_key.h"
#include "impeller/scene/scene_context.h"
#include "impeller/scene/shaders/unlit.frag.h"

Expand Down Expand Up @@ -64,30 +65,27 @@ void UnlitMaterial::SetVertexColorWeight(Scalar weight) {
}

// |Material|
std::shared_ptr<Pipeline<PipelineDescriptor>> UnlitMaterial::GetPipeline(
const SceneContext& scene_context,
const RenderPass& pass) const {
return scene_context.GetUnlitPipeline(GetContextOptions(pass));
MaterialType UnlitMaterial::GetMaterialType() const {
return MaterialType::kUnlit;
}

// |Material|
void UnlitMaterial::BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
Command& command) const {
// Uniform buffer.
UnlitPipeline::FragmentShader::FragInfo info;
UnlitFragmentShader::FragInfo info;
info.color = color_;
info.vertex_color_weight = vertex_color_weight_;
UnlitPipeline::FragmentShader::BindFragInfo(command,
buffer.EmplaceUniform(info));
UnlitFragmentShader::BindFragInfo(command, buffer.EmplaceUniform(info));

// Textures.
SamplerDescriptor sampler_descriptor;
sampler_descriptor.label = "Trilinear";
sampler_descriptor.min_filter = MinMagFilter::kLinear;
sampler_descriptor.mag_filter = MinMagFilter::kLinear;
sampler_descriptor.mip_filter = MipFilter::kLinear;
UnlitPipeline::FragmentShader::BindBaseColorTexture(
UnlitFragmentShader::BindBaseColorTexture(
command,
color_texture_ ? color_texture_ : scene_context.GetPlaceholderTexture(),
scene_context.GetContext()->GetSamplerLibrary()->GetSampler(
Expand Down Expand Up @@ -134,10 +132,9 @@ void StandardMaterial::SetEnvironmentMap(
}

// |Material|
std::shared_ptr<Pipeline<PipelineDescriptor>> StandardMaterial::GetPipeline(
const SceneContext& scene_context,
const RenderPass& pass) const {
return nullptr;
MaterialType StandardMaterial::GetMaterialType() const {
// TODO(bdero): Replace this once a PBR shader has landed.
return MaterialType::kUnlit;
}

// |Material|
Expand Down
18 changes: 7 additions & 11 deletions impeller/scene/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "impeller/renderer/formats.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/texture.h"
#include "impeller/scene/pipeline_key.h"

namespace impeller {
namespace scene {
Expand Down Expand Up @@ -47,16 +48,15 @@ class Material {

void SetTranslucent(bool is_translucent);

virtual std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
const SceneContext& scene_context,
const RenderPass& pass) const = 0;
SceneContextOptions GetContextOptions(const RenderPass& pass) const;

virtual MaterialType GetMaterialType() const = 0;

virtual void BindToCommand(const SceneContext& scene_context,
HostBuffer& buffer,
Command& command) const = 0;

protected:
SceneContextOptions GetContextOptions(const RenderPass& pass) const;

BlendConfig blend_config_;
StencilConfig stencil_config_;
bool is_translucent_ = false;
Expand All @@ -73,9 +73,7 @@ class UnlitMaterial final : public Material {
void SetVertexColorWeight(Scalar weight);

// |Material|
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
const SceneContext& scene_context,
const RenderPass& pass) const override;
MaterialType GetMaterialType() const override;

// |Material|
void BindToCommand(const SceneContext& scene_context,
Expand Down Expand Up @@ -104,9 +102,7 @@ class StandardMaterial final : public Material {
void SetEnvironmentMap(std::shared_ptr<Texture> environment_map);

// |Material|
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
const SceneContext& scene_context,
const RenderPass& pass) const override;
MaterialType GetMaterialType() const override;

// |Material|
void BindToCommand(const SceneContext& scene_context,
Expand Down
41 changes: 41 additions & 0 deletions impeller/scene/pipeline_key.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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/hash_combine.h"

namespace impeller {
namespace scene {

enum class GeometryType {
kUnskinned = 0,
kLastType = kUnskinned,
};
enum class MaterialType {
kUnlit = 0,
kLastType = kUnlit,
};

struct PipelineKey {
GeometryType geometry_type = GeometryType::kUnskinned;
MaterialType material_type = MaterialType::kUnlit;

struct Hash {
constexpr std::size_t operator()(const PipelineKey& o) const {
return fml::HashCombine(o.geometry_type, o.material_type);
}
};

struct Equal {
constexpr bool operator()(const PipelineKey& lhs,
const PipelineKey& rhs) const {
return lhs.geometry_type == rhs.geometry_type &&
lhs.material_type == rhs.material_type;
}
};
};

} // namespace scene
} // namespace impeller
31 changes: 18 additions & 13 deletions impeller/scene/scene_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "impeller/scene/scene_context.h"
#include "impeller/renderer/formats.h"
#include "impeller/scene/material.h"
#include "impeller/scene/shaders/unlit.frag.h"
#include "impeller/scene/shaders/unskinned.vert.h"

namespace impeller {
namespace scene {
Expand All @@ -26,25 +29,15 @@ void SceneContextOptions::ApplyToPipelineDescriptor(
desc.SetPrimitiveType(primitive_type);
}

template <typename PipelineT>
static std::unique_ptr<PipelineT> CreateDefaultPipeline(
const Context& context) {
auto desc = PipelineT::Builder::MakeDefaultPipelineDescriptor(context);
if (!desc.has_value()) {
return nullptr;
}
// Apply default ContentContextOptions to the descriptor.
SceneContextOptions{}.ApplyToPipelineDescriptor(*desc);
return std::make_unique<PipelineT>(context, desc);
}

SceneContext::SceneContext(std::shared_ptr<Context> context)
: context_(std::move(context)) {
if (!context_ || !context_->IsValid()) {
return;
}

unlit_pipeline_[{}] = CreateDefaultPipeline<UnlitPipeline>(*context_);
pipelines_[{PipelineKey{GeometryType::kUnskinned, MaterialType::kUnlit}}] =
MakePipelineVariants<UnskinnedVertexShader, UnlitFragmentShader>(
*context_);

{
impeller::TextureDescriptor texture_descriptor;
Expand Down Expand Up @@ -72,6 +65,18 @@ SceneContext::SceneContext(std::shared_ptr<Context> context)

SceneContext::~SceneContext() = default;

std::shared_ptr<Pipeline<PipelineDescriptor>> SceneContext::GetPipeline(
PipelineKey key,
SceneContextOptions opts) const {
if (!IsValid()) {
return nullptr;
}
if (auto found = pipelines_.find(key); found != pipelines_.end()) {
return found->second->GetPipeline(opts);
}
return nullptr;
}

bool SceneContext::IsValid() const {
return is_valid_;
}
Expand Down
Loading