18 blend_mode_ = blend_mode;
22 std::shared_ptr<Contents> child_contents) {
23 child_contents_ = std::move(child_contents);
27 std::optional<Rect> FramebufferBlendContents::GetCoverage(
28 const Entity& entity)
const {
29 return child_contents_->GetCoverage(entity);
32 bool FramebufferBlendContents::Render(
const ContentContext& renderer,
34 RenderPass& pass)
const {
35 if (!renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
42 auto& host_buffer = pass.GetTransientsBuffer();
44 auto src_snapshot = child_contents_->RenderToSnapshot(
50 "FramebufferBlendContents Snapshot");
52 if (!src_snapshot.has_value()) {
55 auto coverage = src_snapshot->GetCoverage();
56 if (!coverage.has_value()) {
59 Rect src_coverage = coverage.value();
61 auto size = src_coverage.
size;
62 VertexBufferBuilder<VS::PerVertexData> vtx_builder;
63 vtx_builder.AddVertices({
71 auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
78 cmd.BindVertices(vtx_buffer);
79 cmd.stencil_reference = entity.GetStencilDepth();
81 switch (blend_mode_) {
83 cmd.pipeline = renderer.GetFramebufferBlendScreenPipeline(options);
86 cmd.pipeline = renderer.GetFramebufferBlendOverlayPipeline(options);
89 cmd.pipeline = renderer.GetFramebufferBlendDarkenPipeline(options);
92 cmd.pipeline = renderer.GetFramebufferBlendLightenPipeline(options);
95 cmd.pipeline = renderer.GetFramebufferBlendColorDodgePipeline(options);
98 cmd.pipeline = renderer.GetFramebufferBlendColorBurnPipeline(options);
101 cmd.pipeline = renderer.GetFramebufferBlendHardLightPipeline(options);
104 cmd.pipeline = renderer.GetFramebufferBlendSoftLightPipeline(options);
107 cmd.pipeline = renderer.GetFramebufferBlendDifferencePipeline(options);
110 cmd.pipeline = renderer.GetFramebufferBlendExclusionPipeline(options);
113 cmd.pipeline = renderer.GetFramebufferBlendMultiplyPipeline(options);
116 cmd.pipeline = renderer.GetFramebufferBlendHuePipeline(options);
119 cmd.pipeline = renderer.GetFramebufferBlendSaturationPipeline(options);
122 cmd.pipeline = renderer.GetFramebufferBlendColorPipeline(options);
125 cmd.pipeline = renderer.GetFramebufferBlendLuminosityPipeline(options);
131 VS::FrameInfo frame_info;
132 FS::FragInfo frag_info;
134 auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
135 if (!renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
141 auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
142 src_sampler_descriptor);
143 FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
146 src_snapshot->transform;
147 frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
148 VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
150 frag_info.src_input_alpha = src_snapshot->opacity;
151 FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
153 return pass.AddCommand(std::move(cmd));