[Impeller] Clean up fill shaders (flutter/engine#34739)
This commit is contained in:
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
@@ -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";
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {};
|
||||
}
|
||||
@@ -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";
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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) {
|
||||
@@ -181,13 +181,16 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
|
||||
return true;
|
||||
}
|
||||
|
||||
using VS = SolidStrokeVertexShader;
|
||||
using VS = SolidStrokePipeline::VertexShader;
|
||||
using FS = SolidStrokePipeline::FragmentShader;
|
||||
|
||||
VS::FrameInfo frame_info;
|
||||
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
frame_info.color = color_.Premultiply();
|
||||
frame_info.size = stroke_size_;
|
||||
VS::VertInfo vert_info;
|
||||
vert_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
|
||||
entity.GetTransformation();
|
||||
vert_info.size = stroke_size_;
|
||||
|
||||
FS::FragInfo frag_info;
|
||||
frag_info.color = color_.Premultiply();
|
||||
|
||||
Command cmd;
|
||||
cmd.primitive_type = PrimitiveType::kTriangleStrip;
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 =
|
||||
@@ -101,13 +101,13 @@ 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";
|
||||
@@ -115,7 +115,7 @@ bool TextureContents::Render(const ContentContext& renderer,
|
||||
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(
|
||||
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
vert_info;
|
||||
|
||||
in vec2 vertices;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
in vec4 stroke_color;
|
||||
uniform FragInfo {
|
||||
vec4 color;
|
||||
}
|
||||
frag_info;
|
||||
|
||||
in float v_pen_down;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
frag_color = stroke_color * floor(v_pen_down);
|
||||
frag_color = frag_info.color * floor(v_pen_down);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,21 @@
|
||||
// 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;
|
||||
float size;
|
||||
} frame_info;
|
||||
}
|
||||
vert_info;
|
||||
|
||||
in vec2 vertex_position;
|
||||
in vec2 vertex_normal;
|
||||
in vec2 position;
|
||||
in vec2 normal;
|
||||
in float pen_down;
|
||||
|
||||
out vec4 stroke_color;
|
||||
out float v_pen_down;
|
||||
|
||||
void main() {
|
||||
// Push one vertex by the half stroke size along the normal vector.
|
||||
vec2 offset = vertex_normal * vec2(frame_info.size * 0.5);
|
||||
gl_Position = frame_info.mvp * vec4(vertex_position + offset, 0.0, 1.0);
|
||||
stroke_color = frame_info.color;
|
||||
vec2 offset = normal * vec2(vert_info.size * 0.5);
|
||||
gl_Position = vert_info.mvp * vec4(position + offset, 0.0, 1.0);
|
||||
v_pen_down = pen_down;
|
||||
}
|
||||
|
||||
@@ -5,18 +5,19 @@
|
||||
#include <impeller/texture.glsl>
|
||||
|
||||
uniform sampler2D texture_sampler;
|
||||
|
||||
uniform FragInfo {
|
||||
float texture_sampler_y_coord_scale;
|
||||
float alpha;
|
||||
}
|
||||
frag_info;
|
||||
|
||||
in vec2 v_texture_coords;
|
||||
in float v_alpha;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
vec4 sampled = IPSample(texture_sampler, v_texture_coords,
|
||||
frag_info.texture_sampler_y_coord_scale);
|
||||
frag_color = sampled * v_alpha;
|
||||
frag_color = sampled * frag_info.alpha;
|
||||
}
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
// 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;
|
||||
float alpha;
|
||||
} frame_info;
|
||||
}
|
||||
vert_info;
|
||||
|
||||
in vec2 vertices;
|
||||
in vec2 position;
|
||||
in vec2 texture_coords;
|
||||
|
||||
out vec2 v_texture_coords;
|
||||
out float v_alpha;
|
||||
|
||||
void main() {
|
||||
gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0);
|
||||
gl_Position = vert_info.mvp * vec4(position, 0.0, 1.0);
|
||||
v_texture_coords = texture_coords;
|
||||
v_alpha = frame_info.alpha;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user