Commit graph

52 commits

Author SHA1 Message Date
Hermet Park
5332876fe8 common: spec out TexMap
Spec out this incomplete experimental feature,
this is a still promising one, we will reintroduce
this officially after 1.0 release

size: -2kb

issue: https://github.com/thorvg/thorvg/issues/1372
2024-08-20 11:14:54 +09:00
Hermet Park
407fc84796 common: spec out Scene Clipper
Scene Clipper is an unusual feature
that is too unstable and ambiguous in ThorVG.

Users can achieve the same functionality
with multiple composed shapes instead of scene clipping.

size: -2.5kb

issues:
- https://github.com/thorvg/thorvg/issues/1548
- https://github.com/thorvg/thorvg/issues/1549
- https://github.com/thorvg/thorvg/issues/1573
2024-08-13 10:21:54 +09:00
Hermet Park
036ae3c2af renderer: code refactoring
Replaced the transformation with
a strong associated data field.

This helps to reduce the binary size (-1k).
2024-07-29 23:27:19 +09:00
Hermet Park
c4d89d0983 common: code refactoring
Trimming the transform data pass,
from RenderTransform to Matrix.

No logical changes.
2024-07-29 12:16:58 +09:00
Hermet Park
44955b704e common/math: code refactoring
Replaced the prefix "math" with "tvg" namespace.
2024-07-10 00:21:02 +09:00
RuiwenTang
e7c9ec790c gl_engine: make sure solid color not overwrite gradient fill
If there are both gradient colors and solid colors
the gradient color is used first for rendering
2024-07-08 11:33:43 +09:00
Hermet Park
889d1d1fa2 API: revise the APIs.
deprecate the `identifier()` APIs by replacing them with `type()`.

ThorVG is going to introduce an instance `id()`,
and this could be confused with the `identifier()` methods.

with this new type() method can reduce the memory size
by removing unncessary type data.

New Experimental C APIs:
- enum Tvg_Type
- Tvg_Result tvg_paint_get_type(const Tvg_Paint* paint, Tvg_Type* type)
- Tvg_Result tvg_gradient_get_type(const Tvg_Gradient* grad, Tvg_Type* type)

New Experimental C++ APIs:
- Type Paint::type() const
- Type Fill::type() const
- Type LinearGradient::type() const
- Type RadialGradient::type() const
- Type Shape::type() const
- Type Scene::type() const
- Type Picture::type() const
- Type Text::type() const

Deprecated C APIs:
- enum Tvg_Identifier
- Tvg_Result tvg_paint_get_identifier(const Tvg_Paint* paint, Tvg_Identifier* identifier)
- Tvg_Result tvg_gradient_get_identifier(const Tvg_Gradient* grad, Tvg_Identifier* identifier)

Deprecated C++ APIs:
- enum class Type
- uint32_t Paint::identifier() const
- uint32_t Fill::identifier() const
- static uint32_t Picture::identifier()
- static uint32_t Scene::identifier()
- static uint32_t Shape::identifier()
- static uint32_t LinearGradient:identifier()
- static uint32_T RadialGradient::identfier()

Removed Experimental APIs:
- static uint32_t Text::identifier()

issue: https://github.com/thorvg/thorvg/issues/1372
2024-07-05 21:25:58 +09:00
RuiwenTang
ea11d4d8a8 gl_engine: fix memory leak when rendering image 2024-07-05 12:13:53 +09:00
Hermet Park
4fee5458b2 gl_engine/renderer: code clean up
separate private / public methods designated in sectors.

no logical changes.
2024-07-05 10:46:47 +09:00
Hermet Park
688952be56 gl_engine: ++thread safety
The `dispose()` method can be called on a worker thread.
GL resources are released on `sync()`, ensuring guaranteed thread safety.
2024-07-05 10:46:47 +09:00
RuiwenTang
9bed64a4e7 gl_engine: support simple hairline stroke rendering
Reduce alpha if stroke width is too thin to mock hairline rendering
2024-07-04 12:03:39 +09:00
RuiwenTang
76f98008e8 gl_engine: optimize off-screen rendering
Performing a full-screen RenderPass resolve is too expensive.
Because most composite cases only require a small area to be rendered off-screen.
To improve performance, use the bounds of the Geometry for off-screen rendering whenever possible
2024-07-04 11:44:02 +09:00
Josh Soref
e061fa6628
common: fix 178+ spelling errors 2024-07-01 21:58:46 +09:00
RuiwenTang
01b85eea8a gl_engine: correct the return value of render function
If RenderData has nothing to draw, need to return `true`.
2024-06-25 16:05:30 +09:00
RuiwenTang
28331e9bf3 gl_engine: Fix memory leak caused by no deleted GlRenderTask 2024-06-25 00:15:01 +09:00
RuiwenTang
3c6a456d2c gl_engine: Fix compose render not correct after canvas resize
When canvas size changed, need to clear cached GLRenderTarget and
GLCompose.
2024-06-24 11:16:49 +09:00
Hermet Park
af1f3cb59d gl_engine: revise the gl portability
- guarantee minimum gl version requirement
- removed glesv2 dependency
- corrected gl ver dependency

