mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
gl_engine: support simple hairline stroke rendering
Reduce alpha if stroke width is too thin to mock hairline rendering
This commit is contained in:
parent
338c75ca3a
commit
35d168db9e
3 changed files with 21 additions and 3 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include "tvgGlCommon.h"
|
#include "tvgGlCommon.h"
|
||||||
#include "tvgMath.h"
|
#include "tvgMath.h"
|
||||||
|
|
||||||
|
#define MIN_GL_STROKE_WIDTH 0.5f
|
||||||
|
|
||||||
#define MVP_MATRIX(w, h) \
|
#define MVP_MATRIX(w, h) \
|
||||||
float mvp[4*4] = { \
|
float mvp[4*4] = { \
|
||||||
|
|
|
@ -644,6 +644,14 @@ 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) {
|
||||||
|
float strokeWidth = sdata.rshape->strokeWidth();
|
||||||
|
if (strokeWidth < MIN_GL_STROKE_WIDTH) {
|
||||||
|
float alpha = strokeWidth / MIN_GL_STROKE_WIDTH;
|
||||||
|
a = MULTIPLY(a, static_cast<uint8_t>(alpha * 255));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// matrix buffer
|
// matrix buffer
|
||||||
{
|
{
|
||||||
const auto& matrix = sdata.geometry->getTransformMatrix();
|
const auto& matrix = sdata.geometry->getTransformMatrix();
|
||||||
|
@ -801,6 +809,15 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float alpha = 1.0f;
|
||||||
|
|
||||||
|
if (flag & RenderUpdateFlag::GradientStroke) {
|
||||||
|
float strokeWidth = sdata.rshape->strokeWidth();
|
||||||
|
if (strokeWidth < MIN_GL_STROKE_WIDTH) {
|
||||||
|
alpha = strokeWidth / MIN_GL_STROKE_WIDTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// gradient block
|
// gradient block
|
||||||
{
|
{
|
||||||
GlBindingResource gradientBinding{};
|
GlBindingResource gradientBinding{};
|
||||||
|
@ -821,7 +838,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;
|
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f;
|
gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f;
|
gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f;
|
gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f * alpha;
|
||||||
nStops++;
|
nStops++;
|
||||||
}
|
}
|
||||||
gradientBlock.nStops[0] = nStops * 1.f;
|
gradientBlock.nStops[0] = nStops * 1.f;
|
||||||
|
@ -857,7 +874,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;
|
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f;
|
gradientBlock.stopColors[i * 4 + 1] = stops[i].g / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f;
|
gradientBlock.stopColors[i * 4 + 2] = stops[i].b / 255.f;
|
||||||
gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f;
|
gradientBlock.stopColors[i * 4 + 3] = stops[i].a / 255.f * alpha;
|
||||||
nStops++;
|
nStops++;
|
||||||
}
|
}
|
||||||
gradientBlock.nStops[0] = nStops * 1.f;
|
gradientBlock.nStops[0] = nStops * 1.f;
|
||||||
|
|
|
@ -148,7 +148,7 @@ private:
|
||||||
Array<float>* mResGlPoints;
|
Array<float>* mResGlPoints;
|
||||||
Array<uint32_t>* mResIndices;
|
Array<uint32_t>* mResIndices;
|
||||||
Matrix mMatrix;
|
Matrix mMatrix;
|
||||||
float mStrokeWidth = 1.f;
|
float mStrokeWidth = MIN_GL_STROKE_WIDTH;
|
||||||
float mMiterLimit = 4.f;
|
float mMiterLimit = 4.f;
|
||||||
StrokeCap mStrokeCap = StrokeCap::Square;
|
StrokeCap mStrokeCap = StrokeCap::Square;
|
||||||
StrokeJoin mStrokeJoin = StrokeJoin::Bevel;
|
StrokeJoin mStrokeJoin = StrokeJoin::Bevel;
|
||||||
|
|
Loading…
Add table
Reference in a new issue