gl_engine: correct the stroke alpha calculation

The wrong matrix scale factor value caused the stroke alpha to be zero
when the matrix contains rotation.
This commit is contained in:
RuiwenTang 2024-11-26 10:56:57 +08:00 committed by Hermet Park
parent 968e438d25
commit 1a766ec00e
3 changed files with 7 additions and 2 deletions

View file

@ -57,6 +57,11 @@
} while(0)
#endif
static inline float getScaleFactor(const Matrix& m)
{
return sqrtf(m.e11 * m.e11 + m.e21 * m.e21);
}
enum class GlStencilMode {
None,
FillWinding,

View file

@ -162,7 +162,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const RenderColor& c, RenderUpdat
auto a = MULTIPLY(c.a, sdata.opacity);
if (flag & RenderUpdateFlag::Stroke) {
float strokeWidth = sdata.rshape->strokeWidth() * sdata.geometry->getTransformMatrix().e11;
float strokeWidth = sdata.rshape->strokeWidth() * getScaleFactor(sdata.geometry->getTransformMatrix());
if (strokeWidth < MIN_GL_STROKE_WIDTH) {
float alpha = strokeWidth / MIN_GL_STROKE_WIDTH;
a = MULTIPLY(a, static_cast<uint8_t>(alpha * 255));

View file

@ -1534,7 +1534,7 @@ void Stroker::stroke(const RenderShape *rshape)
mStrokeWidth = rshape->strokeWidth();
if (isinf(mMatrix.e11)) {
auto strokeWidth = rshape->strokeWidth() * mMatrix.e11;
auto strokeWidth = rshape->strokeWidth() * getScaleFactor(mMatrix);
if (strokeWidth <= MIN_GL_STROKE_WIDTH) strokeWidth = MIN_GL_STROKE_WIDTH;
mStrokeWidth = strokeWidth / mMatrix.e11;
}