More doc updates.

This commit is contained in:
Chinmay Garde
2021-11-03 13:55:20 -07:00
committed by Dan Field
parent 24f28685fe
commit 351bb6d019
9 changed files with 74 additions and 13 deletions

View File

@@ -51,13 +51,12 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer,
auto vertices_builder = VertexBufferBuilder<VS::PerVertexData>();
{
auto result =
Tessellator{}.Tessellate(entity.GetPath().SubdivideAdaptively(),
[&vertices_builder](Point point) {
VS::PerVertexData vtx;
vtx.vertices = point;
vertices_builder.AppendVertex(vtx);
});
auto result = Tessellator{}.Tessellate(entity.GetPath().CreatePolyline(),
[&vertices_builder](Point point) {
VS::PerVertexData vtx;
vtx.vertices = point;
vertices_builder.AppendVertex(vtx);
});
if (!result) {
return false;
}

View File

@@ -53,7 +53,7 @@ EntityRendererImpl::RenderResult EntityRendererImpl::RenderEntity(
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
{
auto tesselation_result = Tessellator{}.Tessellate(
entity.GetPath().SubdivideAdaptively(), [&vtx_builder](auto point) {
entity.GetPath().CreatePolyline(), [&vtx_builder](auto point) {
VS::PerVertexData vtx;
vtx.vertices = point;
vtx_builder.AppendVertex(vtx);

View File

@@ -12,6 +12,8 @@ impeller_shaders("shader_fixtures") {
shaders = [
"box_fade.vert",
"box_fade.frag",
"sandbox.vert",
"sandbox.frag",
]
}

View File

@@ -149,7 +149,7 @@ static void AddPoints(std::vector<Point>& dest, const std::vector<Point>& src) {
dest.insert(dest.end(), src.begin(), src.end());
}
std::vector<Point> Path::SubdivideAdaptively(
std::vector<Point> Path::CreatePolyline(
const SmoothingApproximation& approximation) const {
std::vector<Point> points;
for (const auto& component : components_) {

View File

@@ -53,7 +53,7 @@ class Path {
bool UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic);
std::vector<Point> SubdivideAdaptively(
std::vector<Point> CreatePolyline(
const SmoothingApproximation& approximation = {}) const;
Rect GetBoundingBox() const;

View File

@@ -26,10 +26,41 @@ struct Bindings {
std::map<size_t, std::shared_ptr<const Sampler>> samplers;
};
//------------------------------------------------------------------------------
/// @brief An object used to specify work to the GPU along with references
/// to resources the GPU will used when doing said work.
///
/// To construct a valid command, follow these steps:
/// * Specify a valid pipeline.
/// * Specify vertex information via a call `BindVertices`
/// * Specify any stage bindings.
/// * (Optional) Specify a debug label.
///
/// Command are very lightweight objects and can be created
/// frequently and on demand. The resources referenced in commands
/// views into buffers managed by other allocators and resource
/// managers.
///
struct Command {
//----------------------------------------------------------------------------
/// The pipeline to use for this command.
///
std::shared_ptr<Pipeline> pipeline;
//----------------------------------------------------------------------------
/// The buffer, texture, and sampler bindings used by the vertex pipeline
/// stage.
///
Bindings vertex_bindings;
//----------------------------------------------------------------------------
/// The buffer, texture, and sampler bindings used by the fragment pipeline
/// stage.
///
Bindings fragment_bindings;
//----------------------------------------------------------------------------
/// The index buffer binding used by the vertex shader stage. Instead of
/// setting this directly, it usually easier to specify the vertex and index
/// buffer bindings directly via a single call to `BindVertices`.
///
BufferView index_buffer;
size_t index_count = 0u;
std::string label;

View File

@@ -17,6 +17,20 @@ class Pipeline;
using PipelineFuture = std::future<std::shared_ptr<Pipeline>>;
//------------------------------------------------------------------------------
/// @brief Describes the fixed function and programmable aspects of
/// rendering and compute operations performed by commands submitted
/// to the GPU via a command buffer.
///
/// A pipeline handle must be allocated upfront and kept alive for
/// as long as possible. Do not create a pipeline object within a
/// frame workload.
///
/// This pipeline object is almost never used directly as it is
/// untyped. Use reflected shader information generated by the
/// Impeller offline shader compiler to generate a typed pipeline
/// object.
///
class Pipeline {
public:
enum class Type {

View File

@@ -269,7 +269,7 @@ TEST_F(RendererTest, CanRenderPath) {
Tessellator tessellator;
ASSERT_TRUE(tessellator.Tessellate(
path.SubdivideAdaptively({}), [&vertex_builder](Point point) {
path.CreatePolyline({}), [&vertex_builder](Point point) {
VS::PerVertexData vtx;
vtx.vertex_position = {point.x, point.y, 0.0};
vtx.texture_coordinates = {0.5, 0.5};

View File

@@ -13,6 +13,12 @@
namespace impeller {
//------------------------------------------------------------------------------
/// @brief A utility that generates triangles of the specified fill type
/// given a polyline. This happens on the CPU.
///
/// @bug This should just be called a triangulator.
///
class Tessellator {
public:
enum class FillType {
@@ -34,8 +40,17 @@ class Tessellator {
WindingOrder GetFrontFaceWinding() const;
using VertexCallback = std::function<void(Point)>;
[[nodiscard]] bool Tessellate(const std::vector<Point>& vertices,
VertexCallback callback) const;
//----------------------------------------------------------------------------
/// @brief Generates triangles from the polyline. A callback is invoked
/// for each vertex of the triangle.
///
/// @param[in] polyline The polyline
/// @param[in] callback The callback
///
/// @return If tessellation was successful.
///
bool Tessellate(const std::vector<Point>& polyline,
VertexCallback callback) const;
private:
FillType fill_type_ = FillType::kNonZero;