void TestStrokeAAPerformance()
{
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
typedef agg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;
renderder_scanline_type rensl(renb);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
renb.clear(agg::rgba8(255,255,255));
int nPointX[5]={20,80,20,80,20};
int nPointY[5]={20,20,80,80,20};
agg::path_storage ps;
ps.move_to(nPointX[0],nPointY[0]);
for (int i =1; i<= 4; i++)
{
ps.line_to(nPointX[i],nPointY[i]);
ps.move_to(nPointX[i],nPointY[i]);
}
stroke(trans);
agg::conv_stroke<agg::path_storage> stroke(ps);
stroke.width(nLineWidth);
int start = ::GetTickCount();
ras.gamma(agg::gamma_threshold(0.5));//取消抗鋸齒;注釋使用抗鋸齒功能
for (int x=0;x<1000;x++)
{
ras.add_path(stroke);
}
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
int end = ::GetTickCount();
int costTime = 0;
costTime = end -start;
}
void TestOutLineAAPerformance()
{
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
typedef agg::renderer_outline_aa<agg::pixfmt_bgr24> renderer_type;
agg::line_profile_aa profile;
profile.gamma(agg::gamma_threshold(0.5));
profile.width(nLineWidth);//強制性要求設置線寬
renderer_type ren(pixf,profile);
typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
rasterizer_type ras(ren);
ren.color(agg::rgba8(255,0,0));//可選
int nPointX[5]={20,80,20,80,20};
int nPointY[5]={20,20,80,80,20};
agg::path_storage ps;
ps.move_to(nPointX[0],nPointY[0]);
for (int i =1; i<= 4; i++)
{
ps.line_to(nPointX[i],nPointY[i]);
ps.move_to(nPointX[i],nPointY[i]);
}
//agg::conv_transform<agg::path_storage,roundoff>trans(ps,roundoff());
int start = ::GetTickCount();
for (int x=0;x<1000;x++)
{
ras.add_path(ps);
}
int end = ::GetTickCount();
int costTime = 0;
costTime = end -start;
}
簡單說明:agg::gamma_threshold(0.5)主要應用于關閉抗鋸齒功能,注釋掉所在的代碼行就可以啟用抗鋸齒功能。
1)是否設置抗鋸齒,對于渲染的速度沒有多大的幫助,不引入抗鋸齒,耗時稍微多了一點。
2)在渲染細微的線的時候,采用outline_aa更快,如果是厚線,采用stroke_aa更好??!
如下是作者的觀點:
1)亞像素精度和速度沒有多大的關系
2)一般情況下,rasterizer_outline_aa渲染的速度是conv_stroke和rasterizer_scanline_aa的兩倍。但是有非常明顯的限制,只支持miter連接,生成一些工件(artifacts),在渲染厚線的時候更加明顯。
3)實際上渲染鋸齒的厚線遠比抗鋸齒的厚線更加的復雜,看起來可能非常奇怪。所以是否抗鋸齒不會加快渲染速度。
4)渲染厚線(是否抗鋸齒)是一項非常復雜的操作,目前只能夠通過stroker和scanline rasterizer配合工作使用。如果你需要一個非常非??斓匿秩竞窬€的方法,AGG恐怕無法勝任,可能需要硬件加速,但是可能會有更多的限制??!
Having subpixel accuracy doesn't reallymatter for speed.
In general, rasterizer_outline_aa worksabout twice faster than conv_stroke
plus rasterizer_scanline_aa. But it hascertain restrictions (only miter joins)
and produces some artifacts, especiallywith thick lines.
It may seem strange, but it's moredifficult to draw aliased thick polyline
than anti-aliased one. You anyway have toconsider line joins at least. To turn
off anti-aliasing you can use thefollowing:
agg::line_profile_aa profile(10.0,agg::gamma_threshold(0.5));
But it won't speed up rendering.
Fully correct thick outline (aliased oranti-aliased) is a very complex task
and can be solved only with the strokerplus scanline rasterizer.
If you really need to draw thick lines veryvery fast, I'm afraid that AGG is
not what you need. You can try somethingelse, with hardware acceleration,
But this method is even more restrictivethan the general stroker.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。