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
26 changes: 17 additions & 9 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ bool ClipContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = ClipPipeline::VertexShader;
using FS = ClipPipeline::FragmentShader;

VS::FrameInfo info;
// The color really doesn't matter.
info.color = Color::SkyBlue();
VS::VertInfo info;

Command cmd;

FS::FragInfo frag_info;
// The color really doesn't matter.
frag_info.color = Color::SkyBlue();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

auto options = OptionsFromPassAndEntity(pass, entity);
cmd.stencil_reference = entity.GetStencilDepth();
options.stencil_compare = CompareFunction::kEqual;
Expand All @@ -69,7 +74,7 @@ bool ClipContents::Render(const ContentContext& renderer,
cmd.BindVertices(std::move(vertices));

info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

cmd.pipeline = renderer.GetClipPipeline(options);
pass.AddCommand(cmd);
Expand All @@ -95,7 +100,7 @@ bool ClipContents::Render(const ContentContext& renderer,

info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

pass.AddCommand(std::move(cmd));
return true;
Expand Down Expand Up @@ -123,6 +128,7 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = ClipPipeline::VertexShader;
using FS = ClipPipeline::FragmentShader;

Command cmd;
cmd.label = "Restore Clip";
Expand All @@ -145,12 +151,14 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
});
cmd.BindVertices(vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer()));

VS::FrameInfo info;
// The color really doesn't matter.
info.color = Color::SkyBlue();
VS::VertInfo info;
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
FS::FragInfo frag_info;
// The color really doesn't matter.
frag_info.color = Color::SkyBlue();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

pass.AddCommand(std::move(cmd));
return true;
Expand Down
21 changes: 11 additions & 10 deletions impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ VertexBuffer SolidColorContents::CreateSolidFillVertices(const Path& path,
VertexBufferBuilder<VS::PerVertexData> vtx_builder;

auto tesselation_result = Tessellator{}.Tessellate(
path.GetFillType(), path.CreatePolyline(), [&vtx_builder](auto point) {
VS::PerVertexData vtx;
vtx.vertices = point;
vtx_builder.AppendVertex(vtx);
});
path.GetFillType(), path.CreatePolyline(),
[&vtx_builder](auto point) { vtx_builder.AppendVertex({point}); });
if (tesselation_result != Tessellator::Result::kSuccess) {
return {};
}
Expand All @@ -64,6 +61,7 @@ bool SolidColorContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = SolidFillPipeline::VertexShader;
using FS = SolidFillPipeline::FragmentShader;

Command cmd;
cmd.label = "Solid Fill";
Expand All @@ -77,11 +75,14 @@ bool SolidColorContents::Render(const ContentContext& renderer,
: path_,
pass.GetTransientsBuffer()));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.color = color_.Premultiply();
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
VS::VertInfo vert_info;
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(vert_info));

FS::FragInfo frag_info;
frag_info.color = color_.Premultiply();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

cmd.primitive_type = PrimitiveType::kTriangle;