issue: https://github.com/thorvg/thorvg/issues/2282
2024-06-24 11:08:28 +09:00
RuiwenTang
f8626d13d1 gl_engine: fix clip path and bounds not correct
* Optimize clip logical, change to use GL_GRATER and keep incrace depth
  value, so no need to do depth clear after every clip draw.
* Correct geometry bounding box calculation, and make sure the bounds is
  larger than all vertices
* Limit drawing area for off-screen RenderPass with correct scissor box
2024-06-11 20:57:07 +09:00
RuiwenTang
ceee253f4e gl_engine: fix GradientStroke ignored by tessellator
Fix the GlRenderer not take GradientStroke into consider when prepare
Geometry vertices.
2024-06-04 11:23:56 +09:00
Hermet Park
42409987e2 renderer/engines: support the canvas viewport function.
The viewport function defines the rectangular area of the canvas
that will be used for drawing operations.

It is used to clip the rendering output to the boundaries of the rectangle.
Apps can use this function to set the drawing region within the canvas.

When the ThorVG canvas is partially inside the screen area such as during scrolling
it could help enhance rendering performance.

New Experimental API:
- Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept;

Issue: https://github.com/thorvg/thorvg/issues/2274
2024-05-18 18:10:50 +09:00
Hermet Park
7e5800df89 renderer/engines: added mainSurface() interface.
This interface expects the main surface of the raster engine.
2024-05-18 18:10:50 +09:00
RuiwenTang
eb6067f87b gl_engine: optimize tessellation performance
* restrict the scissor box of composite task
* do not tessellate stroke or fill geometry if there is no Fill or
  Stroke color
* use actually transformed curve to calculate polyline count when doing
  curve flatten
2024-05-02 13:07:59 +03:00
RuiwenTang
bb7f23da78 gl_engine: fix rendering error caused by viewport and stencil state
Fix some error:
* glViewport not controlled by framebuffer, and need to set manually when
target framebuffer is changed.
* change even-odd stencil operation, so no need to do third draw call to
  clear stencil buffer
* fix the missing `GlCanvas::update` calls in Lottoe and LottieExtension
2024-04-29 17:14:31 +09:00
RuiwenTang
25d43ddacf gl_engine: fix gradient rendering error
* Fix error when handle GradientTransform calculation. And move the inv
calculation into gradient vertex shader.
* Fix cubic tessellation not close the last point
2024-04-25 10:54:53 +09:00
RuiwenTang
da45fa6608 gl_engine: using depth buffer to support path clip
* Append depth buffer attachment in tvgGlRenderPass
* using depth test if Shape has path clip
2024-04-16 13:36:13 +09:00
RuiwenTang
bb793a2762 gl_engine: fix some typo inside GlRenderer
* Fix a typo error when prepare blit task
* Prevent repeated texture generation during task preparation
2024-04-15 11:05:34 +03:00
RuiwenTang
d9d677acc6 gl_engine: using normal texture rendering in final color blit
Since blit msaa framebuffer to another msaa framebuffer may generate
GLError in some platforms. Use normal texture rendering to blit the final
color buffer onto target framebuffer.
2024-04-15 00:44:53 +09:00
Hermet Park
1efb72ce94 gl_engine: hotfix for the main surface drawing issue.
GL might need to generate a default target FBO
when the given target ID indicates the main surface.

However, users may want to draw visuals directly onto the main surface.

This policy must be reviewed thoroughly.
2024-04-05 01:11:14 +09:00
RuiwenTang
1e93eb0f49 gl_engine: change all shader output premultiplied alpha color 2024-04-05 01:11:00 +09:00
RuiwenTang
23386625fc gl_engine: make stencil task support other advance logical
* Support rendering Gradient in path Stroke mode
* Fix GlStencilCoverTask not support even-odd fill rule
* Make GlStencilCoverTask can discard overlapped area during stroke
  rendering
2024-03-21 11:50:13 +09:00
Hermet Park
754a4aeaea renderer/gl_engine: Refine GlCanvas Interface
Refactor the GlCanvas::target() interface to allow
passing the drawing target ID from the user side.

Previously, it performed the drawing on the currently set FBO target.

Beta API change:

Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
-> Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h)
2024-03-13 10:13:02 +02:00
RuiwenTang
cc2fa23359 gl_engine: remove unused alpha attribute
Since we choose MSAA, no need to calculate edge alpha during fragment
stage. So this commit removed the alpha attribute and related code:

