thorvg icon indicating copy to clipboard operation
thorvg copied to clipboard

gl_engine: enhancement plan

Open SergeyLebedkin opened this issue 4 months ago • 1 comments

Shaders

Localize shader managment: add/remove/modify existing shaders and manage RAII (differed creation)

  • [ ] declare and implement GlProgram and GlShader in the same cpp/h file
  • [ ] move shaders to a separate structure-storage f.e. GlShaders
  • [ ] request Unifirm/UBO/Samplers locations at the shader creation, instead of each frame by the name on shader binding

Render Targets

Simplify render targets viewport/scissor and pooling logic

  • [ ] make offscreen buffers the same size as the screen buffer, so we will have same coordinate system (offset and size) for all of them, so we do not need to recalculate viewports for scenes/shapes for each buffer. it will helps in composition/blending/effects
  • [ ] it will also simplify the logic of render targets pools, because we din`t need to create new pool for the new target size

Task based renderer

More tiny context swithing control, increase performance

  • [ ] simplify the logic of the tasks. use just a tasks for shape/image and scene. it will help for proper control in context switching and concentrate all -information about current frame objects/targets

Implement general Context instance

Universilize global entities creation and managment

  • [ ] It will hold information about current GL context, screen information, containe shared objects will localize vertex/index/uniform buffers and textures creations/reallocation

Gradient fill

Cleanup gradient shaders and increase performance, reduce shader code size

  • [ ] Use pre-calculated 1d texture for the gradient color map. It will reduce presure on the fragment shaders in case of gradient fill

Sampler entity

Simplify texture creations and access type (repeat, clamp, mirror, filtration)

  • [ ] start to use sampler entity instead of each texture local settings.

Use generalized compositor

Hold general rasterization mechnics and entities at the same place

  • [ ] use the single class for rasterization in different scenarios (cliping, blending, masking) for different object types (shapes/images/scenes)
  • [ ] it will be holder for view matrix, temporary render targets, shaders, current render target and render pipeline state
  • [ ] it will handle resize mechanics rasterization entities

Batch draw calls to speed up

( Updated by @wenjieshen December 05, 2025)

  • [ ] Batch convex shapes. (WIP)
  • [ ] Use a texture instead of a stencil buffer to enable the batching of complex shapes.
  • [ ] Merge the coverage map into a large image using a texture atlas, depending on hardware bandwidth.

Analytic AA

( Updated by @wenjieshen December 05, 2025)

  • [ ] Implement the Resolution indepentant curve rendering[^1], because this is the closest option to GPU rasterization without support for computer shaders. [^1]:(https://developer.nvidia.cn/gpugems/gpugems3/part-iv-image-effects/chapter-25-rendering-vector-art-gpu)

In general all this changes will made code more clean, faster and modifiable. Also it will sync gl and wg renderer mechanics to simplify new issues integration and code sharing

SergeyLebedkin avatar Aug 07 '25 12:08 SergeyLebedkin

@SergeyLebedkin Hi,

  1. Rather than focusing on what is being done, the reason why the refactoring is necessary should be clearly stated.
  2. Please clarify main purpose of the refactoring between a. improving maintenance or b. performance enhancement

Thanks.

hermet avatar Aug 07 '25 13:08 hermet