Expand Down
74 changes: 39 additions & 35 deletions impeller/entity/contents/solid_stroke_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static VertexBuffer CreateSolidStrokeVertices(
// We're drawing a triangle strip, so we need to "pick up the pen" by
// appending transparent vertices between the end of the previous contour
// and the beginning of the new contour.
vtx.vertex_position = polyline.points[contour_start_point_i - 1];
vtx.vertex_normal = {};
vtx.position = polyline.points[contour_start_point_i - 1];
vtx.normal = {};
vtx.pen_down = 0.0;
// Append two transparent vertices when "picking up" the pen so that the
// triangle drawn when moving to the beginning of the new contour will
Expand All @@ -119,7 +119,7 @@ static VertexBuffer CreateSolidStrokeVertices(
vtx_builder.AppendVertex(vtx);
vtx_builder.AppendVertex(vtx);

vtx.vertex_position = polyline.points[contour_start_point_i];
vtx.position = polyline.points[contour_start_point_i];
// Append two vertices at the beginning of the new contour
// so that the next appended vertex will create a triangle with zero
// volume.
Expand All @@ -139,16 +139,16 @@ static VertexBuffer CreateSolidStrokeVertices(
point_i++) {
if (point_i > contour_start_point_i) {
// Generate line rect.
vtx.vertex_position = polyline.points[point_i - 1];
vtx.position = polyline.points[point_i - 1];
vtx.pen_down = 1.0;
vtx.vertex_normal = normal;
vtx.normal = normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = -normal;
vtx.normal = -normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_position = polyline.points[point_i];
vtx.vertex_normal = normal;
vtx.position = polyline.points[point_i];
vtx.normal = normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = -normal;
vtx.normal = -normal;
vtx_builder.AppendVertex(vtx);

if (point_i < contour_end_point_i - 1) {
Expand Down Expand Up @@ -181,13 +181,16 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
return true;
}

using VS = SolidStrokeVertexShader;
using VS = SolidStrokePipeline::VertexShader;
using FS = SolidStrokePipeline::FragmentShader;

VS::VertInfo vert_info;
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
vert_info.size = stroke_size_;

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.color = color_.Premultiply();
frame_info.size = stroke_size_;
FS::FragInfo frag_info;
frag_info.color = color_.Premultiply();

Command cmd;
cmd.primitive_type = PrimitiveType::kTriangleStrip;
Expand All @@ -206,7 +209,8 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
cmd.BindVertices(CreateSolidStrokeVertices(path_, pass.GetTransientsBuffer(),
cap_proc_, join_proc_,
miter_limit_, smoothing));
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
VS::BindVertInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(vert_info));
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

pass.AddCommand(cmd);

Expand Down Expand Up @@ -251,7 +255,7 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
const Point& position, const Point& normal,
const SmoothingApproximation& smoothing) {
SolidStrokeVertexShader::PerVertexData vtx;
vtx.vertex_position = position;
vtx.position = position;
vtx.pen_down = 1.0;

Point forward(normal.y, -normal.x);
Expand All @@ -262,14 +266,14 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
forward + normal * PathBuilder::kArcApproximationMagic, forward)
.CreatePolyline(smoothing);

vtx.vertex_normal = normal;
vtx.normal = normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = -normal;
vtx.normal = -normal;
vtx_builder.AppendVertex(vtx);
for (const auto& point : arc_points) {
vtx.vertex_normal = point;
vtx.normal = point;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = (-point).Reflect(forward);
vtx.normal = (-point).Reflect(forward);
vtx_builder.AppendVertex(vtx);
}
};
Expand All @@ -279,18 +283,18 @@ void SolidStrokeContents::SetStrokeCap(Cap cap) {
const Point& position, const Point& normal,
const SmoothingApproximation& smoothing) {
SolidStrokeVertexShader::PerVertexData vtx;
vtx.vertex_position = position;
vtx.position = position;
vtx.pen_down = 1.0;

Point forward(normal.y, -normal.x);

vtx.vertex_normal = normal;
vtx.normal = normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = -normal;
vtx.normal = -normal;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = normal + forward;
vtx.normal = normal + forward;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = -normal + forward;
vtx.normal = -normal + forward;
vtx_builder.AppendVertex(vtx);
};
break;
Expand All @@ -307,15 +311,15 @@ static Scalar CreateBevelAndGetDirection(
const Point& start_normal,
const Point& end_normal) {
SolidStrokeVertexShader::PerVertexData vtx;
vtx.vertex_position = position;
vtx.position = position;
vtx.pen_down = 1.0;
vtx.vertex_normal = {};
vtx.normal = {};
vtx_builder.AppendVertex(vtx);

Scalar dir = start_normal.Cross(end_normal) > 0 ? -1 : 1;
vtx.vertex_normal = start_normal * dir;
vtx.normal = start_normal * dir;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = end_normal * dir;
vtx.normal = end_normal * dir;
vtx_builder.AppendVertex(vtx);

return dir;
Expand Down Expand Up @@ -357,9 +361,9 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {

// Outer miter point.
SolidStrokeVertexShader::PerVertexData vtx;
vtx.vertex_position = position;
vtx.position = position;
vtx.pen_down = 1.0;
vtx.vertex_normal = miter_point * dir;
vtx.normal = miter_point * dir;
vtx_builder.AppendVertex(vtx);
};
break;
Expand Down Expand Up @@ -391,12 +395,12 @@ void SolidStrokeContents::SetStrokeJoin(Join join) {
.CreatePolyline(smoothing);

SolidStrokeVertexShader::PerVertexData vtx;
vtx.vertex_position = position;
vtx.position = position;
vtx.pen_down = 1.0;
for (const auto& point : arc_points) {
vtx.vertex_normal = point * dir;
vtx.normal = point * dir;
vtx_builder.AppendVertex(vtx);
vtx.vertex_normal = (-point * dir).Reflect(middle);
vtx.normal = (-point * dir).Reflect(middle);
vtx_builder.AppendVertex(vtx);
}
};
Expand Down
12 changes: 6 additions & 6 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool TextureContents::Render(const ContentContext& renderer,
path_.GetFillType(), path_.CreatePolyline(),
[this, &vertex_builder, &coverage_rect, &texture_size](Point vtx) {
VS::PerVertexData data;
data.vertices = vtx;
data.position = vtx;
auto coverage_coords =
(vtx - coverage_rect->origin) / coverage_rect->size;
data.texture_coords =
Expand All @@ -101,21 +101,21 @@ bool TextureContents::Render(const ContentContext& renderer,

auto& host_buffer = pass.GetTransientsBuffer();

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.alpha = opacity_;
VS::VertInfo vert_info;
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();

FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frag_info.alpha = opacity_;

Command cmd;
cmd.label = "TextureFill";
cmd.pipeline =
renderer.GetTexturePipeline(OptionsFromPassAndEntity(pass, entity));
cmd.stencil_reference = entity.GetStencilDepth();
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
VS::BindVertInfo(cmd, host_buffer.EmplaceUniform(vert_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
FS::BindTextureSampler(cmd, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
Expand Down
14 changes: 10 additions & 4 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ TEST_P(EntityTest, BlendingModeOptions) {
Rect rect, Color color,
Entity::BlendMode blend_mode) -> bool {
using VS = SolidFillPipeline::VertexShader;
using FS = SolidFillPipeline::FragmentShader;

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
{
auto r = rect.GetLTRB();
Expand All @@ -729,12 +731,16 @@ TEST_P(EntityTest, BlendingModeOptions) {
cmd.BindVertices(
vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer()));

VS::FrameInfo frame_info;
VS::VertInfo frame_info;
frame_info.mvp =
Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * world_matrix;
frame_info.color = color.Premultiply();
VS::BindFrameInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(frame_info));
VS::BindVertInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.color = color.Premultiply();
FS::BindFragInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(frag_info));

cmd.primitive_type = PrimitiveType::kTriangle;

Expand Down
7 changes: 5 additions & 2 deletions impeller/entity/shaders/solid_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

in vec4 color;
uniform FragInfo {
vec4 color;
}
frag_info;

out vec4 frag_color;

void main() {
frag_color = color;
frag_color = frag_info.color;
}
13 changes: 5 additions & 8 deletions impeller/entity/shaders/solid_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

uniform FrameInfo {
uniform VertInfo {
mat4 mvp;
vec4 color;
} frame_info;

in vec2 vertices;
}
vert_info;

out vec4 color;
in vec2 position;

void main() {
gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0);
color = frame_info.color;
gl_Position = vert_info.mvp * vec4(position, 0.0, 1.0);
}
Loading