* Remove the alpha attribute in vertex data.
* Change position type from `vec3` to `vec2` in all shader code.
* Remove alhpa multiplication in all fragment shaders
2024-03-06 16:56:32 +09:00
RuiwenTang
be278dfc67 gl_engine: add stencil and cover render task
* add new render task to do stencil and cover rendering which is a
  fallback rendering method to handle cases that trianglation tessellation
  failed

* add a new tessellator to generate stencil and cover vertex mesh
2024-02-07 15:13:40 +09:00
Hermet Park
a1c43a9518 renderer: code refactoring.
removed unnused return value.
2024-02-02 03:02:56 +09:00
RuiwenTang
57cff56e44 gl_engine: fix radial gradient not render correctly
root cause: the gradient shader not taking into account FillSpread property
2024-01-15 10:58:03 +09:00
Jinny You
2c6c8d3b21
updated copyright date (#1866) 2023-12-28 10:43:25 +09:00
Hermet Park
ca44e46d3b gl_engine: fix a compiler warning.
../src/renderer/gl_engine/tvgGlRenderer.cpp:450:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  450 |     for (auto i = 0; i < mComposePool.count; i++) {
      |
2023-12-27 16:42:49 +09:00
RuiwenTang
edb118a0c7 gl_engine: fix svg gradient position not correct
* change the color and stop size to 16 in shader and buffer block
* calculate transform when upload gradient info to gpu pipeline
2023-12-26 17:58:27 +09:00
RuiwenTang
51a69880fd gl_engine: fix wrong scissor value cause content not fully rendered 2023-12-19 22:35:47 +09:00
RuiwenTang
53b0b87bb7 gl_engine: optimize framebuffer creation and save some runtime memory
since the framebuffer will draw back to parent RenderPass, it can be
reused in next compose rendering.

So instead of create framebuffer every time when beginCompose is called, we
trying to reuse the framebuffer created before in the same stack level
2023-12-19 01:59:16 +09:00
Hermet Park
0aa39111ad common/array: code refactoring.
Use a default constructor with reservation.
2023-12-13 09:34:44 +09:00
RuiwenTang
3e9579f92c gl_engine: support advance compose method 2023-11-24 08:07:21 +02:00
Sergii Liebodkin
548962f5f8 apis/engines: Revise the clear() buffer behavior.
ThorVG has offered an option to clear the buffer since version 1.0.
This is essential when users utilize the canvas target buffer
with the main render target. They share the buffer
and need to draw contents onto the existing contents.

API:
Result Canvas::clear(bool free = true)
-> Result Canvas::clear(bool paints = true, bool buffer = true)

Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free);
-> Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool paints, bool buffer);

Issue: https://github.com/thorvg/thorvg/issues/1779

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2023-11-20 18:23:00 +09:00
Hermet Park
6e6dd8a97e gl_engine/renderer: skip sync if nothing should be done.
update by 66305f3e6d
2023-11-15 22:33:39 +09:00
Hermet Park
db55481e97 renamed stroke apis family.
float Shape::stroke(float width) -> float Shape::strokeWidth(float width)
Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) -> Result Shape::strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
Result Shape::stroke(std::unique_ptr<Fill> f) -> Result Shape::strokeFill(std::unique_ptr<Fill> f)
Result Shape::stroke(const float* dashPattern, uint32_t cnt, float offset = 0.0f) ->  Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f)
Result Shape::stroke(StrokeCap cap) -> Result Shape::strokeCap(StrokeCap cap)
Result Shape::stroke(StrokeJoin join) -> Result Shape::strokeJoin(StrokeJoin join)
Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const -> Result Shape::strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-27 11:46:51 +09:00
RuiwenTang
fea0d1bb77 gl_engine: use raw pointer to pass and hold GlRenderTask 2023-10-23 18:08:14 +09:00
RuiwenTang
6a2b34df73 gl_engine: support basic alpha composite
* introduce a new class GlRenderPass to hold off-screen rendering result
* add basic alpha composite support with begin/end render-pass
2023-10-20 10:51:04 +09:00
RuiwenTang
4722550e06 gl_engine: support clip by using scissor and stencil 2023-10-12 23:18:12 +09:00
RuiwenTang
6a3a03f29f gl_engine: support render image 2023-10-04 12:41:22 +09:00
RuiwenTang
453cba7ddd gl_engine: make GlRenderTask generic with uniform block
* Use uniform block to pack all color informations
* Move the actual gl draw call into GlRenderer::sync function, so all
  data is been uploaded into GPU
* Make GlRenderTask simple and generic for direct gl draw
2023-09-21 22:24:07 +09:00