mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-16 04:54:39 +00:00
wg_engine: fix long path support
created a singe shared instance of stoke generator in heap, instead of stack. No performace impact
This commit is contained in:
parent
c926eebba1
commit
40cff2d6f5
5 changed files with 54 additions and 59 deletions
|
@ -48,9 +48,7 @@ void WgCompositor::initialize(WgContext& context, uint32_t width, uint32_t heigh
|
||||||
storageInterm.initialize(context, width, height);
|
storageInterm.initialize(context, width, height);
|
||||||
storageDstCopy.initialize(context, width, height);
|
storageDstCopy.initialize(context, width, height);
|
||||||
// composition and blend geometries
|
// composition and blend geometries
|
||||||
WgVertexBufferInd vertexBuffer;
|
meshData.blitBox(context);
|
||||||
vertexBuffer.appendBlitBox();
|
|
||||||
meshData.update(context, vertexBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -216,9 +216,9 @@ struct WgVertexBuffer {
|
||||||
|
|
||||||
// simple indexed vertex buffer
|
// simple indexed vertex buffer
|
||||||
struct WgVertexBufferInd {
|
struct WgVertexBufferInd {
|
||||||
Point vbuff[WG_POINTS_COUNT*4];
|
Point vbuff[WG_POINTS_COUNT*16];
|
||||||
Point tbuff[WG_POINTS_COUNT*4];
|
Point tbuff[WG_POINTS_COUNT*16];
|
||||||
uint32_t ibuff[WG_POINTS_COUNT*8];
|
uint32_t ibuff[WG_POINTS_COUNT*16];
|
||||||
size_t vcount = 0;
|
size_t vcount = 0;
|
||||||
size_t icount = 0;
|
size_t icount = 0;
|
||||||
|
|
||||||
|
@ -237,42 +237,6 @@ struct WgVertexBufferInd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// append image box with tex coords
|
|
||||||
void appendImageBox(float w, float h) {
|
|
||||||
Point points[4] { { 0.0f, 0.0f }, { w, 0.0f }, { w, h }, { 0.0f, h } };
|
|
||||||
appendImageBox(points);
|
|
||||||
}
|
|
||||||
|
|
||||||
// append blit box with tex coords
|
|
||||||
void appendBlitBox() {
|
|
||||||
Point points[4] { { -1.0f, +1.0f }, { +1.0f, +1.0f }, { +1.0f, -1.0f }, { -1.0f, -1.0f } };
|
|
||||||
appendImageBox(points);
|
|
||||||
}
|
|
||||||
|
|
||||||
// append image box with tex coords
|
|
||||||
void appendImageBox(Point points[4]) {
|
|
||||||
// append vertexes
|
|
||||||
vbuff[vcount+0] = points[0];
|
|
||||||
vbuff[vcount+1] = points[1];
|
|
||||||
vbuff[vcount+2] = points[2];
|
|
||||||
vbuff[vcount+3] = points[3];
|
|
||||||
// append tex coords
|
|
||||||
tbuff[vcount+0] = { 0.0f, 0.0f };
|
|
||||||
tbuff[vcount+1] = { 1.0f, 0.0f };
|
|
||||||
tbuff[vcount+2] = { 1.0f, 1.0f };
|
|
||||||
tbuff[vcount+3] = { 0.0f, 1.0f };
|
|
||||||
// append indexes
|
|
||||||
ibuff[icount+0] = vcount + 0;
|
|
||||||
ibuff[icount+1] = vcount + 1;
|
|
||||||
ibuff[icount+2] = vcount + 2;
|
|
||||||
ibuff[icount+3] = vcount + 0;
|
|
||||||
ibuff[icount+4] = vcount + 2;
|
|
||||||
ibuff[icount+5] = vcount + 3;
|
|
||||||
// update buffer
|
|
||||||
vcount += 4;
|
|
||||||
icount += 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// append quad - two triangles formed from four points
|
// append quad - two triangles formed from four points
|
||||||
void appendQuad(const Point& p0, const Point& p1, const Point& p2, const Point& p3) {
|
void appendQuad(const Point& p0, const Point& p1, const Point& p2, const Point& p3) {
|
||||||
// append vertexes
|
// append vertexes
|
||||||
|
@ -362,7 +326,7 @@ struct WgVertexBufferInd {
|
||||||
}
|
}
|
||||||
|
|
||||||
// append miter joint
|
// append miter joint
|
||||||
void appendMitter(const Point& v0, const Point& v1, const Point& v2, float dist1, float dist2, float halfWidth, float miterLimit) {
|
void appendMiter(const Point& v0, const Point& v1, const Point& v2, float dist1, float dist2, float halfWidth, float miterLimit) {
|
||||||
Point sub1 = v1 - v0;
|
Point sub1 = v1 - v0;
|
||||||
Point sub2 = v2 - v1;
|
Point sub2 = v2 - v1;
|
||||||
Point nrm1 { +sub1.y / dist1, -sub1.x / dist1 };
|
Point nrm1 { +sub1.y / dist1, -sub1.x / dist1 };
|
||||||
|
@ -433,7 +397,7 @@ struct WgVertexBufferInd {
|
||||||
appendBevel(buff.last(1), buff.vbuff[0], buff.vbuff[1], buff.lastDist(0), buff.vdist[1], halfWidth);
|
appendBevel(buff.last(1), buff.vbuff[0], buff.vbuff[1], buff.lastDist(0), buff.vdist[1], halfWidth);
|
||||||
// close by mitter
|
// close by mitter
|
||||||
else if (rstroke->join == StrokeJoin::Miter) {
|
else if (rstroke->join == StrokeJoin::Miter) {
|
||||||
appendMitter(buff.last(1), buff.vbuff[0], buff.vbuff[1], buff.lastDist(0), buff.vdist[1], halfWidth, rstroke->miterlimit);
|
appendMiter(buff.last(1), buff.vbuff[0], buff.vbuff[1], buff.lastDist(0), buff.vdist[1], halfWidth, rstroke->miterlimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +408,7 @@ struct WgVertexBufferInd {
|
||||||
// append joints (mitter)
|
// append joints (mitter)
|
||||||
} else if (rstroke->join == StrokeJoin::Miter) {
|
} else if (rstroke->join == StrokeJoin::Miter) {
|
||||||
for (size_t i = 1; i < buff.vcount - 1; i++)
|
for (size_t i = 1; i < buff.vcount - 1; i++)
|
||||||
appendMitter(buff.vbuff[i-1], buff.vbuff[i], buff.vbuff[i+1], buff.vdist[i], buff.vdist[i+1], halfWidth, rstroke->miterlimit);
|
appendMiter(buff.vbuff[i-1], buff.vbuff[i], buff.vbuff[i+1], buff.vdist[i], buff.vdist[i+1], halfWidth, rstroke->miterlimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,7 +84,7 @@ void WgMeshData::update(WgContext& context, const WgVertexBufferInd& vertexBuffe
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void WgMeshData::update(WgContext& context, const Point pmin, const Point pmax)
|
void WgMeshData::bbox(WgContext& context, const Point pmin, const Point pmax)
|
||||||
{
|
{
|
||||||
vertexCount = 4;
|
vertexCount = 4;
|
||||||
indexCount = 6;
|
indexCount = 6;
|
||||||
|
@ -97,6 +97,32 @@ void WgMeshData::update(WgContext& context, const Point pmin, const Point pmax)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WgMeshData::imageBox(WgContext& context, float w, float h)
|
||||||
|
{
|
||||||
|
vertexCount = 4;
|
||||||
|
indexCount = 6;
|
||||||
|
const float vdata[] = { 0.0f, 0.0f, w, 0.0f, w, h, 0.0f, h };
|
||||||
|
const float tdata[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f };
|
||||||
|
const uint32_t idata[] = { 0, 1, 2, 0, 2, 3 };
|
||||||
|
context.allocateBufferVertex(bufferPosition, vdata, sizeof(vdata));
|
||||||
|
context.allocateBufferVertex(bufferTexCoord, tdata, sizeof(tdata));
|
||||||
|
context.allocateBufferIndex(bufferIndex, idata, sizeof(idata));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WgMeshData::blitBox(WgContext& context)
|
||||||
|
{
|
||||||
|
vertexCount = 4;
|
||||||
|
indexCount = 6;
|
||||||
|
const float vdata[] = { -1.0f, +1.0f, +1.0f, +1.0f, +1.0f, -1.0f, -1.0f, -1.0f };
|
||||||
|
const float tdata[] = { +0.0f, +0.0f, +1.0f, +0.0f, +1.0f, +1.0f, +0.0f, +1.0f };
|
||||||
|
const uint32_t idata[] = { 0, 1, 2, 0, 2, 3 };
|
||||||
|
context.allocateBufferVertex(bufferPosition, vdata, sizeof(vdata));
|
||||||
|
context.allocateBufferVertex(bufferTexCoord, tdata, sizeof(tdata));
|
||||||
|
context.allocateBufferIndex(bufferIndex, idata, sizeof(idata));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgMeshData::release(WgContext& context)
|
void WgMeshData::release(WgContext& context)
|
||||||
{
|
{
|
||||||
context.releaseBuffer(bufferIndex);
|
context.releaseBuffer(bufferIndex);
|
||||||
|
@ -164,7 +190,7 @@ void WgMeshDataGroup::append(WgContext& context, const WgVertexBufferInd& vertex
|
||||||
void WgMeshDataGroup::append(WgContext& context, const Point pmin, const Point pmax)
|
void WgMeshDataGroup::append(WgContext& context, const Point pmin, const Point pmax)
|
||||||
{
|
{
|
||||||
meshes.push(gMeshDataPool->allocate(context));
|
meshes.push(gMeshDataPool->allocate(context));
|
||||||
meshes.last()->update(context, pmin, pmax);
|
meshes.last()->bbox(context, pmin, pmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,6 +298,8 @@ void WgRenderSettings::release(WgContext& context)
|
||||||
// WgRenderDataPaint
|
// WgRenderDataPaint
|
||||||
//***********************************************************************
|
//***********************************************************************
|
||||||
|
|
||||||
|
WgVertexBufferInd* WgRenderDataPaint::gStrokesGenerator = nullptr;
|
||||||
|
|
||||||
void WgRenderDataPaint::release(WgContext& context)
|
void WgRenderDataPaint::release(WgContext& context)
|
||||||
{
|
{
|
||||||
context.pipelines->layouts.releaseBindGroup(bindGroupPaint);
|
context.pipelines->layouts.releaseBindGroup(bindGroupPaint);
|
||||||
|
@ -411,11 +439,11 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update shapes bbox (with empty path hadnling)
|
// update shapes bbox (with empty path handling)
|
||||||
if ((this->meshGroupShapesBBox.meshes.count > 0 ) ||
|
if ((this->meshGroupShapesBBox.meshes.count > 0 ) ||
|
||||||
(this->meshGroupStrokesBBox.meshes.count > 0)) {
|
(this->meshGroupStrokesBBox.meshes.count > 0)) {
|
||||||
updateAABB(tr);
|
updateAABB(tr);
|
||||||
meshDataBBox.update(context, pMin, pMax);
|
meshDataBBox.bbox(context, pMin, pMax);
|
||||||
} else aabb = {0, 0, 0, 0};
|
} else aabb = {0, 0, 0, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +451,7 @@ void WgRenderDataShape::updateMeshes(WgContext &context, const RenderShape &rsha
|
||||||
void WgRenderDataShape::proceedStrokes(WgContext context, const RenderStroke* rstroke, float tbeg, float tend, const WgVertexBuffer& buff)
|
void WgRenderDataShape::proceedStrokes(WgContext context, const RenderStroke* rstroke, float tbeg, float tend, const WgVertexBuffer& buff)
|
||||||
{
|
{
|
||||||
assert(rstroke);
|
assert(rstroke);
|
||||||
WgVertexBufferInd stroke_buff;
|
gStrokesGenerator->reset();
|
||||||
// trim -> dash -> stroke
|
// trim -> dash -> stroke
|
||||||
if ((tbeg != 0.0f) || (tend != 1.0f)) {
|
if ((tbeg != 0.0f) || (tend != 1.0f)) {
|
||||||
if (tbeg == tend) return;
|
if (tbeg == tend) return;
|
||||||
|
@ -431,17 +459,17 @@ void WgRenderDataShape::proceedStrokes(WgContext context, const RenderStroke* rs
|
||||||
trimed_buff.trim(buff, tbeg, tend);
|
trimed_buff.trim(buff, tbeg, tend);
|
||||||
trimed_buff.updateDistances();
|
trimed_buff.updateDistances();
|
||||||
// trim ->dash -> stroke
|
// trim ->dash -> stroke
|
||||||
if (rstroke->dashPattern) stroke_buff.appendStrokesDashed(trimed_buff, rstroke);
|
if (rstroke->dashPattern) gStrokesGenerator->appendStrokesDashed(trimed_buff, rstroke);
|
||||||
// trim -> stroke
|
// trim -> stroke
|
||||||
else stroke_buff.appendStrokes(trimed_buff, rstroke);
|
else gStrokesGenerator->appendStrokes(trimed_buff, rstroke);
|
||||||
} else
|
} else
|
||||||
// dash -> stroke
|
// dash -> stroke
|
||||||
if (rstroke->dashPattern) {
|
if (rstroke->dashPattern) {
|
||||||
stroke_buff.appendStrokesDashed(buff, rstroke);
|
gStrokesGenerator->appendStrokesDashed(buff, rstroke);
|
||||||
// stroke
|
// stroke
|
||||||
} else
|
} else
|
||||||
stroke_buff.appendStrokes(buff, rstroke);
|
gStrokesGenerator->appendStrokes(buff, rstroke);
|
||||||
appendStroke(context, stroke_buff);
|
appendStroke(context, *gStrokesGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@ struct WgMeshData {
|
||||||
|
|
||||||
void update(WgContext& context, const WgVertexBuffer& vertexBuffer);
|
void update(WgContext& context, const WgVertexBuffer& vertexBuffer);
|
||||||
void update(WgContext& context, const WgVertexBufferInd& vertexBufferInd);
|
void update(WgContext& context, const WgVertexBufferInd& vertexBufferInd);
|
||||||
void update(WgContext& context, const Point pmin, const Point pmax);
|
void bbox(WgContext& context, const Point pmin, const Point pmax);
|
||||||
|
void imageBox(WgContext& context, float w, float h);
|
||||||
|
void blitBox(WgContext& context);
|
||||||
void release(WgContext& context);
|
void release(WgContext& context);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,6 +96,9 @@ struct WgRenderSettings
|
||||||
|
|
||||||
struct WgRenderDataPaint
|
struct WgRenderDataPaint
|
||||||
{
|
{
|
||||||
|
// global strokes generator. single instance
|
||||||
|
static WgVertexBufferInd* gStrokesGenerator;
|
||||||
|
|
||||||
WGPUBuffer bufferModelMat{};
|
WGPUBuffer bufferModelMat{};
|
||||||
WGPUBuffer bufferBlendSettings{};
|
WGPUBuffer bufferBlendSettings{};
|
||||||
WGPUBindGroup bindGroupPaint{};
|
WGPUBindGroup bindGroupPaint{};
|
||||||
|
|
|
@ -38,6 +38,7 @@ void WgRenderer::initialize()
|
||||||
{
|
{
|
||||||
mPipelines.initialize(mContext);
|
mPipelines.initialize(mContext);
|
||||||
WgMeshDataGroup::gMeshDataPool = new WgMeshDataPool();
|
WgMeshDataGroup::gMeshDataPool = new WgMeshDataPool();
|
||||||
|
WgRenderDataShape::gStrokesGenerator = new WgVertexBufferInd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ void WgRenderer::release()
|
||||||
mStorageRoot.release(mContext);
|
mStorageRoot.release(mContext);
|
||||||
mRenderStoragePool.release(mContext);
|
mRenderStoragePool.release(mContext);
|
||||||
mRenderDataShapePool.release(mContext);
|
mRenderDataShapePool.release(mContext);
|
||||||
|
delete WgRenderDataShape::gStrokesGenerator;
|
||||||
WgMeshDataGroup::gMeshDataPool->release(mContext);
|
WgMeshDataGroup::gMeshDataPool->release(mContext);
|
||||||
delete WgMeshDataGroup::gMeshDataPool;
|
delete WgMeshDataGroup::gMeshDataPool;
|
||||||
mCompositorStack.clear();
|
mCompositorStack.clear();
|
||||||
|
@ -128,11 +130,9 @@ RenderData WgRenderer::prepare(RenderSurface* surface, RenderData data, const Ma
|
||||||
|
|
||||||
// update image data
|
// update image data
|
||||||
if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Image)) {
|
if (flags & (RenderUpdateFlag::Path | RenderUpdateFlag::Image)) {
|
||||||
WgVertexBufferInd vertexBufferInd;
|
|
||||||
vertexBufferInd.appendImageBox(surface->w, surface->h);
|
|
||||||
mContext.pipelines->layouts.releaseBindGroup(renderDataPicture->bindGroupPicture);
|
mContext.pipelines->layouts.releaseBindGroup(renderDataPicture->bindGroupPicture);
|
||||||
renderDataPicture->meshData.release(mContext);
|
renderDataPicture->meshData.release(mContext);
|
||||||
renderDataPicture->meshData.update(mContext, vertexBufferInd);
|
renderDataPicture->meshData.imageBox(mContext, surface->w, surface->h);
|
||||||
renderDataPicture->imageData.update(mContext, surface);
|
renderDataPicture->imageData.update(mContext, surface);
|
||||||
renderDataPicture->bindGroupPicture = mContext.pipelines->layouts.createBindGroupTexSampled(
|
renderDataPicture->bindGroupPicture = mContext.pipelines->layouts.createBindGroupTexSampled(
|
||||||
mContext.samplerLinearRepeat, renderDataPicture->imageData.textureView
|
mContext.samplerLinearRepeat, renderDataPicture->imageData.textureView
|
||||||
|
|
Loading…
Add table
Reference in a new issue