Skip to content

Conversation

@wenjieshen
Copy link
Collaborator

@wenjieshen wenjieshen commented Dec 9, 2025

Replace GlSimpleBlendTask with GlDirectBlendTask to perform blending directly in the shape shader without a separate compose pass. This copies only the required destination region and blends in a single draw.

  • Introduced GlDirectBlendTask to blit the destination region and run shape blends directly instead of using the old compose path.
  • Added shape-oriented blend programs (solid, linear, radial) selected via BlendSource and new shader headers with BlendRegion uniforms.
  • Extracted reusable gradient helper functions to keep shader mains minimal while supplying the new blend shaders.
  • Remove redundant blend shader headers

Render to texture

There are two textures. The source texture has been anti-aliased, which causes a halo effect due to its softened edges.
Screenshot 2025-12-08 214536

Direct blending

There is only one textue. The MSAA is resolved after blending.
Screenshot 2025-12-08 203840


Result

Screenshot 2025-12-08 203909 Screenshot 2025-12-08 181857

Performance doesn't change, difference less than 0.1%
No regressions found druing execution of all examples.
issue: #4033, #3175

@github-actions github-actions bot added the gl OpenGL/WebGL render backend label Dec 9, 2025
@wenjieshen wenjieshen requested a review from hermet December 9, 2025 07:36
@wenjieshen wenjieshen self-assigned this Dec 9, 2025
@wenjieshen wenjieshen force-pushed the jay/exp/direct-blending branch from 906786c to fcf2c3b Compare December 9, 2025 07:37
@wenjieshen wenjieshen marked this pull request as ready for review December 9, 2025 07:52
Copilot AI review requested due to automatic review settings December 9, 2025 07:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the render-to-texture approach for shape blending with direct blending, eliminating the separate compose pass and reducing visual artifacts (halo effects). The refactor extracts gradient computation logic into reusable functions and introduces shape-specific blend shaders that perform blending in a single draw call.

Key changes:

  • Refactored gradient fragment shaders to separate computation functions from main entry points
  • Added three new blend shader headers for shape blending (solid, linear gradient, radial gradient)
  • Replaced GlSimpleBlendTask with GlDirectBlendTask that copies only the required destination region and blends directly

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tvgGlShaderSrc.h Added declarations for gradient function strings and new shape blend shader headers
tvgGlShaderSrc.cpp Refactored gradient shaders into reusable functions; added shape-specific blend shader headers with direct blending logic
tvgGlRenderer.h Replaced separate blend enums with unified shape blend enums; added BlendSource enum for blend program selection
tvgGlRenderer.cpp Updated shader initialization, modified drawPrimitive to use direct blending with region copying, simplified blend program selection with BlendSource
tvgGlRenderTask.h Renamed GlSimpleBlendTask to GlDirectBlendTask and changed constructor signature
tvgGlRenderTask.cpp Reimplemented blend task to copy destination region and blend directly without blend equations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hermet hermet added optimization Enhance performance / Reduce memory usage or binary size refactoring Code refactoring / Exceptional handles labels Dec 9, 2025
@hermet
Copy link
Member

hermet commented Dec 9, 2025

  • Refactor gradient functions for reuse in blend shaders
  • Add shape-specific blend shaders (solid, linear, radial)
  • Simplify blend program selection with BlendSource enum
  • Remove redundant blend shader headers

@wenjieshen Please note that, when you really want to get a code review but the changes are not easy to read, separating commits is mandatory rather than mixing everything into a single commit.

@wenjieshen wenjieshen force-pushed the jay/exp/direct-blending branch from fcf2c3b to 828aa3b Compare December 10, 2025 07:13
@wenjieshen wenjieshen changed the title gl: shape blending skipping render-to-texture gl: add direct shape blending path and shaders Dec 10, 2025
@wenjieshen
Copy link
Collaborator Author

wenjieshen commented Dec 10, 2025

  • Refactor gradient functions for reuse in blend shaders
  • Add shape-specific blend shaders (solid, linear, radial)
  • Simplify blend program selection with BlendSource enum
  • Remove redundant blend shader headers

@wenjieshen Please note that, when you really want to get a code review but the changes are not easy to read, separating commits is mandatory rather than mixing everything into a single commit.

I apologize for the inconvenience. I have tried separating commits. The modified version has redundant code, and I will create a PR to remove it. Thank you.

@wenjieshen wenjieshen force-pushed the jay/exp/direct-blending branch from 828aa3b to 302b109 Compare December 10, 2025 07:22
Copilot AI review requested due to automatic review settings December 18, 2025 08:32
@wenjieshen wenjieshen force-pushed the jay/exp/direct-blending branch from 302b109 to 53c2eb8 Compare December 18, 2025 08:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/renderer/gl_engine/tvgGlShaderSrc.cpp:1

  • The hardcoded buffer lengths lack explanation for how they were calculated. Consider adding a comment explaining how these values correspond to the shader component lengths, or consider computing them dynamically to avoid maintenance issues when shader strings change.
/*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wenjieshen wenjieshen marked this pull request as draft December 18, 2025 08:38
Split linear and radial gradient helpers from shader mains and add region-aware blend headers so source and destination sampling align for shape blends

issue: #4033, #3175
Expand blend program slots and selection via BlendSource enum to
cover solids, linear gradients, radial gradients, images, scenes

issue: #4033, #3175
Add GlDirectBlendTask to copy target region to temp FBO, run blend
draw, then restore blend defaults so shape blends render in place

issue: #4033, #3175
@wenjieshen wenjieshen force-pushed the jay/exp/direct-blending branch from 53c2eb8 to 4efcc17 Compare December 18, 2025 09:17
@wenjieshen wenjieshen marked this pull request as ready for review December 18, 2025 09:32
Copilot AI review requested due to automatic review settings December 18, 2025 09:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/renderer/gl_engine/tvgGlShaderSrc.cpp:1

  • The hardcoded shader length constants (2831, 5315, 5290) are magic numbers that will require manual updates whenever shader code changes. Consider documenting how these values were calculated or add a comment explaining that these must be updated when modifying shader strings to prevent buffer overflows.
/*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gl OpenGL/WebGL render backend optimization Enhance performance / Reduce memory usage or binary size refactoring Code refactoring / Exceptional handles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gl_engine: blending anti-aliasing quality matter gl_engine: Incorrectly blending at the anti-aliased parts

3 participants