mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
gl_engine: fix mistake in the calculation of stroke miter limit
* correct the stroke width and color calculation with scaling * fix the miter limit calculation to make bevel join fallback correct
This commit is contained in:
parent
34d0309fcc
commit
a9d314985c
3 changed files with 13 additions and 5 deletions
|
@ -27,7 +27,7 @@
|
||||||
#include "tvgGlCommon.h"
|
#include "tvgGlCommon.h"
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
|
|
||||||
#define MIN_GL_STROKE_WIDTH 0.5f
|
#define MIN_GL_STROKE_WIDTH 1.0f
|
||||||
|
|
||||||
#define MVP_MATRIX(w, h) \
|
#define MVP_MATRIX(w, h) \
|
||||||
float mvp[4*4] = { \
|
float mvp[4*4] = { \
|
||||||
|
|
|
@ -140,7 +140,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b,
|
||||||
a = MULTIPLY(a, sdata.opacity);
|
a = MULTIPLY(a, sdata.opacity);
|
||||||
|
|
||||||
if (flag & RenderUpdateFlag::Stroke) {
|
if (flag & RenderUpdateFlag::Stroke) {
|
||||||
float strokeWidth = sdata.rshape->strokeWidth();
|
float strokeWidth = sdata.rshape->strokeWidth() * sdata.geometry->getTransformMatrix().e11;
|
||||||
if (strokeWidth < MIN_GL_STROKE_WIDTH) {
|
if (strokeWidth < MIN_GL_STROKE_WIDTH) {
|
||||||
float alpha = strokeWidth / MIN_GL_STROKE_WIDTH;
|
float alpha = strokeWidth / MIN_GL_STROKE_WIDTH;
|
||||||
a = MULTIPLY(a, static_cast<uint8_t>(alpha * 255));
|
a = MULTIPLY(a, static_cast<uint8_t>(alpha * 255));
|
||||||
|
|
|
@ -1645,11 +1645,19 @@ Stroker::Stroker(Array<float> *points, Array<uint32_t> *indices, const Matrix& m
|
||||||
|
|
||||||
void Stroker::stroke(const RenderShape *rshape)
|
void Stroker::stroke(const RenderShape *rshape)
|
||||||
{
|
{
|
||||||
mMiterLimit = rshape->strokeMiterlimit() * 2.f;
|
mMiterLimit = rshape->strokeMiterlimit();
|
||||||
mStrokeWidth = std::max(mStrokeWidth, rshape->strokeWidth());
|
|
||||||
mStrokeCap = rshape->strokeCap();
|
mStrokeCap = rshape->strokeCap();
|
||||||
mStrokeJoin = rshape->strokeJoin();
|
mStrokeJoin = rshape->strokeJoin();
|
||||||
|
|
||||||
|
mStrokeWidth = rshape->strokeWidth();
|
||||||
|
if (isinf(mMatrix.e11)) {
|
||||||
|
float strokeWidth = rshape->strokeWidth() * mMatrix.e11;
|
||||||
|
|
||||||
|
if (strokeWidth <= MIN_GL_STROKE_WIDTH) strokeWidth = MIN_GL_STROKE_WIDTH;
|
||||||
|
|
||||||
|
mStrokeWidth = strokeWidth / mMatrix.e11;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto cmds = rshape->path.cmds.data;
|
auto cmds = rshape->path.cmds.data;
|
||||||
auto cmdCnt = rshape->path.cmds.count;
|
auto cmdCnt = rshape->path.cmds.count;
|
||||||
|
@ -1955,7 +1963,7 @@ void Stroker::strokeMiter(const GlPoint &prev, const GlPoint &curr, const GlPoin
|
||||||
|
|
||||||
auto pe = out * k;
|
auto pe = out * k;
|
||||||
|
|
||||||
if (detail::_pointLength(pe) >= mMiterLimit) {
|
if (detail::_pointLength(pe) >= mMiterLimit * strokeRadius()) {
|
||||||
this->strokeBevel(prev, curr, center);
|
this->strokeBevel(prev, curr, center);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue